gerbview, pcbnew's BOARD container changes

This commit is contained in:
dickelbeck 2008-12-06 21:20:50 +00:00
parent ceeb27cfd5
commit d814889db7
13 changed files with 133 additions and 215 deletions

View File

@ -5,6 +5,27 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.
2008-Dec-6 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++pcbnew & gerbview
* As a final migration step, made BOARD_ITEM::SetNext() and
BOARD_ITEM::SetBack() _private_, starting at BOARD_ITEM in the class
hierarchy so that the compiler will tell us where they are used illegally.
Classes derived from BOARD_ITEM then also cannot expose SetNext() and
SetPrev(), and this forces everthing related to BOARD_ITEM through DLIST for
list manipulation. The compiler turned up a couple I had missed, two of which
were the back pointers of MODULE::m_Reference->Back(), m_Value->Back(), which I
do not think are needed since the MODULE owns these texts, not the other way around.
This should be the final nail in the coffin for undisciplined list manipulation
within pcbnew and gerbview.
* Converted BOARD::Delete() into BOARD::Remove() and then added an inline for
BOARD::Delete() which deletes what Remove() returns.
* Removed BOARD::DeleteMARKER( int ) since BOARD::Delete() works.
* Removed gerbview's undelete.cpp and made gerbview use pcbnew's,
by moving the two supporting functions into the common base class
of WinEDA_BasePcbFrame, had to add some "#if !defined(GERBVIEW)"s.
2008-Dec-5 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++pcbnew & gerbview

View File

@ -37,8 +37,7 @@ set(GERBVIEW_SRCS
# struct.cpp <-- not used
tool_gerber.cpp
tracepcb.cpp
trpiste.cpp
undelete.cpp)
trpiste.cpp )
set(GERBVIEW_EXTRA_SRCS
../pcbnew/basepcbframe.cpp
@ -55,6 +54,7 @@ set(GERBVIEW_EXTRA_SRCS
../pcbnew/classpcb.cpp
../pcbnew/collectors.cpp
../pcbnew/sel_layer.cpp
../pcbnew/undelete.cpp
../share/drawframe.cpp
../share/setpage.cpp

View File

@ -5,12 +5,6 @@
/***************************/
int * InstallDialogLayerPairChoice(WinEDA_GerberFrame * parent);
/****************/
/* undelete.cpp */
/****************/
BOARD_ITEM* SaveItemEfface( BOARD_ITEM* PtItem, int nbitems );
/***********************/
/* gerbview_config.cpp */
/***********************/

View File

@ -103,7 +103,7 @@ static void fillRoundFlashTRACK( TRACK* aTrack, int Dcode_index, int aLayer,
aTrack->SetNet( Dcode_index );
aTrack->m_Shape = S_SPOT_CIRCLE;
D(printf("%s: isDark=%s\n", __func__, isDark ? "true" : "false" );)
// D(printf("%s: isDark=%s\n", __func__, isDark ? "true" : "false" );)
if( !isDark )
{
@ -156,7 +156,7 @@ static void fillOvalOrRectFlashTRACK( TRACK* aTrack, int Dcode_index, int aLaye
aTrack->m_End.y += len;
}
D(printf("%s: isDark=%s\n", __func__, isDark ? "true" : "false" );)
// D(printf("%s: isDark=%s\n", __func__, isDark ? "true" : "false" );)
if( !isDark )
{
aTrack->m_Flags |= DRAW_ERASED;
@ -192,7 +192,7 @@ static void fillLineTRACK( TRACK* aTrack, int Dcode_index, int aLayer,
aTrack->SetNet( Dcode_index );
D(printf("%s: isDark=%s\n", __func__, isDark ? "true" : "false" );)
//D(printf("%s: isDark=%s\n", __func__, isDark ? "true" : "false" );)
if( !isDark )
{
aTrack->m_Flags |= DRAW_ERASED;

View File

@ -1,120 +0,0 @@
/********************************************************/
/* Effacements : Routines de sauvegarde et d'effacement */
/********************************************************/
#include "fctsys.h"
#include "common.h"
#include "gerbview.h"
#include "protos.h"
/* Routines externes : */
/* Routines Locales */
/***********************************************/
void WinEDA_GerberFrame::UnDeleteItem( wxDC* DC )
/***********************************************/
/* Restitution d'un element (MODULE ou TRACK ) Efface
*/
{
BOARD_ITEM* item;
BOARD_ITEM* next;
int net_code;
if( !g_UnDeleteStackPtr )
return;
g_UnDeleteStackPtr--;
item = g_UnDeleteStack[g_UnDeleteStackPtr];
if( item == NULL )
return; // Ne devrait pas se produire
switch( item->Type() )
{
case TYPE_VIA:
case TYPE_TRACK:
for( ; item; item = next )
{
next = item->Next();
item->SetState( DELETED, OFF ); /* Effacement du bit DELETED */
Trace_Segment( DrawPanel, DC, (TRACK*) item, GR_OR );
}
item = g_UnDeleteStack[g_UnDeleteStackPtr];
net_code = ((TRACK*) item)->GetNet();
m_Pcb->Add( item );
g_UnDeleteStack[g_UnDeleteStackPtr] = NULL;
break;
default:
DisplayError( this, wxT( "Undelete struct: type Struct inattendu" ) );
break;
}
}
/********************************************************************/
BOARD_ITEM* SaveItemEfface( BOARD_ITEM* PtItem, int nbitems )
/********************************************************************/
/* Sauvegarde d'un element aux fins de restitution par Undelete
* Supporte actuellement : Module et segments de piste
*/
{
BOARD_ITEM* NextS, * PtStruct = PtItem;
int ii;
if( (PtItem == NULL) || (nbitems == 0) )
return NULL;
if( g_UnDeleteStackPtr >= UNDELETE_STACK_SIZE )
{
/* Delete last deleted item, and shift stack. */
g_UnDeleteStack[0]->DeleteStructure();
for( ii = 0; ii < (g_UnDeleteStackPtr - 1); ii++ )
{
g_UnDeleteStack[ii] = g_UnDeleteStack[ii + 1];
}
g_UnDeleteStackPtr--;;
}
g_UnDeleteStack[g_UnDeleteStackPtr++] = PtItem;
switch( PtStruct->Type() )
{
case TYPE_VIA:
case TYPE_TRACK:
{
EDA_BaseStruct* Back = NULL;
g_UnDeleteStack[g_UnDeleteStackPtr - 1] = PtStruct;
for( ; nbitems > 0; nbitems--, PtStruct = NextS )
{
NextS = PtStruct->Next();
( (TRACK*) PtStruct )->UnLink();
PtStruct->SetState( DELETED, ON );
if( nbitems <= 1 )
NextS = NULL; /* fin de chaine */
PtStruct->SetNext( NextS );
PtStruct->SetBack( Back );
Back = PtStruct;
if( NextS == NULL )
break;
}
}
break;
default:
break;
}
return g_UnDeleteStack[g_UnDeleteStackPtr - 1];
}

View File

@ -32,6 +32,13 @@ enum Track_Shapes {
*/
class BOARD_ITEM : public EDA_BaseStruct
{
// These are made private here so they may not be used.
// Instead everything derived from BOARD_ITEM is handled via DLIST<>'s
// use of DHEAD's member functions.
void SetNext( EDA_BaseStruct* aNext ) { Pnext = aNext; }
void SetBack( EDA_BaseStruct* aBack ) { Pback = aBack; }
protected:
int m_Layer;

View File

@ -128,6 +128,10 @@ public:
// PCB handling
bool Clear_Pcb( bool query );
void UnDeleteItem( wxDC* DC );
BOARD_ITEM* SaveItemEfface( BOARD_ITEM* aItem, int nbitems );
/**
* Function PcbGeneralLocateAndDisplay
* searches for an item under the mouse cursor.
@ -465,7 +469,6 @@ public:
void Erase_Modules( bool query );
void Erase_Textes_Pcb( bool query );
void Erase_Marqueurs();
void UnDeleteItem( wxDC* DC );
void RemoveStruct( BOARD_ITEM* Item, wxDC* DC );
void Via_Edit_Control( wxDC* DC, int command_type, SEGVIA* via );
@ -704,7 +707,6 @@ public:
void Show_1_Ratsnest( EDA_BaseStruct* item, wxDC* DC );
void Ratsnest_On_Off( wxDC* DC );
void Clean_Pcb( wxDC* DC );
BOARD_ITEM* SaveItemEfface( BOARD_ITEM* PtItem, int nbitems );
void InstallFindFrame( const wxPoint& pos, wxDC* DC );
@ -841,7 +843,6 @@ public:
void Erase_Segments_Pcb( bool is_edges, bool query );
void Erase_Pistes( int masque_type, bool query );
void Erase_Textes_Pcb( bool query );
void UnDeleteItem( wxDC* DC );
void Delete_DCode_Items( wxDC* DC, int dcode_value, int layer_number );
TRACK* Begin_Route( TRACK* track, wxDC* DC );

View File

@ -265,19 +265,20 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl )
}
void BOARD::Delete( BOARD_ITEM* aBoardItem )
BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
{
if ( aBoardItem == NULL ) return;
// find these calls and fix them! Don't send me no stinkin' NULL.
wxASSERT( aBoardItem );
switch( aBoardItem->Type() )
{
case TYPE_MARKER: // this one uses a vector
// find the item in the vector, then delete then erase it.
case TYPE_MARKER:
// find the item in the vector, then remove it
for( unsigned i=0; i<m_markers.size(); ++i )
{
if( m_markers[i] == (MARKER*) aBoardItem )
{
DeleteMARKER( i );
m_markers.erase( m_markers.begin() + i );
break;
}
}
@ -289,24 +290,23 @@ void BOARD::Delete( BOARD_ITEM* aBoardItem )
{
if( m_ZoneDescriptorList[i] == (ZONE_CONTAINER*) aBoardItem )
{
delete m_ZoneDescriptorList[i];
m_ZoneDescriptorList.erase(m_ZoneDescriptorList.begin() + i);
m_ZoneDescriptorList.erase( m_ZoneDescriptorList.begin() + i );
break;
}
}
break;
case TYPE_MODULE:
delete m_Modules.Remove( (MODULE*) aBoardItem );
m_Modules.Remove( (MODULE*) aBoardItem );
break;
case TYPE_TRACK:
case TYPE_VIA:
delete m_Track.Remove( (TRACK*) aBoardItem );
m_Track.Remove( (TRACK*) aBoardItem );
break;
case TYPE_ZONE:
delete m_Zone.Remove( (SEGZONE*) aBoardItem );
m_Zone.Remove( (SEGZONE*) aBoardItem );
break;
case TYPE_COTATION:
@ -314,27 +314,19 @@ void BOARD::Delete( BOARD_ITEM* aBoardItem )
case TYPE_TEXTE:
case TYPE_EDGE_MODULE:
case TYPE_MIRE:
delete m_Drawings.Remove( aBoardItem );
m_Drawings.Remove( aBoardItem );
break;
case TYPE_EQUIPOT:
delete m_Equipots.Remove( (EQUIPOT*) aBoardItem );
m_Equipots.Remove( (EQUIPOT*) aBoardItem );
break;
// other types may use linked list
default:
wxFAIL_MSG( wxT("BOARD::Delete() needs work") );
wxFAIL_MSG( wxT("BOARD::Remove() needs more ::Type() support") );
}
}
void BOARD::DeleteMARKER( int aIndex )
{
if( (unsigned) aIndex < m_markers.size() )
{
delete m_markers[aIndex];
m_markers.erase( m_markers.begin() + aIndex );
}
return aBoardItem;
}

View File

@ -128,11 +128,26 @@ public:
/**
* Function Delete
* deletes the given single item from this BOARD and deletes its memory. If you
* need the object after deletion, first copy it.
* removes the given single item from this BOARD and deletes its memory.
* @param aBoardItem The item to remove from this board and delete
*/
void Delete( BOARD_ITEM* aBoardItem );
void Delete( BOARD_ITEM* aBoardItem )
{
wxASSERT( aBoardItem ); // developers should run DEBUG versions and fix such calls with NULL
if( aBoardItem )
delete Remove( aBoardItem );
}
/**
* Function Remove
* removes \a aBoardItem from this BOARD and returns it to caller without
* deleting it.
* @param aBoardItem The item to remove from this board.
* @return BOARD_ITEM* \a aBoardItem which was passed in.
*/
BOARD_ITEM* Remove( BOARD_ITEM* aBoardItem );
/**
* Function DeleteMARKERs
@ -147,14 +162,6 @@ public:
void DeleteZONEOutlines();
/**
* Function DeleteMARKER
* deletes one MARKER from the board.
* @param aIndex The index of the marker to delete.
*/
void DeleteMARKER( int aIndex );
/**
* Function GetMARKER
* returns the MARKER at a given index.
@ -168,7 +175,6 @@ public:
return NULL;
}
/**
* Function GetMARKERCount
* @return int - The number of MARKERS.

View File

@ -68,10 +68,10 @@ MODULE::MODULE( BOARD* parent ) :
m_LastEdit_Time = time( NULL );
m_Reference = new TEXTE_MODULE( this, TEXT_is_REFERENCE );
m_Reference->SetBack( this );
// m_Reference->SetBack( this );
m_Value = new TEXTE_MODULE( this, TEXT_is_VALUE );
m_Value->SetBack( this );
// m_Value->SetBack( this );
m_3D_Drawings.PushBack( new S3D_MASTER( this ) );
}
@ -342,32 +342,31 @@ int MODULE::Write_3D_Descr( FILE* File ) const
*/
{
char buf[512];
S3D_MASTER* Struct3D = m_3D_Drawings;
for( ; Struct3D != NULL; Struct3D = Struct3D->Next() )
for( S3D_MASTER* t3D = m_3D_Drawings; t3D; t3D = t3D->Next() )
{
if( !Struct3D->m_Shape3DName.IsEmpty() )
if( !t3D->m_Shape3DName.IsEmpty() )
{
fprintf( File, "$SHAPE3D\n" );
fprintf( File, "Na \"%s\"\n", CONV_TO_UTF8( Struct3D->m_Shape3DName ) );
fprintf( File, "Na \"%s\"\n", CONV_TO_UTF8( t3D->m_Shape3DName ) );
sprintf( buf, "Sc %lf %lf %lf\n",
Struct3D->m_MatScale.x,
Struct3D->m_MatScale.y,
Struct3D->m_MatScale.z );
t3D->m_MatScale.x,
t3D->m_MatScale.y,
t3D->m_MatScale.z );
fprintf( File, to_point( buf ) );
sprintf( buf, "Of %lf %lf %lf\n",
Struct3D->m_MatPosition.x,
Struct3D->m_MatPosition.y,
Struct3D->m_MatPosition.z );
t3D->m_MatPosition.x,
t3D->m_MatPosition.y,
t3D->m_MatPosition.z );
fprintf( File, to_point( buf ) );
sprintf( buf, "Ro %lf %lf %lf\n",
Struct3D->m_MatRotation.x,
Struct3D->m_MatRotation.y,
Struct3D->m_MatRotation.z );
t3D->m_MatRotation.x,
t3D->m_MatRotation.y,
t3D->m_MatRotation.z );
fprintf( File, to_point( buf ) );
fprintf( File, "$EndSHAPE3D\n" );
@ -390,15 +389,15 @@ int MODULE::Read_3D_Descr( FILE* File, int* LineNum )
char Line[1024];
char* text = Line + 3;
S3D_MASTER* Struct3D = m_3D_Drawings;
S3D_MASTER* t3D = m_3D_Drawings;
if( !Struct3D->m_Shape3DName.IsEmpty() )
if( !t3D->m_Shape3DName.IsEmpty() )
{
S3D_MASTER* n3D = new S3D_MASTER( this );
m_3D_Drawings.PushBack( n3D );
Struct3D = n3D;
t3D = n3D;
}
while( GetLine( File, Line, LineNum, sizeof(Line) - 1 ) != NULL )
@ -414,29 +413,29 @@ int MODULE::Read_3D_Descr( FILE* File, int* LineNum )
{
char buf[512];
ReadDelimitedText( buf, text, 512 );
Struct3D->m_Shape3DName = CONV_FROM_UTF8( buf );
t3D->m_Shape3DName = CONV_FROM_UTF8( buf );
break;
}
case 'S': // Scale
sscanf( text, "%lf %lf %lf\n",
&Struct3D->m_MatScale.x,
&Struct3D->m_MatScale.y,
&Struct3D->m_MatScale.z );
&t3D->m_MatScale.x,
&t3D->m_MatScale.y,
&t3D->m_MatScale.z );
break;
case 'O': // Offset
sscanf( text, "%lf %lf %lf\n",
&Struct3D->m_MatPosition.x,
&Struct3D->m_MatPosition.y,
&Struct3D->m_MatPosition.z );
&t3D->m_MatPosition.x,
&t3D->m_MatPosition.y,
&t3D->m_MatPosition.z );
break;
case 'R': // Rotation
sscanf( text, "%lf %lf %lf\n",
&Struct3D->m_MatRotation.x,
&Struct3D->m_MatRotation.y,
&Struct3D->m_MatRotation.z );
&t3D->m_MatRotation.x,
&t3D->m_MatRotation.y,
&t3D->m_MatRotation.z );
break;
default:
@ -681,18 +680,18 @@ void MODULE::SetOrientation( int newangle )
m_Value->SetDrawCoord();
/* deplacement des contours et textes de l'empreinte : */
EDA_BaseStruct* PtStruct = m_Drawings;
for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
for( BOARD_ITEM* item = m_Drawings; item; item = item->Next() )
{
if( PtStruct->Type() == TYPE_EDGE_MODULE )
if( item->Type() == TYPE_EDGE_MODULE )
{
EDGE_MODULE* pt_edgmod = (EDGE_MODULE*) PtStruct;
EDGE_MODULE* pt_edgmod = (EDGE_MODULE*) item;
pt_edgmod->SetDrawCoord();
}
if( PtStruct->Type() == TYPE_TEXTE_MODULE )
if( item->Type() == TYPE_TEXTE_MODULE )
{
/* deplacement des inscriptions : */
TEXTE_MODULE* pt_texte = (TEXTE_MODULE*) PtStruct;
TEXTE_MODULE* pt_texte = (TEXTE_MODULE*) item;
pt_texte->SetDrawCoord();
}
}

View File

@ -80,7 +80,9 @@ public:
void DeleteItem( int aIndex )
{
m_board->DeleteMARKER( aIndex );
MARKER* marker = m_board->GetMARKER( aIndex );
if( marker )
m_board->Delete( marker );
}

View File

@ -407,9 +407,9 @@ MODULE* WinEDA_PcbFrame::Genere_Self( wxDC* DC )
newedge->Copy( PtSegm );
Module->m_Drawings.Insert( newedge, PtSegm->Next() );
PtSegm = newedge;
PtSegm->m_Start = PtSegm->m_End;
PtSegm->m_End = Mself.m_End;
PtSegm->SetNext( NULL );
/* Rotation de la self si le trace doit etre horizontal : */
LastSegm = PtSegm;
@ -426,8 +426,7 @@ MODULE* WinEDA_PcbFrame::Genere_Self( wxDC* DC )
}
/* Modif position ancre */
Module->m_Pos.x = LastSegm->m_End.x;
Module->m_Pos.y = LastSegm->m_End.y;
Module->m_Pos = LastSegm->m_End;
/* Placement des 2 pads sur extremite */
PtPad = new D_PAD( Module );
@ -512,7 +511,8 @@ static EDGE_MODULE* gen_arc( EDGE_MODULE* PtSegm, int cX, int cY, int angle )
wxASSERT( list );
angle = -angle;
y0 = PtSegm->m_Start.x - cX; x0 = PtSegm->m_Start.y - cY;
y0 = PtSegm->m_Start.x - cX;
x0 = PtSegm->m_Start.y - cY;
nb_seg = ( abs( angle ) ) / 225; if( nb_seg == 0 )
nb_seg = 1;

View File

@ -8,14 +8,13 @@
#include "common.h"
#include "pcbnew.h"
#include "protos.h"
/* Routines externes : */
/* Routines Locales */
/********************************************/
void WinEDA_PcbFrame::UnDeleteItem( wxDC* DC )
void WinEDA_BasePcbFrame::UnDeleteItem( wxDC* DC )
/********************************************/
/* Restitution d'un element (MODULE ou TRACK ) Efface
@ -32,6 +31,12 @@ void WinEDA_PcbFrame::UnDeleteItem( wxDC* DC )
if( item == NULL )
return; // Ne devrait pas se produire
// we decremented the stack pointer, so the stack no longer
// owns "item". We do here, so we have to delete item if its
// not going back into the board, see default case below.
g_UnDeleteStack[g_UnDeleteStackPtr] = NULL;
switch( item->Type() )
{
case TYPE_VIA:
@ -48,8 +53,11 @@ void WinEDA_PcbFrame::UnDeleteItem( wxDC* DC )
m_Pcb->Add( track );
net_code = track->GetNet();
g_UnDeleteStack[g_UnDeleteStackPtr] = NULL;
#if !defined(GERBVIEW)
test_1_net_connexion( DC, net_code );
#endif
m_Pcb->Display_Infos( this );
break;
@ -66,31 +74,35 @@ void WinEDA_PcbFrame::UnDeleteItem( wxDC* DC )
net_code = t->GetNet();
}
delete list;
g_UnDeleteStack[g_UnDeleteStackPtr] = NULL;
#if !defined(GERBVIEW)
test_1_net_connexion( DC, net_code );
#endif
m_Pcb->Display_Infos( this );
break;
#if !defined(GERBVIEW)
case TYPE_MODULE:
/* Erase general rastnest if needed */
// Erase general rastnest if needed
if( g_Show_Ratsnest )
DrawGeneralRatsnest( DC );
m_Pcb->Add( item );
g_UnDeleteStack[g_UnDeleteStackPtr] = NULL;
item->Draw( DrawPanel, DC, GR_OR );
item->SetState( DELETED, OFF ); /* Creal DELETED flag */
item->m_Flags = 0;
m_Pcb->m_Status_Pcb = 0;
build_liste_pads();
ReCompile_Ratsnest_After_Changes( DC );
break;
#endif
default:
DisplayError( this, wxT( "WinEDA_PcbFrame::UnDeleteItem(): unexpected Struct type" ) );
delete item;
break;
}
}
@ -99,7 +111,7 @@ void WinEDA_PcbFrame::UnDeleteItem( wxDC* DC )
/* Sauvegarde d'un element aux fins de restitution par Undelete
* Supporte actuellement : Module et segments de piste
*/
BOARD_ITEM* WinEDA_PcbFrame::SaveItemEfface( BOARD_ITEM* aItem, int nbitems )
BOARD_ITEM* WinEDA_BasePcbFrame::SaveItemEfface( BOARD_ITEM* aItem, int nbitems )
{
if( aItem == NULL || nbitems == 0 )
return NULL;
@ -135,6 +147,7 @@ BOARD_ITEM* WinEDA_PcbFrame::SaveItemEfface( BOARD_ITEM* aItem, int nbitems )
BOARD_ITEM_LIST* list = new BOARD_ITEM_LIST();
g_UnDeleteStack[g_UnDeleteStackPtr++] = list;
// copy the numerous tracks into the list, which is already on stack
int i = 0;
TRACK* next;
for( TRACK* track = (TRACK*) aItem; track && i<nbitems; track = next, ++i )
@ -146,6 +159,7 @@ BOARD_ITEM* WinEDA_PcbFrame::SaveItemEfface( BOARD_ITEM* aItem, int nbitems )
}
break;
#if !defined(GERBVIEW)
case TYPE_MODULE:
{
MODULE* module = (MODULE*) aItem;
@ -155,10 +169,12 @@ BOARD_ITEM* WinEDA_PcbFrame::SaveItemEfface( BOARD_ITEM* aItem, int nbitems )
build_liste_pads();
}
break;
#endif
default:
break;
}
// don't know why this is not simply return aItem?
return g_UnDeleteStack[g_UnDeleteStackPtr - 1];
}