Commit 2a1b776b authored by CHARRAS's avatar CHARRAS
Browse files

see changelog

parent df7e6f37
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -5,6 +5,23 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.

2008-Feb-26 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+eeschema
	changed in class DrawSheetStruct m_s member name to m_AssociatedScreen
	some others minor problems solved.
	some files "uncrustified"
	Major problem in undo/redo when a sheet is deleted not yet solved
	Only for a complex hierarchy, could lost data.
	When a sheet is deleted by block delete. it is put in undo list.
	It is really deleted after 10 changes (when the undo list is full).
	At this time, the associated data is also deleted.
	If an other (not deleted) sheet shares the same data, this data is lost.
	Need work to solve this problem and keep the undo/redo feature.




2008-Feb-25 UPDATE   Wayne Stambaugh <stambaughw{at}verizon{dot}net>
================================================================================
+eeschema
+5 −7
Original line number Diff line number Diff line
@@ -34,9 +34,6 @@ void ReAnnotatePowerSymbolsOnly( void )
    /* Build the screen list (screen, not sheet) */
    EDA_SheetList SheetList( NULL );

    /* Update the screen number, sheet count and date */

    //ScreenList.UpdateScreenNumberAndDate();

    DrawSheetList* sheet;
    int            CmpNumber = 1;
@@ -161,7 +158,7 @@ void DeleteAnnotation( WinEDA_SchematicFrame* parent, bool annotateSchematic )

    sheet->DeleteAnnotation( annotateSchematic );

    g_RootSheet->m_s->SetModify();
    g_RootSheet->m_AssociatedScreen->SetModify();
    parent->DrawPanel->Refresh( true );
}

