2009-01-04 18:52:57 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: class_drawsheet.cpp
|
|
|
|
// Purpose: member functions for DrawSheetStruct
|
|
|
|
// header = class_drawsheet.h
|
|
|
|
// Author: jean-pierre Charras
|
|
|
|
// Modified by:
|
|
|
|
// Licence: License GNU
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************/
|
2009-01-07 20:09:03 +00:00
|
|
|
/* class to handle a serie of sheets *********/
|
2009-01-04 18:52:57 +00:00
|
|
|
/* a 'path' so to speak.. *********************/
|
|
|
|
/**********************************************/
|
|
|
|
DrawSheetPath::DrawSheetPath()
|
|
|
|
{
|
|
|
|
for( int i = 0; i<DSLSZ; i++ )
|
|
|
|
m_sheets[i] = NULL;
|
|
|
|
|
|
|
|
m_numSheets = 0;
|
|
|
|
}
|
|
|
|
|
2009-01-07 20:09:03 +00:00
|
|
|
/*********************************************************************************************/
|
|
|
|
bool DrawSheetPath::BuildSheetPathInfoFromSheetPathValue(const wxString & aPath, bool aFound )
|
|
|
|
/*********************************************************************************************/
|
|
|
|
/** Function BuildSheetPathInfoFromSheetPathValue
|
|
|
|
* Fill this with data to acces to the hierarchical sheet known by its path aPath
|
|
|
|
* @param aPath = path of the sheet to reach (in non human readable format)
|
|
|
|
* @return true if success else false
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
if ( aFound )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ( GetSheetsCount() == 0 )
|
|
|
|
Push( g_RootSheet );
|
|
|
|
|
|
|
|
if ( aPath == Path() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
SCH_ITEM* schitem = LastDrawList();
|
|
|
|
while( schitem && GetSheetsCount() < NB_MAX_SHEET )
|
|
|
|
{
|
|
|
|
if( schitem->Type() == DRAW_SHEET_STRUCT_TYPE )
|
|
|
|
{
|
|
|
|
DrawSheetStruct* sheet = (DrawSheetStruct*) schitem;
|
|
|
|
Push( sheet );
|
|
|
|
if ( aPath == Path() )
|
|
|
|
return true;
|
|
|
|
if ( BuildSheetPathInfoFromSheetPathValue( aPath ) )
|
|
|
|
return true;
|
|
|
|
Pop();
|
|
|
|
}
|
|
|
|
schitem = schitem->Next();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-01-04 18:52:57 +00:00
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
/*******************************************************************/
|
|
|
|
int DrawSheetPath::Cmp( const DrawSheetPath& aSheetPathToTest ) const
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
/** Function Cmp
|
|
|
|
* Compare if this is the same sheet path as aSheetPathToTest
|
|
|
|
* @param aSheetPathToTest = sheet path to compare
|
|
|
|
* @return -1 if differents, 0 if same
|
|
|
|
*/
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
if( m_numSheets > aSheetPathToTest.m_numSheets )
|
2009-01-04 18:52:57 +00:00
|
|
|
return 1;
|
2009-01-06 20:09:32 +00:00
|
|
|
if( m_numSheets < aSheetPathToTest.m_numSheets )
|
2009-01-04 18:52:57 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
//otherwise, same number of sheets.
|
2009-01-07 20:09:03 +00:00
|
|
|
for( unsigned i = 0; i<m_numSheets; i++ )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
if( m_sheets[i]->m_TimeStamp > aSheetPathToTest.m_sheets[i]->m_TimeStamp )
|
2009-01-04 18:52:57 +00:00
|
|
|
return 1;
|
2009-01-06 20:09:32 +00:00
|
|
|
if( m_sheets[i]->m_TimeStamp < aSheetPathToTest.m_sheets[i]->m_TimeStamp )
|
2009-01-04 18:52:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-07 17:33:18 +00:00
|
|
|
/** Function Last
|
|
|
|
* returns a pointer to the last sheet of the list
|
|
|
|
* One can see the others sheet as the "path" to reach this last sheet
|
|
|
|
*/
|
2009-01-04 18:52:57 +00:00
|
|
|
DrawSheetStruct* DrawSheetPath::Last()
|
|
|
|
{
|
|
|
|
if( m_numSheets )
|
|
|
|
return m_sheets[m_numSheets - 1];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-07 17:33:18 +00:00
|
|
|
/** Function LastScreen
|
|
|
|
* @return the SCH_SCREEN relative to the last sheet in list
|
|
|
|
*/
|
2009-01-04 18:52:57 +00:00
|
|
|
SCH_SCREEN* DrawSheetPath::LastScreen()
|
|
|
|
{
|
|
|
|
if( m_numSheets )
|
|
|
|
return m_sheets[m_numSheets - 1]->m_AssociatedScreen;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-07 17:33:18 +00:00
|
|
|
/** Function LastScreen
|
|
|
|
* @return a pointer to the first schematic item handled by the
|
|
|
|
* SCH_SCREEN relative to the last sheet in list
|
|
|
|
*/
|
|
|
|
SCH_ITEM* DrawSheetPath::LastDrawList()
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
if( m_numSheets && m_sheets[m_numSheets - 1]->m_AssociatedScreen )
|
|
|
|
return m_sheets[m_numSheets - 1]->m_AssociatedScreen->EEDrawList;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
/**************************************************/
|
|
|
|
void DrawSheetPath::Push( DrawSheetStruct* aSheet )
|
|
|
|
/**************************************************/
|
|
|
|
|
|
|
|
/** Function Push
|
|
|
|
* store (push) aSheet in list
|
|
|
|
* @param aSheet = pointer to the DrawSheetStruct to store in list
|
|
|
|
*/
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
if( m_numSheets > DSLSZ )
|
|
|
|
wxMessageBox( wxT( "DrawSheetPath::Push() error: no room in buffer to store sheet" ) );
|
2009-01-04 18:52:57 +00:00
|
|
|
if( m_numSheets < DSLSZ )
|
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
m_sheets[m_numSheets] = aSheet;
|
2009-01-04 18:52:57 +00:00
|
|
|
m_numSheets++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DrawSheetStruct* DrawSheetPath::Pop()
|
2009-01-06 20:09:32 +00:00
|
|
|
|
|
|
|
/** Function Pop
|
|
|
|
* retrieves (pop) the last entered sheet and remove it from list
|
|
|
|
* @return a DrawSheetStruct* pointer to the removed sheet in list
|
|
|
|
*/
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
if( m_numSheets > 0 )
|
|
|
|
{
|
|
|
|
m_numSheets--;
|
|
|
|
return m_sheets[m_numSheets];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString DrawSheetPath::Path()
|
2009-01-06 20:09:32 +00:00
|
|
|
|
|
|
|
/** Function Path
|
|
|
|
* the path uses the time stamps which do not changes even when editing sheet parameters
|
|
|
|
* a path is something like / (root) or /34005677 or /34005677/00AE4523
|
|
|
|
*/
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
wxString s, t;
|
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
s = wxT( "/" ); // This is the root path
|
2009-01-04 18:52:57 +00:00
|
|
|
|
|
|
|
//start at 1 to avoid the root sheet,
|
|
|
|
//which does not need to be added to the path
|
|
|
|
//it's timestamp changes anyway.
|
2009-01-07 20:09:03 +00:00
|
|
|
for( unsigned i = 1; i< m_numSheets; i++ )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
t.Printf( _( "%8.8lX/" ), m_sheets[i]->m_TimeStamp );
|
|
|
|
s = s + t;
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
/******************************************/
|
2009-01-04 18:52:57 +00:00
|
|
|
wxString DrawSheetPath::PathHumanReadable()
|
2009-01-06 20:09:32 +00:00
|
|
|
/******************************************/
|
|
|
|
|
|
|
|
/** Function PathHumanReadable
|
|
|
|
* Return the sheet path in a readable form, i.e.
|
|
|
|
* as a path made from sheet names.
|
|
|
|
* (the "normal" path uses the time stamps which do not changes even when editing sheet parameters)
|
|
|
|
*/
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
wxString s, t;
|
|
|
|
|
|
|
|
s = wxT( "/" );
|
|
|
|
|
|
|
|
//start at 1 to avoid the root sheet, as above.
|
2009-01-07 20:09:03 +00:00
|
|
|
for( unsigned i = 1; i< m_numSheets; i++ )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
s = s + m_sheets[i]->m_SheetName + wxT( "/" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************/
|
|
|
|
void DrawSheetPath::UpdateAllScreenReferences()
|
|
|
|
/***********************************************/
|
|
|
|
{
|
|
|
|
EDA_BaseStruct* t = LastDrawList();
|
|
|
|
|
|
|
|
while( t )
|
|
|
|
{
|
|
|
|
if( t->Type() == TYPE_SCH_COMPONENT )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) t;
|
2009-01-06 20:09:32 +00:00
|
|
|
component->GetField( REFERENCE )->m_Text = component->GetRef( this );
|
2009-01-04 18:52:57 +00:00
|
|
|
component->m_Multi = component->GetUnitSelection( this );
|
|
|
|
}
|
|
|
|
t = t->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DrawSheetPath::operator=( const DrawSheetPath& d1 )
|
|
|
|
{
|
|
|
|
m_numSheets = d1.m_numSheets;
|
2009-01-07 20:09:03 +00:00
|
|
|
unsigned i;
|
2009-01-04 18:52:57 +00:00
|
|
|
for( i = 0; i<m_numSheets; i++ )
|
|
|
|
{
|
|
|
|
m_sheets[i] = d1.m_sheets[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ; i<DSLSZ; i++ )
|
|
|
|
{
|
|
|
|
m_sheets[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DrawSheetPath::operator==( const DrawSheetPath& d1 )
|
|
|
|
{
|
|
|
|
if( m_numSheets != d1.m_numSheets )
|
|
|
|
return false;
|
2009-01-07 20:09:03 +00:00
|
|
|
for( unsigned i = 0; i<m_numSheets; i++ )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
if( m_sheets[i] != d1.m_sheets[i] )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DrawSheetPath::operator!=( const DrawSheetPath& d1 )
|
|
|
|
{
|
|
|
|
if( m_numSheets != d1.m_numSheets )
|
|
|
|
return true;
|
2009-01-07 20:09:03 +00:00
|
|
|
for( unsigned i = 0; i<m_numSheets; i++ )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
if( m_sheets[i] != d1.m_sheets[i] )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
/* Class EDA_SheetList to handle the list of Sheets in a hierarchy */
|
|
|
|
/*********************************************************************/
|
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
|
|
|
|
/*******************************************************/
|
|
|
|
EDA_SheetList::EDA_SheetList( DrawSheetStruct* aSheet )
|
|
|
|
/*******************************************************/
|
|
|
|
|
|
|
|
/* The constructor: build the list of sheets from aSheet.
|
|
|
|
* If aSheet == NULL (default) build the whole list of sheets in hierarchy
|
|
|
|
* So usually call it with no param.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
m_index = 0;
|
|
|
|
m_count = 0;
|
|
|
|
m_List = NULL;
|
|
|
|
if( aSheet == NULL )
|
|
|
|
aSheet = g_RootSheet;
|
|
|
|
BuildSheetList( aSheet );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
/*****************************************/
|
|
|
|
DrawSheetPath* EDA_SheetList::GetFirst()
|
|
|
|
/*****************************************/
|
2009-01-06 20:09:32 +00:00
|
|
|
|
|
|
|
/** Function GetFirst
|
|
|
|
* @return the first item (sheet) in m_List and prepare calls to GetNext()
|
|
|
|
*/
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
m_index = 0;
|
2009-01-06 20:09:32 +00:00
|
|
|
if( GetCount() > 0 )
|
2009-01-04 18:52:57 +00:00
|
|
|
return &( m_List[0] );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************/
|
|
|
|
DrawSheetPath* EDA_SheetList::GetNext()
|
|
|
|
/*****************************************/
|
2009-01-06 20:09:32 +00:00
|
|
|
|
|
|
|
/** Function GetNext
|
|
|
|
* @return the next item (sheet) in m_List or NULL if no more item in sheet list
|
|
|
|
*/
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
if( m_index < GetCount() )
|
2009-01-04 18:52:57 +00:00
|
|
|
m_index++;
|
|
|
|
return GetSheet( m_index );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************/
|
2009-01-06 20:09:32 +00:00
|
|
|
DrawSheetPath* EDA_SheetList::GetSheet( int aIndex )
|
2009-01-04 18:52:57 +00:00
|
|
|
/************************************************/
|
|
|
|
|
2009-01-06 20:09:32 +00:00
|
|
|
/** Function GetSheet
|
|
|
|
* @return the item (sheet) in aIndex position in m_List or NULL if less than index items
|
|
|
|
* @param aIndex = index in sheet list to get the sheet
|
2009-01-04 18:52:57 +00:00
|
|
|
*/
|
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
if( aIndex < GetCount() )
|
|
|
|
return &(m_List[aIndex]);
|
2009-01-04 18:52:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
2009-01-06 20:09:32 +00:00
|
|
|
void EDA_SheetList::BuildSheetList( DrawSheetStruct* aSheet )
|
2009-01-04 18:52:57 +00:00
|
|
|
/************************************************************************/
|
2009-01-06 20:09:32 +00:00
|
|
|
|
|
|
|
/** Function BuildSheetList
|
|
|
|
* Build the list of sheets and their sheet path from the aSheet sheet
|
|
|
|
* if aSheet = g_RootSheet, the full sheet path list (and full sheet list) is built
|
|
|
|
* @param aSheet = the starting sheet to build list
|
|
|
|
*/
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
if( m_List == NULL )
|
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
int count = aSheet->CountSheets();
|
2009-01-04 18:52:57 +00:00
|
|
|
m_count = count;
|
|
|
|
m_index = 0;
|
2009-01-06 20:09:32 +00:00
|
|
|
count *= sizeof(DrawSheetPath);
|
|
|
|
m_List = (DrawSheetPath*) MyZMalloc( count );
|
2009-01-04 18:52:57 +00:00
|
|
|
m_currList.Clear();
|
|
|
|
}
|
2009-01-06 20:09:32 +00:00
|
|
|
m_currList.Push( aSheet );
|
2009-01-04 18:52:57 +00:00
|
|
|
m_List[m_index] = m_currList;
|
|
|
|
m_index++;
|
2009-01-06 20:09:32 +00:00
|
|
|
if( aSheet->m_AssociatedScreen != NULL )
|
2009-01-04 18:52:57 +00:00
|
|
|
{
|
|
|
|
EDA_BaseStruct* strct = m_currList.LastDrawList();
|
|
|
|
while( strct )
|
|
|
|
{
|
|
|
|
if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
|
|
|
|
{
|
2009-01-06 20:09:32 +00:00
|
|
|
DrawSheetStruct* sheet = (DrawSheetStruct*) strct;
|
|
|
|
BuildSheetList( sheet );
|
2009-01-04 18:52:57 +00:00
|
|
|
}
|
|
|
|
strct = strct->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_currList.Pop();
|
|
|
|
}
|