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
Please add newer entries at the top, list the date and your name with
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>
================================================================================
+eeschema
......
......@@ -46,11 +46,10 @@ DrawSheetStruct::DrawSheetStruct( const wxPoint& pos ) :
m_TimeStamp = GetTimeStamp();
m_SheetNameSize = m_FileNameSize = 60;
m_AssociatedScreen = NULL;
m_SheetName.Printf( wxT("Sheet%8.8lX"), m_TimeStamp);
m_FileName.Printf( wxT("file%8.8lX.sch"), m_TimeStamp);
m_SheetName.Printf( wxT( "Sheet%8.8lX" ), m_TimeStamp );
m_FileName.Printf( wxT( "file%8.8lX.sch" ), m_TimeStamp );
m_SheetNumber = 1;
m_NumberOfSheets = 1;
}
......@@ -336,7 +335,8 @@ bool DrawSheetStruct::SearchHierarchy( wxString filename, SCH_SCREEN** screen )
if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
{
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;
return true;
......@@ -404,8 +404,8 @@ bool DrawSheetStruct::Load( WinEDA_SchematicFrame* frame )
{
m_AssociatedScreen = new SCH_SCREEN( SCHEMATIC_FRAME );
m_AssociatedScreen->m_RefCount++;
success = frame->LoadOneEEFile( m_AssociatedScreen, m_FileName);
if ( success )
success = frame->LoadOneEEFile( m_AssociatedScreen, m_FileName );
if( success )
{
EDA_BaseStruct* bs = m_AssociatedScreen->EEDrawList;
while( bs )
......@@ -448,7 +448,7 @@ int DrawSheetStruct::CountSheets()
/******************************************/
wxString DrawSheetStruct::GetFileName(void)
wxString DrawSheetStruct::GetFileName( void )
/******************************************/
{
return m_FileName;
......@@ -456,12 +456,108 @@ wxString DrawSheetStruct::GetFileName(void)
/************************************************************/
void DrawSheetStruct::SetFileName(const wxString & aFilename)
void DrawSheetStruct::SetFileName( const wxString& 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 */
/************************/
......
......@@ -138,7 +138,8 @@ public:
bool LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetPath* list );
int CountSheets();
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);
//to remove a sheet, just delete it
......
......@@ -257,21 +257,19 @@ SCH_SCREEN * WinEDA_SchematicFrame::CreateNewScreen(
void WinEDA_SchematicFrame::SaveProject( )
/****************************************************/
/* Sauvegarde toutes les feuilles du projet
* et cr�e une librairie archive des composants, de nom <root_name>.chche.lib
/* Saves the entire project and creates an archive for components
* the library archive name is <root_name>.cache.lib
*/
{
SCH_SCREEN* screen_tmp, *screen;
SCH_SCREEN* screen;
wxString LibArchiveFileName;
screen_tmp = (SCH_SCREEN*)GetScreen(); //save...
EDA_ScreenList ScreenList;
for( screen = ScreenList.GetFirst(); screen != NULL;
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 );
}
......
......@@ -163,7 +163,8 @@ void WinEDA_SheetPropertiesFrame::CreateControls()
itemBoxSizer3->Add( itemBoxSizer4, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC, _(
"Filename:" ), wxDefaultPosition, wxDefaultSize, 0 );
"Filename:" ), wxDefaultPosition,
wxDefaultSize, 0 );
itemBoxSizer4->Add( itemStaticText5,
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
......@@ -171,11 +172,13 @@ void WinEDA_SheetPropertiesFrame::CreateControls()
m_FileNameWin =
new wxTextCtrl( itemDialog1, ID_TEXTCTRL1, _T( "" ), wxDefaultPosition, wxSize( 300,
-1 ), wxTE_PROCESS_ENTER );
-1 ),
wxTE_PROCESS_ENTER );
itemBoxSizer4->Add( m_FileNameWin, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
wxStaticText* itemStaticText7 = new wxStaticText( itemDialog1, wxID_STATIC, _(
"Sheetname:" ), wxDefaultPosition, wxDefaultSize, 0 );
"Sheetname:" ), wxDefaultPosition,
wxDefaultSize, 0 );
itemBoxSizer4->Add( itemStaticText7,
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
......@@ -278,6 +281,11 @@ wxIcon WinEDA_SheetPropertiesFrame::GetIconResource( const wxString& name )
/*****************************************************************************/
void WinEDA_SheetPropertiesFrame::SheetPropertiesAccept( wxCommandEvent& event )
/*****************************************************************************/
/** Function SheetPropertiesAccept
* Set the new sheets properties:
* sheetname and filename (text and size)
*/
{
wxString FileName, msg;
......@@ -292,39 +300,15 @@ void WinEDA_SheetPropertiesFrame::SheetPropertiesAccept( wxCommandEvent& event )
}
ChangeFileNameExt( FileName, g_SchExtBuffer );
if( (m_CurrentSheet->GetFileName() != FileName)
|| (m_CurrentSheet->m_Flags & IS_NEW)
|| !m_CurrentSheet->m_AssociatedScreen )
{
m_CurrentSheet->SetFileName( FileName );
if( wxFileExists( FileName ) ) //do we reload the data from the existing file
{
msg.Printf( _(
"A file named %s exists, load it (otherwise overwrite it)?" ),
FileName.GetData() );
if( IsOK( this, msg ) )
if ( (FileName != m_CurrentSheet->GetFileName()) && m_CurrentSheet->m_AssociatedScreen )
{
if( m_CurrentSheet->m_AssociatedScreen )
msg = _("Changing a Filename can change all the schematic structure and cannot be undone" );
msg << wxT("\n");
msg << _("Ok to continue renaming?");
if( IsOK( NULL, msg) )
{
m_CurrentSheet->m_AssociatedScreen->m_RefCount--;
if( m_CurrentSheet->m_AssociatedScreen->m_RefCount == 0 )
SAFE_DELETE( m_CurrentSheet->m_AssociatedScreen );
}
m_CurrentSheet->m_AssociatedScreen = NULL; //so that we reload..
m_CurrentSheet->Load( m_Parent );
}
}
else
{
//just make a new screen if needed.
if( !m_CurrentSheet->m_AssociatedScreen )
{
m_CurrentSheet->m_AssociatedScreen = new SCH_SCREEN( SCHEMATIC_FRAME );
m_CurrentSheet->m_AssociatedScreen->m_RefCount++; //be careful with these
m_CurrentSheet->m_AssociatedScreen->m_FileName = FileName;
}
m_Parent->GetScreen()->ClearUndoRedoList();
m_CurrentSheet->ChangeFileName(m_Parent, FileName);
}
}
......@@ -351,9 +335,9 @@ void WinEDA_SheetPropertiesFrame::SheetPropertiesAccept( wxCommandEvent& event )
/*************************************************************************/
bool WinEDA_SchematicFrame::EditSheet( DrawSheetStruct* Sheet, wxDC* DC )
{
/*************************************************************************/
/* Routine to edit the SheetName and the FileName for the sheet "Sheet" */
{
WinEDA_SheetPropertiesFrame* frame;
bool edit = TRUE;
......@@ -378,9 +362,9 @@ bool WinEDA_SchematicFrame::EditSheet( DrawSheetStruct* Sheet, wxDC* DC )
#define SHEET_MIN_HEIGHT 150
/****************************************************************/
DrawSheetStruct* WinEDA_SchematicFrame::CreateSheet( wxDC* DC )
{
/****************************************************************/
/* Routine de Creation d'une feuille de hierarchie (Sheet) */
{
g_ItemToRepeat = NULL;
DrawSheetStruct* Sheet = new DrawSheetStruct( GetScreen()->m_Curseur );
......@@ -408,8 +392,8 @@ DrawSheetStruct* WinEDA_SchematicFrame::CreateSheet( wxDC* DC )
/*******************************************************************************/
void WinEDA_SchematicFrame::ReSizeSheet( DrawSheetStruct* Sheet, wxDC* DC )
/*******************************************************************************/
{
/*******************************************************************************/
DrawSheetLabelStruct* sheetlabel;
if( Sheet == NULL )
......@@ -437,7 +421,8 @@ void WinEDA_SchematicFrame::ReSizeSheet( DrawSheetStruct* Sheet, wxDC* DC )
while( sheetlabel )
{
s_SheetMindx = MAX( s_SheetMindx,
(int) ( (sheetlabel->GetLength() + 1) * sheetlabel->m_Size.x ) );
(int) ( (sheetlabel->GetLength() +
1) * sheetlabel->m_Size.x ) );
s_SheetMindy = MAX( s_SheetMindy, sheetlabel->m_Pos.y - Sheet->m_Pos.y );
sheetlabel = (DrawSheetLabelStruct*) sheetlabel->Pnext;
}
......@@ -450,8 +435,8 @@ void WinEDA_SchematicFrame::ReSizeSheet( DrawSheetStruct* Sheet, wxDC* DC )
/*********************************************************************************/
void WinEDA_SchematicFrame::StartMoveSheet( DrawSheetStruct* Sheet, wxDC* DC )
/*********************************************************************************/
{
/*********************************************************************************/
if( (Sheet == NULL) || ( Sheet->Type() != DRAW_SHEET_STRUCT_TYPE) )
return;
......
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