kicad/pcbnew/dragsegm.cpp

250 lines
6.7 KiB
C++
Raw Normal View History

2007-11-02 18:21:43 +00:00
/*********************************************************/
/* Routines relatives a la gestions des pistes en "DRAG" */
/*********************************************************/
2007-11-02 18:21:43 +00:00
/* Fichier dragsegm.cpp */
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "pcbnew.h"
#include "autorout.h"
#include "trigo.h"
#include "protos.h"
#include "drag.h"
/* fonctions locales */
2007-11-02 18:21:43 +00:00
DRAG_SEGM::DRAG_SEGM( TRACK* segm )
{
2007-11-02 18:21:43 +00:00
m_Segm = segm;
m_StartInitialValue = m_Segm->m_Start;
m_EndInitialValue = m_Segm->m_End;
2007-11-02 18:21:43 +00:00
m_Pad_Start = m_Pad_End = NULL;
m_Flag = 0;
}
DRAG_SEGM::~DRAG_SEGM()
{
}
void DRAG_SEGM::SetInitialValues()
{
2007-11-02 18:21:43 +00:00
m_Segm->m_Start = m_StartInitialValue;
m_Segm->m_End = m_EndInitialValue;
}
2007-11-02 18:21:43 +00:00
/*******************************************************************/
2007-11-02 18:21:43 +00:00
void Dessine_Segments_Dragges( WinEDA_DrawPanel* panel, wxDC* DC )
/*******************************************************************/
/* Redraw the list of segments starting in g_DragSegmentList, while moving a footprint */
{
2007-11-02 18:21:43 +00:00
D_PAD* pt_pad;
TRACK* Track;
DRAG_SEGM* pt_drag;
if( g_DragSegmentList == NULL )
return;
pt_drag = g_DragSegmentList;
for( ; pt_drag; pt_drag = pt_drag->Pnext )
{
int px, py;
Track = pt_drag->m_Segm;
Track->Draw( panel, DC, GR_XOR ); // erase from screen at old position
pt_pad = pt_drag->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;
2007-11-02 18:21:43 +00:00
Track->m_Start.y = py;
}
pt_pad = pt_drag->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;
2007-11-02 18:21:43 +00:00
Track->m_End.y = py;
}
2007-11-02 18:21:43 +00:00
Track->Draw( panel, DC, GR_XOR );
}
}
/*************************************************************************/
2007-11-02 18:21:43 +00:00
void Build_Drag_Liste( WinEDA_DrawPanel* panel, wxDC* DC, MODULE* Module )
/*************************************************************************/
2007-11-02 18:21:43 +00:00
/* Construit la liste des segments connectes aus pads du module Module
2007-11-02 18:21:43 +00:00
* 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)
*/
{
2007-11-02 18:21:43 +00:00
D_PAD* pt_pad;
pt_pad = Module->m_Pads;
for( ; pt_pad != NULL; pt_pad = (D_PAD*) pt_pad->Next() )
2007-11-02 18:21:43 +00:00
{
Build_1_Pad_SegmentsToDrag( panel, DC, pt_pad );
}
return;
}
/**********************************************************************************/
2007-11-02 18:21:43 +00:00
void Build_1_Pad_SegmentsToDrag( WinEDA_DrawPanel* panel, wxDC* DC, D_PAD* PtPad )
/**********************************************************************************/
2007-11-02 18:21:43 +00:00
/* Routine construisant la liste les segments de piste connectes au pad PtPad
2007-11-02 18:21:43 +00:00
* Les net_codes sont supposes a jour.
*/
{
2007-11-02 18:21:43 +00:00
TRACK* Track;
int net_code = PtPad->GetNet();
int MasqueLayer;
wxPoint pos;
BOARD* pcb = ( (WinEDA_BasePcbFrame*) (panel->m_Parent) )->m_Pcb;
Track = pcb->m_Track->GetStartNetCode( net_code );
pos = PtPad->m_Pos;
MasqueLayer = PtPad->m_Masque_Layer;
for( ; Track; Track = Track->Next() )
{
if( Track->GetNet() != net_code )
break; /* hors zone */
2007-11-02 18:21:43 +00:00
if( ( MasqueLayer & Track->ReturnMaskLayer() ) == 0 )
continue; /* couches differentes */
2007-11-02 18:21:43 +00:00
if( pos == Track->m_Start )
{
AddSegmentToDragList( panel, DC, STARTPOINT, Track );
g_DragSegmentList->m_Pad_Start = PtPad;
}
2007-11-02 18:21:43 +00:00
if( pos == Track->m_End )
{
AddSegmentToDragList( panel, DC, ENDPOINT, Track );
g_DragSegmentList->m_Pad_End = PtPad;
}
}
}
2007-11-02 18:21:43 +00:00
/******************************************************************/
2007-11-02 18:21:43 +00:00
void AddSegmentToDragList( WinEDA_DrawPanel* panel, wxDC* DC,
int flag, TRACK* Track )
/******************************************************************/
2007-11-02 18:21:43 +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
*/
{
2007-11-02 18:21:43 +00:00
DRAG_SEGM* pt_drag;
pt_drag = new DRAG_SEGM( Track );
pt_drag->Pnext = g_DragSegmentList;
2007-11-02 18:21:43 +00:00
g_DragSegmentList = pt_drag;
2007-11-02 18:21:43 +00:00
if( (flag & STARTPOINT) )
pt_drag->m_Flag |= 1;
2007-11-02 18:21:43 +00:00
if( (flag & ENDPOINT) )
pt_drag->m_Flag |= 2;
2007-11-02 18:21:43 +00:00
Track->Draw( panel, DC, GR_XOR );
Track->SetState( EDIT, ON );
2007-11-02 18:21:43 +00:00
if( (flag & STARTPOINT) )
Track->m_Flags |= STARTPOINT;
2007-11-02 18:21:43 +00:00
if( (flag & ENDPOINT) )
Track->m_Flags |= ENDPOINT;
2007-11-02 18:21:43 +00:00
Track->Draw( panel, DC, GR_XOR );
}
2007-11-02 18:21:43 +00:00
/**********************************************************************************/
2007-11-02 18:21:43 +00:00
void Collect_TrackSegmentsToDrag( WinEDA_DrawPanel* panel, wxDC* DC,
wxPoint& point, int MasqueLayer, int net_code )
/**********************************************************************************/
2007-11-02 18:21:43 +00:00
/* Routine construisant la liste les segments de piste connectes a la via Via
2007-11-02 18:21:43 +00:00
* Les net_codes sont supposes a jour.
*/
{
2007-11-02 18:21:43 +00:00
BOARD* pcb = ( (WinEDA_BasePcbFrame*) (panel->m_Parent) )->m_Pcb;
TRACK* track = pcb->m_Track->GetStartNetCode( net_code );
for( ; track; track = track->Next() )
2007-11-02 18:21:43 +00:00
{
if( track->GetNet() != net_code )
2007-11-02 18:21:43 +00:00
break; /* hors zone */
if( ( MasqueLayer & track->ReturnMaskLayer() ) == 0 )
2007-11-02 18:21:43 +00:00
continue; /* couches differentes */
if( track->m_Flags & IS_DRAGGED )
2007-11-02 18:21:43 +00:00
continue; // already in list
if( track->m_Start == point )
2007-11-02 18:21:43 +00:00
{
AddSegmentToDragList( panel, DC, STARTPOINT, track );
2007-11-02 18:21:43 +00:00
}
if( track->m_End == point )
2007-11-02 18:21:43 +00:00
{
AddSegmentToDragList( panel, DC, ENDPOINT, track );
2007-11-02 18:21:43 +00:00
}
}
}
/*****************************/
void EraseDragListe()
/*****************************/
2007-11-02 18:21:43 +00:00
/* Routine de liberation memoire de la liste des structures DRAG_SEGM
2007-11-02 18:21:43 +00:00
* remet a zero le pointeur global g_DragSegmentList
*/
{
2007-11-02 18:21:43 +00:00
DRAG_SEGM* pt_drag;
DRAG_SEGM* NextStruct;
if( g_DragSegmentList == NULL )
return;
2007-11-02 18:21:43 +00:00
pt_drag = g_DragSegmentList;
for( ; pt_drag != NULL; pt_drag = NextStruct )
{
2007-11-05 07:07:00 +00:00
NextStruct = pt_drag->Pnext;
pt_drag->m_Segm->m_Flags = 0;
2007-11-02 18:21:43 +00:00
delete pt_drag;
}
2007-11-02 18:21:43 +00:00
g_DragSegmentList = NULL;
}