Commit 148a574e authored by charras's avatar charras

More about undo/redo in pcbnew

parent 42b1020d
......@@ -314,6 +314,25 @@ void PICKED_ITEMS_LIST::CopyList( const PICKED_ITEMS_LIST& aSource )
m_ItemsList = aSource.m_ItemsList; // Vector's copy
}
/** function ReversePickersListOrder()
* reverses the order of pickers stored in this list
* Useful when pop a list from Undo to Redo (and vice-versa)
* because sometimes undo (or redo) a command needs to keep the
* order of successive changes.
* and obviously, undo and redo are in reverse order
*/
void PICKED_ITEMS_LIST::ReversePickersListOrder()
{
std::vector <ITEM_PICKER> tmp;
while( !m_ItemsList.empty() )
{
tmp.push_back( m_ItemsList.back() );
m_ItemsList.pop_back();
}
m_ItemsList.swap( tmp );
}
/**********************************************/
/********** UNDO_REDO_CONTAINER ***************/
......@@ -355,3 +374,5 @@ PICKED_ITEMS_LIST* UNDO_REDO_CONTAINER::PopCommand()
}
return NULL;
}
......@@ -137,6 +137,15 @@ public:
return m_ItemsList.size();
}
/** function ReversePickersListOrder()
* reverses the order of pickers stored in this list
* Useful when pop a list from Undo to Redo (and vice-versa)
* because sometimes undo (or redo) a command needs to keep the
* order of successive changes.
* and obviously, undo and redo are in reverse order
*/
void ReversePickersListOrder();
/** function GetItemWrapper
* @return the picker of a picked item
......
......@@ -386,8 +386,21 @@ public:
void Remove_One_Track( wxDC* DC, TRACK* pt_segm );
bool Resize_Pistes_Vias( wxDC* DC, bool Track, bool Via );
void Edit_Net_Width( wxDC* DC, int Netcode );
/** Function Edit_Track_Width
* Modify a full track width (using DRC control).
* a full track is the set of track segments between 2 ends: pads or a point that has more than 2 segments ends connected
* @param DC = the curred device context (can be NULL)
* @param aTrackSegment = a segment or via on the track to change
*/
void Edit_Track_Width( wxDC* DC, TRACK* Track );
int Edit_TrackSegm_Width( wxDC* DC, TRACK* segm );
/** Function Edit_TrackSegm_Width
* Modify one track segment width or one via diameter (using DRC control).
* @param DC = the curred device context (can be NULL)
* @param aTrackItem = the track segment or via to modify
*/
void Edit_TrackSegm_Width( wxDC* DC, TRACK* segm );
TRACK* Begin_Route( TRACK* track, wxDC* DC );
void End_Route( TRACK* track, wxDC* DC );
void ExChange_Track_Layer( TRACK* pt_segm, wxDC* DC );
......@@ -395,13 +408,35 @@ public:
void Attribut_Track( TRACK* track, wxDC* DC, bool Flag_On );
void Attribut_net( wxDC* DC, int net_code, bool Flag_On );
void Start_MoveOneNodeOrSegment( TRACK* track, wxDC* DC, int command );
bool PlaceDraggedTrackSegment( TRACK* Track, wxDC* DC );
bool PlaceDraggedOrMovedTrackSegment( TRACK* Track, wxDC* DC );
bool MergeCollinearTracks( TRACK* track, wxDC* DC, int end );
void Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC );
void SwitchLayer( wxDC* DC, int layer );
bool Add_45_degrees_Segment( wxDC* DC );
bool Genere_Pad_Connexion( wxDC* DC, int layer );
/** function EraseRedundantTrack
* Called after creating a track
* Remove (if exists) the old track that have the same starting and the same ending point as the new created track
* (this is the redunding track)
* @param aDC = the current device context (can be NULL)
* @param aNewTrack = the new created track (a pointer to a segment of the track list)
* @param aNewTrackSegmentsCount = number of segments in this new track
* @param aItemsListPicker = the list picker to use for an undo command (can be NULL)
*/
int EraseRedundantTrack( wxDC* aDC, TRACK* aNewTrack, int aNewTrackSegmentsCount,
PICKED_ITEMS_LIST* aItemsListPicker );
/** Function SetTrackSegmentWidth
* Modify one track segment width or one via diameter (using DRC control).
* Basic routine used by other routines when editing tracks or vias
* @param aTrackItem = the track segment or via to modify
* @param aItemsListPicker = the list picker to use for an undo command (can be NULL)
* @return true if done, false if no not change (because DRC error)
*/
bool SetTrackSegmentWidth( TRACK* aTrackItem, PICKED_ITEMS_LIST* aItemsListPicker );
// zone handling
/** Function Delete_Zone_Fill
......
......@@ -641,7 +641,7 @@ void WinEDA_PcbFrame::Block_Delete()
// These items are deleted, but not put in undo list
case TYPE_MARKER_PCB: // a marker used to show something
case TYPE_ZONE: // a segment used to fill a zome area (segment on a copper layer)
case TYPE_ZONE: // SEG_ZONE items are now deprecated
item->UnLink();
itemsList->RemovePicker( ii );
ii--;
......@@ -715,7 +715,7 @@ void WinEDA_PcbFrame::Block_Rotate()
break;
// This item is not put in undo list
case TYPE_ZONE: // a segment used to fill a zome area (segment on a copper layer)
case TYPE_ZONE: // SEG_ZONE items are now deprecated
itemsList->RemovePicker( ii );
ii--;
break;
......@@ -786,7 +786,7 @@ void WinEDA_PcbFrame::Block_Flip()
break;
// This item is not put in undo list
case TYPE_ZONE: // a segment used to fill a zome area (segment on a copper layer)
case TYPE_ZONE: // SEG_ZONE items are now deprecated
itemsList->RemovePicker( ii );
ii--;
break;
......@@ -853,7 +853,7 @@ void WinEDA_PcbFrame::Block_Move()
break;
// This item is not put in undo list
case TYPE_ZONE: // a segment used to fill a zome area (segment on a copper layer)
case TYPE_ZONE: // SEG_ZONE items are now deprecated
itemsList->RemovePicker( ii );
ii--;
break;
......@@ -928,11 +928,7 @@ void WinEDA_PcbFrame::Block_Duplicate()
}
break;
case TYPE_ZONE: // a segment used to fill a zome area (segment on a copper layer)
{
// SEG_ZONE items are not copied or put in undo list
// they must be recreated by zone filling
}
case TYPE_ZONE: // SEG_ZONE items are now deprecated
break;
case TYPE_ZONE_CONTAINER:
......
......@@ -126,7 +126,7 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
}
// Swap layers:
if( aItem->Type() != TYPE_MODULE ) // Modules have a global swap function
if( aItem->Type() != TYPE_MODULE && aItem->Type() != TYPE_ZONE_CONTAINER ) // these items have a global swap function
{
int layer, layerimg;
layer = aItem->GetLayer();
......@@ -139,15 +139,20 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
{
case TYPE_MODULE:
{
MODULE* m_tmp = (MODULE*) DuplicateStruct( aImage );
MODULE* tmp = (MODULE*) DuplicateStruct( aImage );
( (MODULE*) aImage )->Copy( (MODULE*) aItem );
( (MODULE*) aItem )->Copy( m_tmp );
delete m_tmp;
( (MODULE*) aItem )->Copy( tmp );
delete tmp;
}
break;
case TYPE_ZONE_CONTAINER:
wxMessageBox( wxT( "SwapData(): TYPE_ZONE_CONTAINER not handled" ) );
{
ZONE_CONTAINER* tmp = (ZONE_CONTAINER*) DuplicateStruct( aImage );
( (ZONE_CONTAINER*) aImage )->Copy( (ZONE_CONTAINER*) aItem );
( (ZONE_CONTAINER*) aItem )->Copy( tmp );
delete tmp;
}
break;
case TYPE_DRAWSEGMENT:
......@@ -189,7 +194,7 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
case TYPE_COTATION:
{
wxString txt = ( (COTATION*) aItem )->GetText();
( (COTATION*) aItem )->SetText( ((COTATION*) aImage )->GetText() );
( (COTATION*) aItem )->SetText( ( (COTATION*) aImage )->GetText() );
( (COTATION*) aImage )->SetText( txt );
EXCHG( ( (COTATION*) aItem )->m_Text->m_Size, ( (COTATION*) aImage )->m_Text->m_Size );
EXCHG( ( (COTATION*) aItem )->m_Text->m_Width, ( (COTATION*) aImage )->m_Text->m_Width );
......@@ -383,6 +388,7 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
commandToUndo->m_TransformPoint = aTransformPoint;
// Copy picker list:
commandToUndo->CopyList( aItemsList );
......@@ -394,20 +400,21 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
if( command == UR_UNSPECIFIED )
{
command = aTypeCommand;
commandToUndo->SetPickedItemStatus(command, ii );
commandToUndo->SetPickedItemStatus( command, ii );
}
wxASSERT( item );
switch( command )
{
case UR_CHANGED:
/* If needed, create a copy of item, and put in undo list
* in the picker, as link
* If this link is not null, the copy is already done
*/
if( commandToUndo->GetPickedItemLink(ii) == NULL )
if( commandToUndo->GetPickedItemLink( ii ) == NULL )
commandToUndo->SetPickedItemLink( DuplicateStruct( item ), ii );
wxASSERT( commandToUndo->GetPickedItemLink(ii) );
wxASSERT( commandToUndo->GetPickedItemLink( ii ) );
break;
case UR_MOVED:
......@@ -453,7 +460,9 @@ void WinEDA_PcbFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRe
bool not_found = false;
bool reBuild_ratsnest = false;
for( unsigned ii = 0; ii < aList->GetCount(); ii++ )
// Undo in the reverse order of list creation: (this can allow stacked changes
// like the same item can be changes and deleted in the same complex command
for( int ii = aList->GetCount()-1; ii >= 0 ; ii-- )
{
item = (BOARD_ITEM*) aList->GetPickedItem( ii );
wxASSERT( item );
......@@ -464,7 +473,7 @@ void WinEDA_PcbFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRe
{
// Remove this non existant item
aList->RemovePicker( ii );
ii--; // the current item was removed, ii points now the next item
ii++; // the current item was removed, ii points now the next item
// whe must decrement it because it will be incremented
not_found = true;
continue;
......@@ -557,12 +566,15 @@ void WinEDA_PcbFrame::GetBoardFromUndoList( wxCommandEvent& event )
if( GetScreen()->GetUndoCommandCount() <= 0 )
return;
/* Get the old wrapper and put it in RedoList */
/* Get the old list */
PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromUndoList();
GetScreen()->PushCommandToRedoList( List );
/* Undo the command */
PutDataInPreviousState( List, false );
/* Pu the old list in RedoList */
List->ReversePickersListOrder();
GetScreen()->PushCommandToRedoList( List );
GetScreen()->SetModify();
ReCreateHToolbar();
SetToolbars();
......@@ -583,13 +595,16 @@ void WinEDA_PcbFrame::GetBoardFromRedoList( wxCommandEvent& event )
return;
/* Get the old wrapper and put it in UndoList */
/* Get the old list */
PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromRedoList();
GetScreen()->PushCommandToUndoList( List );
/* Redo the command: */
PutDataInPreviousState( List, true );
/* Put the old list in UndoList */
List->ReversePickersListOrder();
GetScreen()->PushCommandToUndoList( List );
GetScreen()->SetModify();
ReCreateHToolbar();
SetToolbars();
......
......@@ -1145,8 +1145,8 @@ void ZONE_CONTAINER::Copy( ZONE_CONTAINER* src )
/**
* Function SetNetNameFromNetCode
* Fin the nat name corresponding to the net code.
* @param aPcb: the curren board
* Find the net name corresponding to the net code.
* @param aPcb: the current board
* @return bool - true if net found, else false
*/
bool ZONE_CONTAINER::SetNetNameFromNetCode( void )
......
......@@ -165,22 +165,11 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
break;
case ID_TOGGLE_PRESENT_COMMAND:
/* if( DrawPanel->ManageCurseur
* && DrawPanel->ForceCloseManageCurseur )
* {
* DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc );
* }
*/
break;
default: // Finish (abort ) the command
if( DrawPanel->ManageCurseur
&& DrawPanel->ForceCloseManageCurseur )
{
if( DrawPanel->ManageCurseur && DrawPanel->ForceCloseManageCurseur )
DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc );
}
if( m_ID_current_state != id )
{
......@@ -286,11 +275,6 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
m_ModuleEditFrame->Iconize( false );
break;
case ID_NEW_PROJECT:
case ID_LOAD_PROJECT:
Files_io( event );
break;
case ID_PCB_GLOBAL_DELETE:
InstallPcbGlobalDeleteFrame( pos );
break;
......@@ -470,7 +454,7 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
DrawPanel->MouseToCursorSchema();
if( GetCurItem()->m_Flags & IS_DRAGGED )
{
PlaceDraggedTrackSegment( (TRACK*) GetCurItem(), &dc );
PlaceDraggedOrMovedTrackSegment( (TRACK*) GetCurItem(), &dc );
}
break;
......@@ -482,7 +466,7 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
DrawPanel->MouseToCursorSchema();
if( GetCurItem()->m_Flags & IS_DRAGGED )
{
PlaceDraggedTrackSegment( (TRACK*) GetCurItem(), &dc );
PlaceDraggedOrMovedTrackSegment( (TRACK*) GetCurItem(), &dc );
}
else
{
......@@ -1131,7 +1115,9 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
TRACK* track = (TRACK*) GetScreen()->GetCurItem();
wxPoint pos = GetScreen()->m_Curseur;
track->Draw( DrawPanel, &dc, GR_XOR );
TRACK* newtrack = CreateLockPoint( &pos.x, &pos.y, track, NULL );
PICKED_ITEMS_LIST itemsListPicker;
TRACK* newtrack = CreateLockPoint( pos, track, NULL, &itemsListPicker);
SaveCopyInUndoList(itemsListPicker,UR_UNSPECIFIED);
track->Draw( DrawPanel, &dc, GR_XOR );
newtrack->Draw( DrawPanel, &dc, GR_XOR );
}
......
This diff is collapsed.
......@@ -27,6 +27,7 @@ static void EnsureEndTrackOnPad( D_PAD* Pad );
/* variables locales */
static int OldNetCodeSurbrillance;
static int OldEtatSurbrillance;
static PICKED_ITEMS_LIST s_ItemsListPicker;
/************************************************************/
......@@ -53,6 +54,9 @@ static void Exit_Editrack( WinEDA_DrawPanel* Panel, wxDC* DC )
frame->MsgPanel->EraseMsgBox();
// Clear the undo picker list:
s_ItemsListPicker.ClearListAndDeleteItems();
// Delete current (new) track
g_CurrentTrackList.DeleteAll();
}
......@@ -95,6 +99,9 @@ TRACK* WinEDA_PcbFrame::Begin_Route( TRACK* aTrack, wxDC* DC )
if( aTrack == NULL ) /* Starting a new track */
{
// Prepare the undo command info
s_ItemsListPicker.ClearListAndDeleteItems(); // Should not be necessary, but...
/* erase old highlight */
OldNetCodeSurbrillance = g_HightLigth_NetCode;
OldEtatSurbrillance = g_HightLigt_Status;
......@@ -126,7 +133,7 @@ TRACK* WinEDA_PcbFrame::Begin_Route( TRACK* aTrack, wxDC* DC )
{
TrackOnStartPoint = (TRACK*) LockPoint;
g_HightLigth_NetCode = TrackOnStartPoint->GetNet();
CreateLockPoint( &pos.x, &pos.y, TrackOnStartPoint, NULL );
CreateLockPoint( pos, TrackOnStartPoint, NULL, &s_ItemsListPicker );
}
}
else // no starting point, but a filled zone area can exist. This is also a good starting point.
......@@ -471,10 +478,10 @@ void WinEDA_PcbFrame::End_Route( TRACK* aTrack, wxDC* DC )
g_HightLigth_NetCode = adr_buf->GetNet();
/* creation eventuelle d'un point d'accrochage */
LockPoint = CreateLockPoint( &g_CurrentTrackSegment->m_End.x,
&g_CurrentTrackSegment->m_End.y,
LockPoint = CreateLockPoint( g_CurrentTrackSegment->m_End,
adr_buf,
g_CurrentTrackSegment );
g_CurrentTrackSegment,
&s_ItemsListPicker);
}
}
......@@ -488,11 +495,13 @@ void WinEDA_PcbFrame::End_Route( TRACK* aTrack, wxDC* DC )
TRACK* firstTrack = g_FirstTrackSegment;
int newCount = g_CurrentTrackList.GetCount();
// Put entire new current segment list in BOARD
// Put entire new current segment list in BOARD, ans prepare undo command
TRACK* track;
TRACK* insertBeforeMe = g_CurrentTrackSegment->GetBestInsertPoint( GetBoard() );
while( ( track = g_CurrentTrackList.PopFront() ) != NULL )
{
ITEM_PICKER picker( track, UR_NEW );
s_ItemsListPicker.PushItem( picker );
GetBoard()->m_Track.Insert( track, insertBeforeMe );
}
......@@ -510,8 +519,10 @@ void WinEDA_PcbFrame::End_Route( TRACK* aTrack, wxDC* DC )
// erase the old track, if exists
if( g_AutoDeleteOldTrack )
{
EraseOldTrack( this, GetBoard(), DC, firstTrack, newCount );
EraseRedundantTrack( DC, firstTrack, newCount, & s_ItemsListPicker );
}
SaveCopyInUndoList(s_ItemsListPicker, UR_UNSPECIFIED);
s_ItemsListPicker.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
/* compute the new rastnest : */
test_1_net_connexion( DC, netcode );
......
......@@ -55,9 +55,9 @@ void WinEDA_PcbGlobalDeleteFrame::AcceptPcbDelete( wxCommandEvent& event )
{
gen_rastnest = true;
/* Segments used in Zone filling selection */
// for many reasons saving these items can create problems so they are not saved
// (because they are numerous and can be deleted in zones operation)
/* ZEG_ZONE items used in Zone filling selection are now deprecated :
* and are deleted but not put in undo buffer if exist
*/
pcb->m_Zone.DeleteAll();
while( pcb->GetAreaCount() )
......
......@@ -139,7 +139,7 @@ int WinEDA_BasePcbFrame::ReadListeSegmentDescr( FILE* File,
GetBoard()->m_Track.Insert( newTrack, insertBeforeMe );
break;
case TYPE_ZONE:
case TYPE_ZONE: // this is now deprecated, but exits in old boards
newTrack = new SEGZONE( GetBoard() );
GetBoard()->m_Zone.Insert( (SEGZONE*)newTrack, (SEGZONE*)insertBeforeMe );
break;
......@@ -846,7 +846,7 @@ int WinEDA_PcbFrame::ReadPcbFile( FILE* File, bool Append )
{
ZONE_CONTAINER * zone_descr = new ZONE_CONTAINER(GetBoard());
zone_descr->ReadDescr( File, &LineNum );
if ( zone_descr->GetNumCorners( ) > 2 ) // should not occur
if ( zone_descr->GetNumCorners( ) > 2 ) // should always occur
GetBoard()->Add(zone_descr);
else delete zone_descr;
continue;
......
This diff is collapsed.
......@@ -50,7 +50,7 @@ void WinEDA_PcbFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
case TYPE_VIA:
if( DrawStruct->m_Flags & IS_DRAGGED )
{
PlaceDraggedTrackSegment( (TRACK*) DrawStruct, DC );
PlaceDraggedOrMovedTrackSegment( (TRACK*) DrawStruct, DC );
exit = true;
}
break;
......
......@@ -208,9 +208,7 @@ TRACK* Locate_Pistes( TRACK* start_adresse, int typeloc );
DRAWSEGMENT* Locate_Segment_Pcb( BOARD* Pcb, int LayerSearch, int typeloc );
D_PAD* Fast_Locate_Pad_Connecte( BOARD* Pcb, const wxPoint& ref_pos, int layer );
/* Routine cherchant le pad contenant le point px,py, sur la couche layer
* ( extremite de piste )
* La liste des pads doit deja exister.
......@@ -290,30 +288,6 @@ void ListSetState( EDA_BaseStruct* Start, int Nbitem, int State, int onoff );
/* Met a jour le membre .state d'une chaine de structures */
/************/
/* DRC.CPP : */
/************/
int Drc( WinEDA_BasePcbFrame* frame, wxDC* DC,
TRACK* pt_segment, TRACK* pt_start_buffer, int show_err );
/* Teste le segment pointe par pt_segment:
* debsegment = adresse du segment a tester
* pt_start_buffer = adresse de la zone piste
* show_err (flag) si 0 pas d'affichage d'erreur sur ecran
* retourne :
* BAD_DRC (1) si Violation DRC
* OK_DRC (0) si OK */
/*****************/
/* TR_MODIF.CPP : */
/*****************/
int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
TRACK* pt_new_track, int nbptnewpiste );
void Modif_Auto_Route( TRACK* pt_debut_new_piste );
/**************/
/* CLEAN.CPP : */
/**************/
......@@ -324,21 +298,6 @@ int Netliste_Controle_piste( WinEDA_PcbFrame* frame, wxDC* DC, int affiche );
* de net_code differents */
/************/
/* BLOCK.CPP */
/************/
void Block_Affiche( int on_off ); /*
* routine de trace du cadre d'un Block en cours de delimitation
* Si on_off = 0 : effacement du cadre
* Si on_off = 1 : affichage du cadre */
void Trace_Block( WinEDA_DrawPanel* panel, wxDC* DC, int ox, int oy, int fx, int fy, int color );
/* Routine de trace d'un rectangle symbolisant un block
* (toujours en mode XOR) */
/************/
/* ZONES.CPP */
/************/
......@@ -362,8 +321,6 @@ void MasqueAttributs( int* masque_set, int* masque_clr );
/* DUPLTRAC.CPP */
/***************/
BOARD_ITEM* LocateLockPoint( BOARD* Pcb, wxPoint pos, int LayerMask );
/* Routine trouvant le point " d'accrochage " d'une extremite de piste.
* Ce point peut etre un PAD ou un autre segment de piste
* Retourne:
......@@ -371,24 +328,26 @@ BOARD_ITEM* LocateLockPoint( BOARD* Pcb, wxPoint pos, int LayerMask );
* - pointeur sur le segment ou:
* - NULL
* Parametres d'appel:
* coord pX, pY du point tst
* masque des couches a tester
* coord aPos du point tst
* aLayerMask masque des couches a tester
*/
BOARD_ITEM* LocateLockPoint( BOARD* aPcb, wxPoint aPos, int aLayerMask );
TRACK* CreateLockPoint( int* pX, int* pY, TRACK* ptsegm, TRACK* refsegm );
/* Routine de creation d'un point intermediaire sur un segment
* le segment ptsegm est casse en 2 segments se raccordant au point pX, pY
* le segment aSegm est casse en 2 segments se raccordant au point pX, pY
* retourne:
* NULL si pas de nouveau point ( c.a.d si pX, pY correspondait deja
* NULL si pas de nouveau point ( c.a.d si aRefPoint correspondait deja
* a une extremite ou:
* pointeur sur le segment cree
* si refsegm != NULL refsegm est pointeur sur le segment incident,
* et le point cree est l'ntersection des 2 axes des segments ptsegm et
* refsegm
* retourne la valeur exacte de pX et pY
* si aRefSegm != NULL refsegm est pointeur sur le segment incident,
* et le point cree est l'intersection des 2 axes des segments ptsegm et aRefSegm
* retourne la valeur exacte de aRefPoint
* Si aSegm pointe sur une via:
* retourne la valeur exacte de aRefPoint et aSegm,
* mais ne cree pas de point supplementaire
*/
TRACK* CreateLockPoint( wxPoint & aRefPoint, TRACK* aSegm, TRACK* aRefSegm, PICKED_ITEMS_LIST* aItemsListPicker );
/****************/
/* CONTROLE.CPP */
......
......@@ -4,25 +4,23 @@
/**************************************************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "pcbnew.h"
#include "wxPcbStruct.h"
#include "protos.h"
/*********************************************************************/
int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
TRACK* pt_new_track, int nbptnewpiste )
/*********************************************************************/
/* Routine d'effacement de la piste redondante a la piste nouvellement cree
* pointee par pt_new_track (nbptnewpiste segments)
*
* la piste cree est supposee constituee de segments contigus en memoire avec:
* point de depart pt_newtrack->m_Start.x,y
* point d'arrivee pt_newtrack->m_End.x,y
/** function EraseRedundantTrack
* Called after creating a track
* Remove (if exists) the old track that have the same starting and the same ending point as the new created track
* (this is the redunding track)
* @param aDC = the current device context (can be NULL)
* @param aNewTrack = the new created track (a pointer to a segment of the track list)
* @param aNewTrackSegmentsCount = number of segments in this new track
* @param aItemsListPicker = the list picker to use for an undo command (can be NULL)
*/
int WinEDA_PcbFrame::EraseRedundantTrack( wxDC* aDC, TRACK* aNewTrack, int aNewTrackSegmentsCount, PICKED_ITEMS_LIST* aItemsListPicker )
{
TRACK* StartTrack, * EndTrack;/* Pointeurs des segments de debut et fin
* (extremites) de la nouvelle piste */
......@@ -35,31 +33,31 @@ int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
TRACK* BufDeb, * BufEnd; /* Pointeurs de debut et de fin de la zone
* des pistes equipotentielles */
int netcode = pt_new_track->GetNet();
int netcode = aNewTrack->GetNet();
/* Reconstitution de la piste complete ( la nouvelle piste
* a pu demarrer sur un segment de piste en l'air
*/
ListSetState( pt_new_track, nbptnewpiste, BUSY, OFF );
ListSetState( aNewTrack, aNewTrackSegmentsCount, BUSY, OFF );
/* si la novelle piste commence par une via, il est plus sur de rechercher
/* si la nouvelle piste commence par une via, il est plus sur de rechercher
* la piste complete en utilisant le segment suivant comme reference, car
* une via est souvent sur un carrefour de segments, et ne caracterise pas
* une piste */
if( pt_new_track->Type() == TYPE_VIA && (nbptnewpiste > 1 ) )
pt_new_track = pt_new_track->Next();
if( aNewTrack->Type() == TYPE_VIA && (aNewTrackSegmentsCount > 1 ) )
aNewTrack = aNewTrack->Next();
pt_new_track = Marque_Une_Piste( frame, DC, pt_new_track, &nbptnewpiste, 0 );
wxASSERT( pt_new_track );
aNewTrack = Marque_Une_Piste( this, aDC, aNewTrack, &aNewTrackSegmentsCount, 0 );
wxASSERT( aNewTrack );
#if 0 && defined(DEBUG)
TRACK* EndNewTrack; /* Pointeur sur le dernier segment de la liste
* chainee de la mouvelle piste */
EndNewTrack = pt_new_track;
for( ii = 1; ii < nbptnewpiste; ii++ )
EndNewTrack = aNewTrack;
for( ii = 1; ii < aNewTrackSegmentsCount; ii++ )
{
wxASSERT( EndNewTrack->GetState(-1) != 0 );
D(printf("track %p is newly part of net %d\n", EndNewTrack, netcode );)
......@@ -69,13 +67,13 @@ int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
wxASSERT( EndNewTrack->GetState(-1) != 0 );
D(printf("track %p is newly part of net %d\n", EndNewTrack, netcode );)
for( TRACK* track = Pcb->m_Track; track; track = track->Next() )
for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() )
track->Show( 0, std::cout );
#endif
/* Calcul des limites de recherche des segments de piste */
/* BufDeb pointe le 1er segment utile */
BufDeb = Pcb->m_Track->GetStartNetCode( netcode );
BufDeb = m_Pcb->m_Track->GetStartNetCode( netcode );
/* BufEnd Pointe le dernier segment */
BufEnd = BufDeb->GetEndNetCode( netcode );
......@@ -90,7 +88,7 @@ int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
}
/* Calcul des points limites de la nouvelle piste */
if( ReturnEndsTrack( pt_new_track, nbptnewpiste,
if( ReturnEndsTrack( aNewTrack, aNewTrackSegmentsCount,
&StartTrack, &EndTrack ) == 0 )
return 0;
......@@ -110,7 +108,7 @@ int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
endmasklayer = EndTrack->ReturnMaskLayer();
/* Il peut y avoir une via ou un pad sur les extremites: */
pt_segm = Fast_Locate_Via( Pcb->m_Track, NULL, start, startmasklayer );
pt_segm = Fast_Locate_Via( m_Pcb->m_Track, NULL, start, startmasklayer );
if( pt_segm )
startmasklayer |= pt_segm->ReturnMaskLayer();
......@@ -121,7 +119,7 @@ int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
startmasklayer |= pt_pad->m_Masque_Layer;
}
pt_segm = Fast_Locate_Via( Pcb->m_Track, NULL, end, endmasklayer );
pt_segm = Fast_Locate_Via( m_Pcb->m_Track, NULL, end, endmasklayer );
if( pt_segm )
endmasklayer |= pt_segm->ReturnMaskLayer();
......@@ -134,7 +132,7 @@ int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
/* Marquage a DELETED de la piste nouvelle (qui ne doit pas intervenir
* dans la recherche d'autres connexions)
*/
ListSetState( pt_new_track, nbptnewpiste, DELETED, ON );
ListSetState( aNewTrack, aNewTrackSegmentsCount, DELETED, ON );
/* test : un segment doit etre connecte au point de depart car sinon
* il est inutile d'analyser l'autre point
......@@ -145,7 +143,7 @@ int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
if( pt_segm == NULL ) /* Pas de piste reliee au point de depart */
{
/* Suppression du flag DELETED */
ListSetState( pt_new_track, nbptnewpiste, DELETED, OFF );
ListSetState( aNewTrack, aNewTrackSegmentsCount, DELETED, OFF );
return 0;
}
......@@ -188,9 +186,9 @@ int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
/* Marquage a EDIT de la piste nouvelle (qui ne doit pas intervenir
* dans la recherche d'autres pistes) */
ListSetState( pt_new_track, nbptnewpiste, DELETED, OFF );
ListSetState( aNewTrack, aNewTrackSegmentsCount, DELETED, OFF );
ListSetState( pt_new_track, nbptnewpiste, EDIT, ON );
ListSetState( aNewTrack, aNewTrackSegmentsCount, EDIT, ON );
/* Examen de tous les segments marques */
while( nbconnect )
......@@ -206,7 +204,7 @@ int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
nbconnect--;
pt_del->SetState( CHAIN, OFF );
pt_del = Marque_Une_Piste( frame, DC, pt_del, &nb_segm, 0 );
pt_del = Marque_Une_Piste( this, aDC, pt_del, &nb_segm, 0 );
/* Test si La piste marquee est redondante, c'est a dire si l'un des
* segments marques est connecte au point de depart de la piste nouvelle
......@@ -222,21 +220,31 @@ int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
{
/* la piste marquee peut etre effacee */
TRACK* NextS;
Trace_Une_Piste( frame->DrawPanel, DC, pt_del, nb_segm, GR_XOR | GR_SURBRILL );
Trace_Une_Piste( DrawPanel, aDC, pt_del, nb_segm, GR_XOR | GR_SURBRILL );
for( jj = 0; jj < nb_segm; jj++, pt_del = NextS )
{
NextS = pt_del->Next();
if( aItemsListPicker )
{
pt_del->UnLink();
pt_del->SetStatus( 0 );
pt_del->m_Flags = 0;
ITEM_PICKER picker( pt_del, UR_DELETED );
aItemsListPicker->PushItem( picker );
}
else
pt_del->DeleteStructure();
}
/* nettoyage des flags */
for( pt_del = Pcb->m_Track; pt_del != NULL; pt_del = pt_del->Next() )
for( pt_del = m_Pcb->m_Track; pt_del != NULL; pt_del = pt_del->Next() )
{
if( pt_del->GetState( EDIT ) )
{
pt_del->SetState( EDIT, OFF );
pt_del->Draw( frame->DrawPanel, DC, GR_OR );
if( aDC )
pt_del->Draw( DrawPanel, aDC, GR_OR );
}
pt_del->SetState( EDIT | CHAIN, OFF );
}
......@@ -251,7 +259,7 @@ int EraseOldTrack( WinEDA_BasePcbFrame* frame, BOARD* Pcb, wxDC* DC,
}
/* Clear used flags */
for( pt_del = Pcb->m_Track; pt_del; pt_del = pt_del->Next() )
for( pt_del = m_Pcb->m_Track; pt_del; pt_del = pt_del->Next() )
{
pt_del->SetState( BUSY | DELETED | EDIT | CHAIN, OFF );
if( pt_del == BufEnd ) // Last segment reached
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment