From d814889db7824f866e6f1038a991fef5d7bfc283 Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Sat, 6 Dec 2008 21:20:50 +0000 Subject: [PATCH] gerbview, pcbnew's BOARD container changes --- change_log.txt | 21 +++++++ gerbview/CMakeLists.txt | 4 +- gerbview/protos.h | 6 -- gerbview/rs274d.cpp | 6 +- gerbview/undelete.cpp | 120 ------------------------------------ include/board_item_struct.h | 7 +++ include/wxPcbStruct.h | 7 ++- pcbnew/class_board.cpp | 36 +++++------ pcbnew/class_board.h | 30 +++++---- pcbnew/class_module.cpp | 67 ++++++++++---------- pcbnew/dialog_drc.cpp | 4 +- pcbnew/gen_self.h | 8 +-- pcbnew/undelete.cpp | 32 +++++++--- 13 files changed, 133 insertions(+), 215 deletions(-) delete mode 100644 gerbview/undelete.cpp diff --git a/change_log.txt b/change_log.txt index c5339c48cd..e29745eb99 100644 --- a/change_log.txt +++ b/change_log.txt @@ -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 +================================================================================ +++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 ================================================================================ ++pcbnew & gerbview diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt index 118513f201..1d65ae638a 100644 --- a/gerbview/CMakeLists.txt +++ b/gerbview/CMakeLists.txt @@ -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 diff --git a/gerbview/protos.h b/gerbview/protos.h index e7040004ff..8ec2267303 100644 --- a/gerbview/protos.h +++ b/gerbview/protos.h @@ -5,12 +5,6 @@ /***************************/ int * InstallDialogLayerPairChoice(WinEDA_GerberFrame * parent); -/****************/ -/* undelete.cpp */ -/****************/ -BOARD_ITEM* SaveItemEfface( BOARD_ITEM* PtItem, int nbitems ); - - /***********************/ /* gerbview_config.cpp */ /***********************/ diff --git a/gerbview/rs274d.cpp b/gerbview/rs274d.cpp index 0d16a299bc..6c33858ac3 100644 --- a/gerbview/rs274d.cpp +++ b/gerbview/rs274d.cpp @@ -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; diff --git a/gerbview/undelete.cpp b/gerbview/undelete.cpp deleted file mode 100644 index 301d8c0384..0000000000 --- a/gerbview/undelete.cpp +++ /dev/null @@ -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]; -} diff --git a/include/board_item_struct.h b/include/board_item_struct.h index a18bc0956a..ad8e0cf7ab 100644 --- a/include/board_item_struct.h +++ b/include/board_item_struct.h @@ -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; diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 16d6ce0d14..ba2022506a 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -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 ); diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 6745f97bfb..af34b08b5b 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -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; iSetBack( 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(); } } diff --git a/pcbnew/dialog_drc.cpp b/pcbnew/dialog_drc.cpp index 2ffa05ef2d..f4c0c38afb 100644 --- a/pcbnew/dialog_drc.cpp +++ b/pcbnew/dialog_drc.cpp @@ -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 ); } diff --git a/pcbnew/gen_self.h b/pcbnew/gen_self.h index dfce2d8cd9..68ca599f56 100644 --- a/pcbnew/gen_self.h +++ b/pcbnew/gen_self.h @@ -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; diff --git a/pcbnew/undelete.cpp b/pcbnew/undelete.cpp index 5e064a89ee..9a437d149b 100644 --- a/pcbnew/undelete.cpp +++ b/pcbnew/undelete.cpp @@ -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