Commit 4715ea28 authored by dickelbeck's avatar dickelbeck

delete hierarhical pin sheet bug

parent 6f4f6f6e
...@@ -5,6 +5,22 @@ Started 2007-June-11 ...@@ -5,6 +5,22 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with Please add newer entries at the top, list the date and your name with
email address. email address.
2008-Apr-22 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
+eeschema
* Spent a 1/2 day tracking down two linked list bugs in deleting a
DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE. I cannot believe in the year
2008 we should have to debug a linked list function. This is stuff I expected
to do 20 years ago, not today. The function
void WinEDA_SchematicFrame::DeleteSheetLabel( wxDC* DC,
Hierarchical_PIN_Sheet_Struct* SheetLabelToDel ) never worked as
far as I can tell.
Should switch to boost::ptr_vector ASAP everywhere, and leave linked lists in the 1980's.
* Hierarchical_PIN_Sheet_Struct::Hierarchical_PIN_Sheet_Struct() was not
setting the m_Parent.
2008-Apr-21 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr> 2008-Apr-21 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================ ================================================================================
+eeschema +eeschema
......
...@@ -161,22 +161,12 @@ std::ostream& operator<<( std::ostream& out, const wxPoint& pt ) ...@@ -161,22 +161,12 @@ std::ostream& operator<<( std::ostream& out, const wxPoint& pt )
*/ */
void EDA_BaseStruct::Show( int nestLevel, std::ostream& os ) void EDA_BaseStruct::Show( int nestLevel, std::ostream& os )
{ {
// for now, make it look like XML: // XML output:
wxString s = GetClass(); wxString s = GetClass();
s = s + wxT( " " ); NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">"
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">\n"; << " Need ::Show() override for this class "
<< "</" << s.Lower().mb_str() << ">\n";
/*
* EDA_BaseStruct* kid = m_Son;
* for( ; kid; kid = kid->Pnext )
* {
* kid->Show( nestLevel+1, os );
* }
*/
NestedSpace( nestLevel + 1, os ) << "Need ::Show() override\n";
NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";
} }
...@@ -195,7 +185,6 @@ std::ostream& EDA_BaseStruct::NestedSpace( int nestLevel, std::ostream& os ) ...@@ -195,7 +185,6 @@ std::ostream& EDA_BaseStruct::NestedSpace( int nestLevel, std::ostream& os )
return os; return os;
} }
#endif #endif
......
...@@ -631,6 +631,28 @@ bool DrawSheetStruct::ChangeFileName( WinEDA_SchematicFrame* aFrame, const wxStr ...@@ -631,6 +631,28 @@ bool DrawSheetStruct::ChangeFileName( WinEDA_SchematicFrame* aFrame, const wxStr
} }
#if defined(DEBUG)
void DrawSheetStruct::Show( int nestLevel, std::ostream& os )
{
// XML output:
wxString s = GetClass();
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">"
<< " sheet_name=\"" << CONV_TO_UTF8( m_SheetName) << '"'
<< ">\n";
// show all the pins, and check the linked list integrity
Hierarchical_PIN_Sheet_Struct* label;
for( label = m_Label; label; label=label->Next() )
{
label->Show( nestLevel+1, os );
}
NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n"
<< std::flush;
}
#endif
/**********************************************/ /**********************************************/
/* class to handle a series of sheets *********/ /* class to handle a series of sheets *********/
...@@ -815,3 +837,4 @@ bool DrawSheetPath::operator!=( const DrawSheetPath& d1 ) ...@@ -815,3 +837,4 @@ bool DrawSheetPath::operator!=( const DrawSheetPath& d1 )
return false; return false;
} }
...@@ -29,6 +29,7 @@ public: ...@@ -29,6 +29,7 @@ public:
const wxString& text = wxEmptyString ); const wxString& text = wxEmptyString );
~Hierarchical_PIN_Sheet_Struct() { } ~Hierarchical_PIN_Sheet_Struct() { }
virtual wxString GetClass() const virtual wxString GetClass() const
{ {
return wxT( "Hierarchical_PIN_Sheet_Struct" ); return wxT( "Hierarchical_PIN_Sheet_Struct" );
...@@ -37,11 +38,10 @@ public: ...@@ -37,11 +38,10 @@ public:
Hierarchical_PIN_Sheet_Struct* GenCopy(); Hierarchical_PIN_Sheet_Struct* GenCopy();
Hierarchical_PIN_Sheet_Struct* Next() Hierarchical_PIN_Sheet_Struct* Next() { return (Hierarchical_PIN_Sheet_Struct*) Pnext; }
{ return (Hierarchical_PIN_Sheet_Struct*) Pnext; }
void Place( WinEDA_SchematicFrame* frame, wxDC* DC ); void Place( WinEDA_SchematicFrame* frame, wxDC* DC );
void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
int draw_mode, int Color = -1 ); int draw_mode, int Color = -1 );
/** /**
...@@ -50,7 +50,12 @@ public: ...@@ -50,7 +50,12 @@ public:
* @param aFile The FILE to write to. * @param aFile The FILE to write to.
* @return bool - true if success writing else false. * @return bool - true if success writing else false.
*/ */
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
#if defined(DEBUG)
// comment inherited by Doxygen from Base_Struct
void Show( int nestLevel, std::ostream& os );
#endif
}; };
...@@ -120,6 +125,11 @@ public: ...@@ -120,6 +125,11 @@ public:
//void RemoveSheet(DrawSheetStruct* sheet); //void RemoveSheet(DrawSheetStruct* sheet);
//to remove a sheet, just delete it //to remove a sheet, just delete it
//-- the destructor should take care of everything else. //-- the destructor should take care of everything else.
#if defined(DEBUG)
// comment inherited by Doxygen from Base_Struct
void Show( int nestLevel, std::ostream& os );
#endif
}; };
......
...@@ -36,10 +36,12 @@ ...@@ -36,10 +36,12 @@
/*******************************************************************/ /*******************************************************************/
Hierarchical_PIN_Sheet_Struct::Hierarchical_PIN_Sheet_Struct( DrawSheetStruct* parent, Hierarchical_PIN_Sheet_Struct::Hierarchical_PIN_Sheet_Struct( DrawSheetStruct* parent,
const wxPoint& pos, const wxString& text ) : const wxPoint& pos, const wxString& text ) :
SCH_ITEM( NULL, DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ), SCH_ITEM( parent, DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ),
EDA_TextStruct( text ) EDA_TextStruct( text )
/*******************************************************************/ /*******************************************************************/
{ {
wxASSERT( parent );
wxASSERT( Pnext == NULL );
m_Layer = LAYER_SHEETLABEL; m_Layer = LAYER_SHEETLABEL;
m_Pos = pos; m_Pos = pos;
m_Edge = 0; m_Edge = 0;
...@@ -199,3 +201,19 @@ bool Hierarchical_PIN_Sheet_Struct::Save( FILE* aFile ) const ...@@ -199,3 +201,19 @@ bool Hierarchical_PIN_Sheet_Struct::Save( FILE* aFile ) const
return true; return true;
} }
#if defined(DEBUG)
void Hierarchical_PIN_Sheet_Struct::Show( int nestLevel, std::ostream& os )
{
// XML output:
wxString s = GetClass();
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">"
<< " pin_name=\"" << CONV_TO_UTF8( m_Text ) << '"'
<< "/>\n"
<< std::flush;
// NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";
}
#endif
...@@ -154,6 +154,20 @@ EDA_Rect DrawJunctionStruct::GetBoundingBox() ...@@ -154,6 +154,20 @@ EDA_Rect DrawJunctionStruct::GetBoundingBox()
}; };
#if defined(DEBUG)
void DrawJunctionStruct::Show( int nestLevel, std::ostream& os )
{
// XML output:
wxString s = GetClass();
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str()
<< m_Pos
<< "/>\n";
}
#endif
/*****************************/ /*****************************/
/* class DrawNoConnectStruct */ /* class DrawNoConnectStruct */
/*****************************/ /*****************************/
...@@ -245,8 +259,6 @@ void DrawMarkerStruct::Show( int nestLevel, std::ostream& os ) ...@@ -245,8 +259,6 @@ void DrawMarkerStruct::Show( int nestLevel, std::ostream& os )
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << m_Pos NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << m_Pos
<< "/>\n"; << "/>\n";
} }
#endif #endif
/** /**
......
...@@ -196,6 +196,24 @@ bool SCH_TEXT::Save( FILE* aFile ) const ...@@ -196,6 +196,24 @@ bool SCH_TEXT::Save( FILE* aFile ) const
} }
#if defined(DEBUG)
void SCH_TEXT::Show( int nestLevel, std::ostream& os )
{
// XML output:
wxString s = GetClass();
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str()
<< " layer=\"" << m_Layer << '"'
<< " shape=\"" << m_Shape << '"'
<< " dangling=\"" << m_IsDangling << '"'
<< '>'
<< CONV_TO_UTF8( m_Text )
<< "</" << s.Lower().mb_str() << ">\n";
}
#endif
/****************************************************************************/ /****************************************************************************/
SCH_LABEL::SCH_LABEL( const wxPoint& pos, const wxString& text ) : SCH_LABEL::SCH_LABEL( const wxPoint& pos, const wxString& text ) :
SCH_TEXT( pos, text, TYPE_SCH_LABEL ) SCH_TEXT( pos, text, TYPE_SCH_LABEL )
......
...@@ -112,6 +112,11 @@ public: ...@@ -112,6 +112,11 @@ public:
*/ */
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os );
#endif
}; };
......
...@@ -62,9 +62,12 @@ bool SegmentIntersect( int Sx1, int Sy1, int Sx2, int Sy2, ...@@ -62,9 +62,12 @@ bool SegmentIntersect( int Sx1, int Sy1, int Sx2, int Sy2,
if( Sx1 == Sx2 ) /* Line S is vertical. */ if( Sx1 == Sx2 ) /* Line S is vertical. */
{ {
Symin = MIN( Sy1, Sy2 ); Symax = MAX( Sy1, Sy2 ); Symin = MIN( Sy1, Sy2 );
Symax = MAX( Sy1, Sy2 );
if( Px1 != Sx1 ) if( Px1 != Sx1 )
return FALSE; return FALSE;
if( Py1 >= Symin && Py1 <= Symax ) if( Py1 >= Symin && Py1 <= Symax )
return TRUE; return TRUE;
else else
...@@ -72,9 +75,12 @@ bool SegmentIntersect( int Sx1, int Sy1, int Sx2, int Sy2, ...@@ -72,9 +75,12 @@ bool SegmentIntersect( int Sx1, int Sy1, int Sx2, int Sy2,
} }
else if( Sy1 == Sy2 ) /* Line S is horizontal. */ else if( Sy1 == Sy2 ) /* Line S is horizontal. */
{ {
Sxmin = MIN( Sx1, Sx2 ); Sxmax = MAX( Sx1, Sx2 ); Sxmin = MIN( Sx1, Sx2 );
Sxmax = MAX( Sx1, Sx2 );
if( Py1 != Sy1 ) if( Py1 != Sy1 )
return FALSE; return FALSE;
if( Px1 >= Sxmin && Px1 <= Sxmax ) if( Px1 >= Sxmin && Px1 <= Sxmax )
return TRUE; return TRUE;
else else
...@@ -92,35 +98,34 @@ void WinEDA_SchematicFrame::TestDanglingEnds( SCH_ITEM* DrawList, wxDC* DC ) ...@@ -92,35 +98,34 @@ void WinEDA_SchematicFrame::TestDanglingEnds( SCH_ITEM* DrawList, wxDC* DC )
/* Met a jour les membres m_Dangling des wires, bus, labels /* Met a jour les membres m_Dangling des wires, bus, labels
*/ */
{ {
EDA_BaseStruct* DrawItem;
const DanglingEndHandle* DanglingItem, * nextitem;
if( ItemList ) if( ItemList )
{
const DanglingEndHandle* DanglingItem;
const DanglingEndHandle* nextitem;
for( DanglingItem = ItemList; DanglingItem != NULL; DanglingItem = nextitem ) for( DanglingItem = ItemList; DanglingItem != NULL; DanglingItem = nextitem )
{ {
nextitem = DanglingItem->m_Pnext; nextitem = DanglingItem->m_Pnext;
SAFE_DELETE( DanglingItem ); SAFE_DELETE( DanglingItem );
} }
}
ItemList = RebuildEndList( DrawList ); ItemList = RebuildEndList( DrawList );
// Controle des elements // Controle des elements
for( DrawItem = DrawList; DrawItem != NULL; DrawItem = DrawItem->Next() ) for( SCH_ITEM* item = DrawList; item; item = item->Next() )
{ {
switch( DrawItem->Type() ) switch( item->Type() )
{ {
case TYPE_SCH_GLOBALLABEL: case TYPE_SCH_GLOBALLABEL:
case TYPE_SCH_HIERLABEL: case TYPE_SCH_HIERLABEL:
case TYPE_SCH_LABEL: case TYPE_SCH_LABEL:
#undef STRUCT TestLabelForDangling( (SCH_LABEL*) item, this, DC );
#define STRUCT ( (SCH_LABEL*) DrawItem )
TestLabelForDangling( STRUCT, this, DC );
break;
break; break;
case DRAW_SEGMENT_STRUCT_TYPE: case DRAW_SEGMENT_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ( (EDA_DrawLineStruct*) DrawItem ) #define STRUCT ( (EDA_DrawLineStruct*) item )
if( STRUCT->GetLayer() == LAYER_WIRE ) if( STRUCT->GetLayer() == LAYER_WIRE )
{ {
TestWireForDangling( STRUCT, this, DC ); TestWireForDangling( STRUCT, this, DC );
...@@ -432,26 +437,26 @@ DanglingEndHandle* RebuildEndList( EDA_BaseStruct* DrawList ) ...@@ -432,26 +437,26 @@ DanglingEndHandle* RebuildEndList( EDA_BaseStruct* DrawList )
} }
case DRAW_SHEET_STRUCT_TYPE: case DRAW_SHEET_STRUCT_TYPE:
{
#undef STRUCT
#define STRUCT ( (DrawSheetStruct*) DrawItem )
Hierarchical_PIN_Sheet_Struct* pinsheet = STRUCT->m_Label;
while( pinsheet )
{ {
item = new DanglingEndHandle( SHEET_LABEL_END ); Hierarchical_PIN_Sheet_Struct* pinsheet;
for( pinsheet = ((DrawSheetStruct*)DrawItem)->m_Label; pinsheet; pinsheet = pinsheet->Next() )
{
wxASSERT( pinsheet->Type() == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE );
item->m_Item = pinsheet; item = new DanglingEndHandle( SHEET_LABEL_END );
item->m_Pos = pinsheet->m_Pos;
if( lastitem ) item->m_Item = pinsheet;
lastitem->m_Pnext = item; item->m_Pos = pinsheet->m_Pos;
else
StartList = item;
lastitem = item;
pinsheet = (Hierarchical_PIN_Sheet_Struct*) pinsheet->Pnext;
}
if( lastitem )
lastitem->m_Pnext = item;
else
StartList = item;
lastitem = item;
}
}
break; break;
}
default: default:
; ;
......
...@@ -473,7 +473,7 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& F ...@@ -473,7 +473,7 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& F
screen->EEDrawList = Phead; screen->EEDrawList = Phead;
#if 0 && defined(DEBUG) #if 1 && defined(DEBUG)
screen->Show( 0, std::cout ); screen->Show( 0, std::cout );
#endif #endif
......
...@@ -107,13 +107,6 @@ public: ...@@ -107,13 +107,6 @@ public:
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
#if defined(DEBUG) #if defined(DEBUG)
/**
* Function Show
* is used to output the object tree, currently for debugging only.
* @param nestLevel An aid to prettier tree indenting, and is the level
* of nesting of this object within the overall tree.
* @param os The ostream& to output to.
*/
void Show( int nestLevel, std::ostream& os ); void Show( int nestLevel, std::ostream& os );
#endif #endif
}; };
...@@ -149,13 +142,6 @@ public: ...@@ -149,13 +142,6 @@ public:
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
#if defined(DEBUG) #if defined(DEBUG)
/**
* Function Show
* is used to output the object tree, currently for debugging only.
* @param nestLevel An aid to prettier tree indenting, and is the level
* of nesting of this object within the overall tree.
* @param os The ostream& to output to.
*/
void Show( int nestLevel, std::ostream& os ); void Show( int nestLevel, std::ostream& os );
#endif #endif
}; };
...@@ -287,6 +273,10 @@ public: ...@@ -287,6 +273,10 @@ public:
*/ */
bool Save( FILE* aFile ) const; bool Save( FILE* aFile ) const;
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os );
#endif
}; };
......
...@@ -408,8 +408,8 @@ Hierarchical_PIN_Sheet_Struct* WinEDA_SchematicFrame::Import_PinSheet( DrawSheet ...@@ -408,8 +408,8 @@ Hierarchical_PIN_Sheet_Struct* WinEDA_SchematicFrame::Import_PinSheet( DrawSheet
/**************************************************************/ /**************************************************************/
void WinEDA_SchematicFrame::DeleteSheetLabel( wxDC* DC, void WinEDA_SchematicFrame::DeleteSheetLabel( wxDC* DC,
Hierarchical_PIN_Sheet_Struct* SheetLabelToDel ) Hierarchical_PIN_Sheet_Struct* SheetLabelToDel )
/**************************************************************/ /**************************************************************/
/* /*
...@@ -419,43 +419,41 @@ void WinEDA_SchematicFrame::DeleteSheetLabel( wxDC* DC, ...@@ -419,43 +419,41 @@ void WinEDA_SchematicFrame::DeleteSheetLabel( wxDC* DC,
* si DC != NULL, effacement a l'ecran du dessin * si DC != NULL, effacement a l'ecran du dessin
*/ */
{ {
EDA_BaseStruct* DrawStruct;
Hierarchical_PIN_Sheet_Struct* SheetLabel, * NextLabel;
if( DC ) if( DC )
RedrawOneStruct( DrawPanel, DC, SheetLabelToDel, g_XorMode ); RedrawOneStruct( DrawPanel, DC, SheetLabelToDel, g_XorMode );
/* Recherche de la DrawSheetStruct d'origine */ DrawSheetStruct* parent = (DrawSheetStruct*) SheetLabelToDel->m_Parent;
DrawStruct = SheetLabelToDel->m_Parent;
wxASSERT( parent );
wxASSERT( parent->Type() == DRAW_SHEET_STRUCT_TYPE );
#if 0 && defined(DEBUG)
std::cout << "\n\nbefore deleting:\n" << std::flush;
parent->Show( 0, std::cout );
std::cout << "\n\n\n" << std::flush;
#endif
Hierarchical_PIN_Sheet_Struct* label = parent->m_Label;
if( DrawStruct ) // Modification du chainage Hierarchical_PIN_Sheet_Struct** pprev = &parent->m_Label;
while( label )
{ {
if( DrawStruct->Type() != DRAW_SHEET_STRUCT_TYPE ) if( label == SheetLabelToDel )
{ {
DisplayError( this, *pprev = label->Next();
wxT( "DeleteSheetLabel error: m_Parent != DRAW_SHEET_STRUCT_TYPE" ) ); break;
return;
} }
/* suppression chainage */ pprev = (Hierarchical_PIN_Sheet_Struct**) &label->Pnext;
SheetLabel = ( (DrawSheetStruct*) DrawStruct )->m_Label; label = label->Next();
if( SheetLabel == SheetLabelToDel )
( (DrawSheetStruct*) DrawStruct )->m_Label =
(Hierarchical_PIN_Sheet_Struct*) SheetLabel->Pnext;
else
while( SheetLabel ) /* Examen de la liste dependante et suppression chainage */
{
NextLabel = (Hierarchical_PIN_Sheet_Struct*) SheetLabel->Pnext;
if( NextLabel == SheetLabelToDel )
{
SheetLabel->Pnext = NextLabel->Pnext;
break;;
}
SheetLabel = NextLabel;
}
} }
delete SheetLabelToDel; delete SheetLabelToDel;
#if 0 && defined(DEBUG)
std::cout << "\n\nafter deleting:\n" << std::flush;
parent->Show( 0, std::cout );
std::cout << "~after deleting\n\n" << std::flush;
#endif
} }
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