@@ -192,10 +189,11 @@ void AnnotateComponents( WinEDA_SchematicFrame* parent,
    /* Build the sheet list */
    EDA_SheetList SheetList( g_RootSheet );

    /* Update the sheet number */
    ii = 0;
    /* Update the screen number, sheet count and date */
    SheetList.UpdateSheetNumberAndDate();

    /* First pass: Component counting */
    ii = 0;
    sheet = parent->GetSheet();
    if( annotateSchematic )
    {
@@ -595,7 +593,7 @@ int CheckAnnotate( WinEDA_SchematicFrame* frame, bool oneSheetOnly )
    /* build the screen list */
    EDA_SheetList  SheetList( NULL );

    g_RootSheet->m_s->SetModify();
    g_RootSheet->m_AssociatedScreen->SetModify();
    ii = 0;

    /* first pass : count composents */
+2 −2
Original line number Diff line number Diff line
@@ -258,7 +258,7 @@ void WinEDA_AnnotateFrame::OnClear( wxCommandEvent& event )

    message += _( "\n\nThis operation will clear the existing annotation " \
                  "and cannot be undone." );
    response = wxMessageBox( message, _( "" ),
    response = wxMessageBox( message, wxT( "" ),
                             wxICON_EXCLAMATION | wxOK | wxCANCEL );
    if (response == wxCANCEL)
        return;
@@ -283,7 +283,7 @@ void WinEDA_AnnotateFrame::OnApply( wxCommandEvent& event )

    message += _( "\n\nThis operation will change the current annotation and " \
                  "cannot be undone." );
    response = wxMessageBox( message, _( "" ),
    response = wxMessageBox( message, wxT( "" ),
                             wxICON_EXCLAMATION | wxOK | wxCANCEL );
    if (response == wxCANCEL)
        return;
+4 −4
Original line number Diff line number Diff line
@@ -832,12 +832,12 @@ static EDA_BaseStruct* CopyStruct( WinEDA_DrawPanel* panel, wxDC* DC, BASE_SCREE
            case DRAW_SHEET_STRUCT_TYPE:
            {
				//DuplicateStruct calls GenCopy, which should handle 
				//m_s and m_sRefCount properly. 
				//m_AssociatedScreen and m_sRefCount properly. 
                DrawSheetStruct* sheet = (DrawSheetStruct*) Struct;
                sheet->m_TimeStamp = GetTimeStamp();
				//sheet->m_s->m_UndoList  = NULL;
				//sheet->m_s->m_RedoList  = NULL;
				//keep m_s pointer & associated.
				//sheet->m_AssociatedScreen->m_UndoList  = NULL;
				//sheet->m_AssociatedScreen->m_RedoList  = NULL;
				//keep m_AssociatedScreen pointer & associated.
                //sheet->m_Son = NULL; m_son is involved in undo and redo.
                break;
            }
+395 −277
Original line number Diff line number Diff line
@@ -43,9 +43,12 @@ DrawSheetStruct::DrawSheetStruct( const wxPoint& pos ) :
    m_Layer   = LAYER_SHEET;
    m_Pos = pos;
    m_SheetNameSize = m_FileNameSize = 60;
	m_s = NULL; 
    m_AssociatedScreen = NULL;
    m_SheetName = wxT( "Root" );
    m_FileName  = wxT( " " );
	m_SheetNumber = 1;
    m_NumberOfSheets = 1;

}


@@ -54,7 +57,9 @@ DrawSheetStruct::~DrawSheetStruct()
/**************************************/
{
    DrawSheetLabelStruct* label = m_Label, * next_label;
    while( label ){

    while( label )
    {
        next_label = (DrawSheetLabelStruct*) label->Pnext;
        delete label;
        label = next_label;
@@ -62,13 +67,15 @@ DrawSheetStruct::~DrawSheetStruct()

    //also, look at the associated sheet & its reference count
    //perhaps it should be deleted also.
	if(m_s){
		m_s->m_RefCount--; 
		if(m_s->m_RefCount == 0)
			delete m_s;
    if( m_AssociatedScreen )
    {
        m_AssociatedScreen->m_RefCount--;
        if( m_AssociatedScreen->m_RefCount == 0 )
            delete m_AssociatedScreen;
    }
}


/***********************************************/
DrawSheetStruct* DrawSheetStruct::GenCopy()
/***********************************************/
@@ -109,9 +116,9 @@ DrawSheetStruct* DrawSheetStruct::GenCopy()
    }

    /* don't copy screen data - just reference it. */
	newitem->m_s = m_s; 
	if(m_s)
		m_s->m_RefCount++; 
    newitem->m_AssociatedScreen = m_AssociatedScreen;
    if( m_AssociatedScreen )
        m_AssociatedScreen->m_RefCount++;

    return newitem;
}
@@ -120,6 +127,7 @@ DrawSheetStruct* DrawSheetStruct::GenCopy()
/**********************************************************/
void DrawSheetStruct::SwapData( DrawSheetStruct* copyitem )
/**********************************************************/

/* Used if undo / redo command:
 *  swap data between this and copyitem
 */
@@ -132,6 +140,8 @@ void DrawSheetStruct::SwapData( DrawSheetStruct* copyitem )
    EXCHG( m_Label, copyitem->m_Label );
    EXCHG( m_NbLabel, copyitem->m_NbLabel );
}


/****************************************************************/
void DrawSheetStruct::Place( WinEDA_DrawFrame* frame, wxDC* DC )
/****************************************************************/
@@ -152,9 +162,12 @@ void DrawSheetStruct::Place( WinEDA_DrawFrame* frame, wxDC* DC )

    EDA_BaseStruct::Place( frame, DC ); //puts it on the EEDrawList.
}


/********************************************************************/
void DrawSheetStruct::CleanupSheet( WinEDA_SchematicFrame* frame, wxDC* DC )
/********************************************************************/

/* Delete pinsheets which are not corresponding to a hierarchal label
 *  if DC != NULL, redraw Sheet
 */
@@ -169,7 +182,7 @@ void DrawSheetStruct::CleanupSheet( WinEDA_SchematicFrame* frame, wxDC* DC )
    {
        /* Search Hlabel corresponding to this Pinsheet */

		EDA_BaseStruct*        DrawStruct = m_s->EEDrawList;
        EDA_BaseStruct*      DrawStruct = m_AssociatedScreen->EEDrawList;
        DrawHierLabelStruct* HLabel = NULL;
        for( ; DrawStruct != NULL; DrawStruct = DrawStruct->Pnext )
        {
@@ -191,6 +204,7 @@ void DrawSheetStruct::CleanupSheet( WinEDA_SchematicFrame* frame, wxDC* DC )
    }
}


/**************************************************************************************/
void DrawSheetStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
                            int DrawMode, int Color )
@@ -247,43 +261,57 @@ void DrawSheetStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& of
    }
}


