Commit a664e14b authored by CHARRAS's avatar CHARRAS

Renaming the sheet filename now works in simple and complex hierarchies

parent 8ef96230
...@@ -5,6 +5,13 @@ Started 2007-June-11 ...@@ -5,6 +5,13 @@ 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-Feb-29 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+eeschema
Renaming the sheet filename now works in simple and complex hierarchies.
Use carefully because this can change the whole schematic structure.
2008-Feb-28 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr> 2008-Feb-28 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================ ================================================================================
+eeschema +eeschema
......
...@@ -43,14 +43,13 @@ DrawSheetStruct::DrawSheetStruct( const wxPoint& pos ) : ...@@ -43,14 +43,13 @@ DrawSheetStruct::DrawSheetStruct( const wxPoint& pos ) :
m_NbLabel = 0; m_NbLabel = 0;
m_Layer = LAYER_SHEET; m_Layer = LAYER_SHEET;
m_Pos = pos; m_Pos = pos;
m_TimeStamp = GetTimeStamp(); m_TimeStamp = GetTimeStamp();
m_SheetNameSize = m_FileNameSize = 60; m_SheetNameSize = m_FileNameSize = 60;
m_AssociatedScreen = NULL; m_AssociatedScreen = NULL;
m_SheetName.Printf( wxT("Sheet%8.8lX"), m_TimeStamp); m_SheetName.Printf( wxT( "Sheet%8.8lX" ), m_TimeStamp );
m_FileName.Printf( wxT("file%8.8lX.sch"), m_TimeStamp); m_FileName.Printf( wxT( "file%8.8lX.sch" ), m_TimeStamp );
m_SheetNumber = 1; m_SheetNumber = 1;
m_NumberOfSheets = 1; m_NumberOfSheets = 1;
} }
...@@ -336,7 +335,8 @@ bool DrawSheetStruct::SearchHierarchy( wxString filename, SCH_SCREEN** screen ) ...@@ -336,7 +335,8 @@ bool DrawSheetStruct::SearchHierarchy( wxString filename, SCH_SCREEN** screen )
if( strct->Type() == DRAW_SHEET_STRUCT_TYPE ) if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
{ {
DrawSheetStruct* ss = (DrawSheetStruct*) strct; DrawSheetStruct* ss = (DrawSheetStruct*) strct;
if( ss->m_AssociatedScreen && ss->m_AssociatedScreen->m_FileName.CmpNoCase( filename ) == 0 ) if( ss->m_AssociatedScreen &&
ss->m_AssociatedScreen->m_FileName.CmpNoCase( filename ) == 0 )
{ {
*screen = ss->m_AssociatedScreen; *screen = ss->m_AssociatedScreen;
return true; return true;
...@@ -387,7 +387,7 @@ bool DrawSheetStruct::LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetPath* lis ...@@ -387,7 +387,7 @@ bool DrawSheetStruct::LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetPath* lis
bool DrawSheetStruct::Load( WinEDA_SchematicFrame* frame ) bool DrawSheetStruct::Load( WinEDA_SchematicFrame* frame )
/*******************************************************************************/ /*******************************************************************************/
{ {
bool success = true; bool success = true;
if( !m_AssociatedScreen ) if( !m_AssociatedScreen )
{ {
...@@ -404,21 +404,21 @@ bool DrawSheetStruct::Load( WinEDA_SchematicFrame* frame ) ...@@ -404,21 +404,21 @@ bool DrawSheetStruct::Load( WinEDA_SchematicFrame* frame )
{ {
m_AssociatedScreen = new SCH_SCREEN( SCHEMATIC_FRAME ); m_AssociatedScreen = new SCH_SCREEN( SCHEMATIC_FRAME );
m_AssociatedScreen->m_RefCount++; m_AssociatedScreen->m_RefCount++;
success = frame->LoadOneEEFile( m_AssociatedScreen, m_FileName); success = frame->LoadOneEEFile( m_AssociatedScreen, m_FileName );
if ( success ) if( success )
{ {
EDA_BaseStruct* bs = m_AssociatedScreen->EEDrawList; EDA_BaseStruct* bs = m_AssociatedScreen->EEDrawList;
while( bs ) while( bs )
{ {
if( bs->Type() == DRAW_SHEET_STRUCT_TYPE ) if( bs->Type() == DRAW_SHEET_STRUCT_TYPE )
{ {
DrawSheetStruct* sheetstruct = (DrawSheetStruct*) bs; DrawSheetStruct* sheetstruct = (DrawSheetStruct*) bs;
if( !sheetstruct->Load( frame ) ) if( !sheetstruct->Load( frame ) )
success = false; success = false;
} }
bs = bs->Pnext; bs = bs->Pnext;
} }
} }
} }
} }
return success; return success;
...@@ -448,20 +448,116 @@ int DrawSheetStruct::CountSheets() ...@@ -448,20 +448,116 @@ int DrawSheetStruct::CountSheets()
/******************************************/ /******************************************/
wxString DrawSheetStruct::GetFileName(void) wxString DrawSheetStruct::GetFileName( void )
/******************************************/ /******************************************/
{ {
return m_FileName; return m_FileName;
} }
/************************************************************/ /************************************************************/
void DrawSheetStruct::SetFileName(const wxString & aFilename) void DrawSheetStruct::SetFileName( const wxString& aFilename )
/************************************************************/ /************************************************************/
{ {
m_FileName = aFilename; m_FileName = aFilename;
}
/** Function ChangeFileName
* Set a new filename and manage data and associated screen
* The main difficulty is the filename change in a complex hierarchy.
* - if new filename is not already used: change to the new name (and if an existing file is found, load it on request)
* - if new filename is already used (a complex hierarchy) : add the sheet to the complex hierarchy.
*/
bool DrawSheetStruct::ChangeFileName( WinEDA_SchematicFrame * aFrame, const wxString& aFileName )
{
if( (GetFileName() == aFileName) && m_AssociatedScreen )
return true;
SCH_SCREEN* Screen_to_use = NULL;
wxString msg;
bool LoadFromFile = false;
if( g_RootSheet->SearchHierarchy( aFileName, &Screen_to_use ) ) //do we reload the data from the existing hierarchy
{
msg.Printf( _(
"A Sub Hierarchy named %s exists, Use it (The data in this sheet will be replaced)?" ),
aFileName.GetData() );
if( ! IsOK( NULL, msg ) )
{
DisplayInfo(NULL, _("Sheet Filename Renaming Aborted"));
return false;
}
}
else if( wxFileExists( aFileName ) ) //do we reload the data from an existing file
{
msg.Printf( _(
"A file named %s exists, load it (otherwise keep current sheet data if possible)?" ),
aFileName.GetData() );
if( IsOK( NULL, msg ) )
{
LoadFromFile = true;
m_AssociatedScreen->m_RefCount--; //be careful with these
if( m_AssociatedScreen->m_RefCount == 0 )
SAFE_DELETE( m_AssociatedScreen );
m_AssociatedScreen = NULL; //will be created later
}
}
// if an associated screen exists, shared between this sheet and others sheets, what we do ?
if( m_AssociatedScreen && ( m_AssociatedScreen->m_RefCount > 1 ))
{
msg = _("This sheet uses shared data in a complex hierarchy" ) ;
msg << wxT("\n");
msg << _("Do we convert it in a simple hierarchical sheet (otherwise delete current sheet data)");
if( IsOK( NULL, msg ) )
{
LoadFromFile = true;
wxString oldfilename = m_AssociatedScreen->m_FileName;
m_AssociatedScreen->m_FileName = aFileName;
aFrame->SaveEEFile( m_AssociatedScreen, FILE_SAVE_AS );
m_AssociatedScreen->m_FileName = oldfilename;
}
m_AssociatedScreen->m_RefCount--; //be careful with these
m_AssociatedScreen = NULL; //will be created later
}
SetFileName( aFileName );
// if we use new data (from file or from internal hierarchy), delete the current sheet data
if( m_AssociatedScreen && (LoadFromFile || Screen_to_use) )
{
m_AssociatedScreen->m_RefCount--;
if( m_AssociatedScreen->m_RefCount == 0 )
SAFE_DELETE( m_AssociatedScreen );
m_AssociatedScreen = NULL; //so that we reload..
}
if ( LoadFromFile )
Load( aFrame );
else if ( Screen_to_use )
{
m_AssociatedScreen = Screen_to_use;
m_AssociatedScreen->m_RefCount++;
}
//just make a new screen if needed.
if( !m_AssociatedScreen )
{
m_AssociatedScreen = new SCH_SCREEN( SCHEMATIC_FRAME );
m_AssociatedScreen->m_RefCount++; //be careful with these
}
m_AssociatedScreen->m_FileName = aFileName;
return true;
} }
/************************/ /************************/
/* DrawSheetLabelStruct */ /* DrawSheetLabelStruct */
/************************/ /************************/
...@@ -646,7 +742,7 @@ EDA_BaseStruct* DrawSheetPath::LastDrawList() ...@@ -646,7 +742,7 @@ EDA_BaseStruct* DrawSheetPath::LastDrawList()
void DrawSheetPath::Push( DrawSheetStruct* sheet ) void DrawSheetPath::Push( DrawSheetStruct* sheet )
{ {
wxASSERT( m_numSheets <= DSLSZ ); wxASSERT( m_numSheets <= DSLSZ );
if( m_numSheets < DSLSZ ) if( m_numSheets < DSLSZ )
{ {
m_sheets[m_numSheets] = sheet; m_sheets[m_numSheets] = sheet;
......
...@@ -138,7 +138,8 @@ public: ...@@ -138,7 +138,8 @@ public:
bool LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetPath* list ); bool LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetPath* list );
int CountSheets(); int CountSheets();
wxString GetFileName(void); wxString GetFileName(void);
void SetFileName(const wxString & aFilename); void SetFileName(const wxString & aFilename); // Set a new filename without changing anything else
bool ChangeFileName(WinEDA_SchematicFrame * aFrame, const wxString & aFileName); // Set a new filename and manage data and associated screen
//void RemoveSheet(DrawSheetStruct* sheet); //void RemoveSheet(DrawSheetStruct* sheet);
//to remove a sheet, just delete it //to remove a sheet, just delete it
......
...@@ -257,21 +257,19 @@ SCH_SCREEN * WinEDA_SchematicFrame::CreateNewScreen( ...@@ -257,21 +257,19 @@ SCH_SCREEN * WinEDA_SchematicFrame::CreateNewScreen(
void WinEDA_SchematicFrame::SaveProject( ) void WinEDA_SchematicFrame::SaveProject( )
/****************************************************/ /****************************************************/
/* Sauvegarde toutes les feuilles du projet /* Saves the entire project and creates an archive for components
* et cr�e une librairie archive des composants, de nom <root_name>.chche.lib * the library archive name is <root_name>.cache.lib
*/ */
{ {
SCH_SCREEN* screen_tmp, *screen; SCH_SCREEN* screen;
wxString LibArchiveFileName; wxString LibArchiveFileName;
screen_tmp = (SCH_SCREEN*)GetScreen(); //save...
EDA_ScreenList ScreenList; EDA_ScreenList ScreenList;
for( screen = ScreenList.GetFirst(); screen != NULL; for( screen = ScreenList.GetFirst(); screen != NULL;
screen = ScreenList.GetNext() ) screen = ScreenList.GetNext() )
{ {
printf("SaveEEFile, %s\n", (const char*)screen->m_FileName.mb_str() ); printf("SaveEEFile, %s\n", CONV_TO_UTF8(screen->m_FileName) );
SaveEEFile( screen, FILE_SAVE_AS ); SaveEEFile( screen, FILE_SAVE_AS );
} }
......
This diff is collapsed.
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