/**************************************************************************************/
void DrawSheetStruct::DeleteAnnotation( bool recurse )
/**************************************************************************************/
{
	if(recurse && m_s){
		EDA_BaseStruct* strct = m_s->EEDrawList;
		for(; strct; strct = strct->Pnext){
			if(strct->Type() == DRAW_SHEET_STRUCT_TYPE){
    if( recurse && m_AssociatedScreen )
    {
        EDA_BaseStruct* strct = m_AssociatedScreen->EEDrawList;
        for( ; strct; strct = strct->Pnext )
        {
            if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
            {
                DrawSheetStruct* sheet = (DrawSheetStruct*) strct;
                sheet->DeleteAnnotation( recurse );
            }
        }
    }
	EDA_BaseStruct* comp = m_s->EEDrawList;
	for( ; comp ; comp = comp->Pnext ){
		if(comp->Type() == DRAW_LIB_ITEM_STRUCT_TYPE ){
    EDA_BaseStruct* comp = m_AssociatedScreen->EEDrawList;
    for( ; comp; comp = comp->Pnext )
    {
        if( comp->Type() == DRAW_LIB_ITEM_STRUCT_TYPE )
        {
            ( (EDA_SchComponentStruct*) comp )->ClearAnnotation();
        }
    }
}


/*******************************************************************/
int DrawSheetStruct::ComponentCount()
/*******************************************************************/
{
    //count our own components, without the power components.

    /* Routine retournant le nombre de composants dans le schema,
     *  powers non comprises */
    int n = 0;
	if(m_s){

    if( m_AssociatedScreen )
    {
        EDA_BaseStruct* bs;
		for( bs = m_s->EEDrawList; bs != NULL; bs = bs->Pnext ){
			if( bs->Type() == DRAW_LIB_ITEM_STRUCT_TYPE ){
        for( bs = m_AssociatedScreen->EEDrawList; bs != NULL; bs = bs->Pnext )
        {
            if( bs->Type() == DRAW_LIB_ITEM_STRUCT_TYPE )
            {
                DrawPartStruct* Cmp = (DrawPartStruct*) bs;
                if( Cmp->m_Field[VALUE].m_Text.GetChar( 0 ) != '#' )
                    n++;
            }
			if(bs->Type() == DRAW_SHEET_STRUCT_TYPE){
            if( bs->Type() == DRAW_SHEET_STRUCT_TYPE )
            {
                DrawSheetStruct* sheet = (DrawSheetStruct*) bs;
                n += sheet->ComponentCount();
            }
@@ -291,18 +319,24 @@ int DrawSheetStruct::ComponentCount( )
    }
    return n;
}


/*******************************************************************************/
bool DrawSheetStruct::SearchHierarchy( wxString filename, SCH_SCREEN** screen )
/*******************************************************************************/
{
    //search the existing hierarchy for an instance of screen "FileName".
	if(m_s){
		EDA_BaseStruct* strct = m_s->EEDrawList;
		while(strct){
			if(strct->Type() == DRAW_SHEET_STRUCT_TYPE){
    if( m_AssociatedScreen )
    {
        EDA_BaseStruct* strct = m_AssociatedScreen->EEDrawList;
        while( strct )
        {
            if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
            {
                DrawSheetStruct* ss = (DrawSheetStruct*) strct;
				if(ss->m_s && ss->m_s->m_FileName.CmpNoCase(filename) == 0){
					*screen = ss->m_s; 
                if( ss->m_AssociatedScreen && ss->m_AssociatedScreen->m_FileName.CmpNoCase( filename ) == 0 )
                {
                    *screen = ss->m_AssociatedScreen;
                    return true;
                }
                if( ss->SearchHierarchy( filename, screen ) )
@@ -313,6 +347,8 @@ bool DrawSheetStruct::SearchHierarchy(wxString filename, SCH_SCREEN **screen)
    }
    return false;
}


/*******************************************************************************/
bool DrawSheetStruct::LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetList* list )
/*******************************************************************************/
@@ -322,43 +358,55 @@ bool DrawSheetStruct::LocatePathOfScreen(SCH_SCREEN *screen, DrawSheetList* list
    //no other references to its m_s otherwise there would be loops
    //in the heirarchy.
    //search the existing hierarchy for an instance of screen "FileName".
	if(m_s){
    if( m_AssociatedScreen )
    {
        list->Push( this );
		if(m_s == screen)
        if( m_AssociatedScreen == screen )
            return true;
		EDA_BaseStruct* strct = m_s->EEDrawList;
		while(strct){
			if(strct->Type() == DRAW_SHEET_STRUCT_TYPE){
        EDA_BaseStruct* strct = m_AssociatedScreen->EEDrawList;
        while( strct )
        {
            if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
            {
                DrawSheetStruct* ss = (DrawSheetStruct*) strct;
                if( ss->LocatePathOfScreen( screen, list ) )
                    return true;
            }
            strct = strct->Pnext;
        }

        list->Pop();
    }
    return false;
}


/*******************************************************************************/
bool DrawSheetStruct::Load( WinEDA_SchematicFrame* frame )
/*******************************************************************************/
{
	if(!m_s){
    if( !m_AssociatedScreen )
    {
        SCH_SCREEN* screen = NULL;
        g_RootSheet->SearchHierarchy( m_FileName, &screen );
		if(screen){
			m_s = screen; 
			m_s->m_RefCount++;
        if( screen )
        {
            m_AssociatedScreen = screen;
            m_AssociatedScreen->m_RefCount++;

            //do not need to load the sub-sheets - this has already been done.
		}else{
			m_s = new SCH_SCREEN(SCHEMATIC_FRAME); 
			m_s->m_RefCount++; 
			if(!frame->LoadOneEEFile(m_s, m_FileName))
        }
        else
        {
            m_AssociatedScreen = new SCH_SCREEN( SCHEMATIC_FRAME );
            m_AssociatedScreen->m_RefCount++;
            if( !frame->LoadOneEEFile( m_AssociatedScreen, m_FileName ) )
                return false;
			EDA_BaseStruct* bs = m_s->EEDrawList; 
			while(bs){
				if(bs->Type() ==  DRAW_SHEET_STRUCT_TYPE){
            EDA_BaseStruct* bs = m_AssociatedScreen->EEDrawList;
            while( bs )
            {
                if( bs->Type() ==  DRAW_SHEET_STRUCT_TYPE )
                {
                    DrawSheetStruct* ss = (DrawSheetStruct*) bs;
                    if( !ss->Load( frame ) )
                        return false;
@@ -369,15 +417,21 @@ bool DrawSheetStruct::Load(WinEDA_SchematicFrame* frame)
    }
    return true;
}


/*******************************************************************************/
int DrawSheetStruct::CountSheets()
/*******************************************************************************/
{
    int count = 1; //1 = this!!
	if(m_s){
		EDA_BaseStruct* strct = m_s->EEDrawList;
		for(; strct; strct = strct->Pnext){
			if(strct->Type() == DRAW_SHEET_STRUCT_TYPE){

    if( m_AssociatedScreen )
    {
        EDA_BaseStruct* strct = m_AssociatedScreen->EEDrawList;
        for( ; strct; strct = strct->Pnext )
        {
            if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
            {
                DrawSheetStruct* ss = (DrawSheetStruct*) strct;
                count += ss->CountSheets();
            }
@@ -394,8 +448,8 @@ int DrawSheetStruct::CountSheets()
/*******************************************************************/
DrawSheetLabelStruct::DrawSheetLabelStruct( DrawSheetStruct* parent,
                                            const wxPoint& pos, const wxString& text ) :
    EDA_BaseStruct( DRAW_SHEETLABEL_STRUCT_TYPE ),
    EDA_TextStruct( text )
    EDA_BaseStruct( DRAW_SHEETLABEL_STRUCT_TYPE )
    , EDA_TextStruct( text )
/*******************************************************************/
{
    m_Layer      = LAYER_SHEETLABEL;
@@ -511,115 +565,179 @@ void DrawSheetLabelStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoin
    GRPoly( &panel->m_ClipBox, DC, NbSegm, coord, FillShape, LineWidth, txtcolor, txtcolor ); /* Poly Non rempli */
}


/**********************************************/
/* class to handle a series of sheets *********/
/* a 'path' so to speak.. *********************/
/**********************************************/
DrawSheetList::DrawSheetList(){
DrawSheetList::DrawSheetList()
{
    for( int i = 0; i<DSLSZ; i++ )
        m_sheets[i] = NULL;

    m_numSheets = 0;
}
int DrawSheetList::Cmp(DrawSheetList& d){


int DrawSheetList::Cmp( DrawSheetList& d )
{
    if( m_numSheets > d.m_numSheets )
        return 1;
    if( m_numSheets < d.m_numSheets )
        return -1;

    //otherwise, same number of sheets.
	for(int i=0; i<m_numSheets; i++){
    for( int i = 0; i<m_numSheets; i++ )
    {
        if( m_sheets[i]->m_TimeStamp > d.m_sheets[i]->m_TimeStamp )
            return 1;
        if( m_sheets[i]->m_TimeStamp < d.m_sheets[i]->m_TimeStamp )
            return -1;
    }

    return 0;
}
DrawSheetStruct* DrawSheetList::Last(){


DrawSheetStruct* DrawSheetList::Last()
{
    if( m_numSheets )
        return m_sheets[m_numSheets - 1];
    return NULL;
}
SCH_SCREEN* DrawSheetList::LastScreen(){


SCH_SCREEN* DrawSheetList::LastScreen()
{
    if( m_numSheets )
		return m_sheets[m_numSheets-1]->m_s; 
        return m_sheets[m_numSheets - 1]->m_AssociatedScreen;
    return NULL;
}
EDA_BaseStruct* DrawSheetList::LastDrawList(){
	if(m_numSheets && m_sheets[m_numSheets-1]->m_s)
		return m_sheets[m_numSheets-1]->m_s->EEDrawList; 


EDA_BaseStruct* DrawSheetList::LastDrawList()
{
    if( m_numSheets && m_sheets[m_numSheets - 1]->m_AssociatedScreen )
        return m_sheets[m_numSheets - 1]->m_AssociatedScreen->EEDrawList;
    return NULL;
}
void DrawSheetList::Push(DrawSheetStruct* sheet){
	if(m_numSheets < DSLSZ){


void DrawSheetList::Push( DrawSheetStruct* sheet )
{
    if( m_numSheets < DSLSZ )
    {
        m_sheets[m_numSheets] = sheet;
        m_numSheets++;
    }
}
DrawSheetStruct* DrawSheetList::Pop(){
	if(m_numSheets > 0){


DrawSheetStruct* DrawSheetList::Pop()
{
    if( m_numSheets > 0 )
    {
        m_numSheets--;
        return m_sheets[m_numSheets];
    }
    return NULL;
}
wxString DrawSheetList::Path(){


wxString DrawSheetList::Path()
{
    wxString s, t;

    s = wxT( "/" );

    //start at 1 to avoid the root sheet,
    //which does not need to be added to the path
    //it's timestamp changes anyway.
	for(int i=1; i< m_numSheets; i++){
    for( int i = 1; i< m_numSheets; i++ )
    {
        t.Printf( _( "%8.8lX/" ), m_sheets[i]->m_TimeStamp );
        s = s + t;
    }

    return s;
}
wxString DrawSheetList::PathHumanReadable(){


wxString DrawSheetList::PathHumanReadable()
{
    wxString s, t;

    s = wxT( "/" );

    //start at 1 to avoid the root sheet, as above.
	for(int i=1; i< m_numSheets; i++){
    for( int i = 1; i< m_numSheets; i++ )
    {
        s = s + m_sheets[i]->m_SheetName + wxT( "/" );
    }

    return s;
}
void DrawSheetList::UpdateAllScreenReferences(){


void DrawSheetList::UpdateAllScreenReferences()
{
    EDA_BaseStruct* t = LastDrawList();
	while(t){
		if(t->Type() == DRAW_LIB_ITEM_STRUCT_TYPE){

    while( t )
    {
        if( t->Type() == DRAW_LIB_ITEM_STRUCT_TYPE )
        {
            EDA_SchComponentStruct* d = (EDA_SchComponentStruct*) t;
            d->m_Field[REFERENCE].m_Text = d->GetRef( this );
        }
        t = t->Pnext;
    }

    printf( "on sheet: %s \n", CONV_TO_UTF8( PathHumanReadable() ) );
}
bool DrawSheetList::operator= (const DrawSheetList& d1){


bool DrawSheetList::operator=( const DrawSheetList& d1 )
{
    m_numSheets = d1.m_numSheets;
    int i;
	for(i=0; i<m_numSheets; i++){
    for( i = 0; i<m_numSheets; i++ )
    {
        m_sheets[i] = d1.m_sheets[i];
    }
	for(; i<DSLSZ; i++){

    for( ; i<DSLSZ; i++ )
    {
        m_sheets[i] = 0;
    }

    return true;
}
bool DrawSheetList::operator==(const DrawSheetList &d1){


bool DrawSheetList::operator==( const DrawSheetList& d1 )
{
    if( m_numSheets != d1.m_numSheets )
        return false;
	for(int i=0; i<m_numSheets; i++){
    for( int i = 0; i<m_numSheets; i++ )
    {
        if( m_sheets[i] != d1.m_sheets[i] )
            return false;
    }

    return true;
}
bool DrawSheetList::operator!=(const DrawSheetList &d1){


bool DrawSheetList::operator!=( const DrawSheetList& d1 )
{
    if( m_numSheets != d1.m_numSheets )
        return true;
	for(int i=0; i<m_numSheets; i++){
    for( int i = 0; i<m_numSheets; i++ )
    {
        if( m_sheets[i] != d1.m_sheets[i] )
            return true;
    }

    return false;
}
Loading