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
......
......@@ -43,14 +43,13 @@ DrawSheetStruct::DrawSheetStruct( const wxPoint& pos ) :
m_NbLabel = 0;
m_Layer = LAYER_SHEET;
m_Pos = pos;
m_TimeStamp = GetTimeStamp();
m_SheetNameSize = m_FileNameSize = 60;
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_SheetNumber = 1;
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;
......@@ -387,7 +387,7 @@ bool DrawSheetStruct::LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetPath* lis
bool DrawSheetStruct::Load( WinEDA_SchematicFrame* frame )
/*******************************************************************************/
{
bool success = true;
bool success = true;
if( !m_AssociatedScreen )
{
......@@ -404,21 +404,21 @@ 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 )
{
EDA_BaseStruct* bs = m_AssociatedScreen->EEDrawList;
while( bs )
{
if( bs->Type() == DRAW_SHEET_STRUCT_TYPE )
{
DrawSheetStruct* sheetstruct = (DrawSheetStruct*) bs;
if( !sheetstruct->Load( frame ) )
success = false;
}
bs = bs->Pnext;
}
}
success = frame->LoadOneEEFile( m_AssociatedScreen, m_FileName );
if( success )
{
EDA_BaseStruct* bs = m_AssociatedScreen->EEDrawList;
while( bs )
{
if( bs->Type() == DRAW_SHEET_STRUCT_TYPE )
{
DrawSheetStruct* sheetstruct = (DrawSheetStruct*) bs;
if( !sheetstruct->Load( frame ) )
success = false;
}
bs = bs->Pnext;
}
}
}
}
return success;
......@@ -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 */
/************************/
......@@ -646,7 +742,7 @@ EDA_BaseStruct* DrawSheetPath::LastDrawList()
void DrawSheetPath::Push( DrawSheetStruct* sheet )
{
wxASSERT( m_numSheets <= DSLSZ );
wxASSERT( m_numSheets <= DSLSZ );
if( m_numSheets < DSLSZ )
{
m_sheets[m_numSheets] = sheet;
......
......@@ -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 );
}
......
......@@ -99,11 +99,11 @@ WinEDA_SheetPropertiesFrame::WinEDA_SheetPropertiesFrame( WinEDA_SchematicFrame*
AddUnitSymbol( *m_SheetNameTextSize );
PutValueInLocalUnits( *m_SheetNameSize, m_CurrentSheet->m_SheetNameSize,
m_Parent->m_InternalUnits );
m_Parent->m_InternalUnits );
AddUnitSymbol( *m_FileNameTextSize );
PutValueInLocalUnits( *m_FileNameSize, m_CurrentSheet->m_FileNameSize,
m_Parent->m_InternalUnits );
m_Parent->m_InternalUnits );
}
......@@ -163,52 +163,55 @@ 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,
5 );
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
5 );
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,
5 );
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
5 );
m_SheetNameWin =
new wxTextCtrl( itemDialog1, ID_TEXTCTRL, _T( "" ), wxDefaultPosition, wxSize( 300,
-1 ), 0 );
-1 ), 0 );
itemBoxSizer4->Add( m_SheetNameWin, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
wxBoxSizer* itemBoxSizer9 = new wxBoxSizer( wxVERTICAL );
itemBoxSizer3->Add( itemBoxSizer9, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
m_FileNameTextSize = new wxStaticText( itemDialog1, wxID_STATIC, _(
"Size" ), wxDefaultPosition, wxDefaultSize, 0 );
"Size" ), wxDefaultPosition, wxDefaultSize, 0 );
itemBoxSizer9->Add( m_FileNameTextSize,
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
5 );
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
5 );
m_FileNameSize = new wxTextCtrl( itemDialog1, ID_TEXTCTRL2, _T(
"" ), wxDefaultPosition, wxDefaultSize, 0 );
"" ), wxDefaultPosition, wxDefaultSize, 0 );
itemBoxSizer9->Add( m_FileNameSize, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
m_SheetNameTextSize = new wxStaticText( itemDialog1, wxID_STATIC, _(
"Size" ), wxDefaultPosition, wxDefaultSize, 0 );
"Size" ), wxDefaultPosition, wxDefaultSize, 0 );
itemBoxSizer9->Add( m_SheetNameTextSize,
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
5 );
0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
5 );
m_SheetNameSize = new wxTextCtrl( itemDialog1, ID_TEXTCTRL3, _T(
"" ), wxDefaultPosition, wxDefaultSize, 0 );
"" ), wxDefaultPosition, wxDefaultSize, 0 );
itemBoxSizer9->Add( m_SheetNameSize, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
itemBoxSizer2->Add( 5, 5, 1, wxGROW | wxALL, 5 );
......@@ -217,12 +220,12 @@ void WinEDA_SheetPropertiesFrame::CreateControls()
itemBoxSizer2->Add( itemBoxSizer15, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );
wxButton* itemButton16 = new wxButton( itemDialog1, wxID_CANCEL, _(
"&Cancel" ), wxDefaultPosition, wxDefaultSize, 0 );
"&Cancel" ), wxDefaultPosition, wxDefaultSize, 0 );
itemButton16->SetForegroundColour( wxColour( 0, 0, 255 ) );
itemBoxSizer15->Add( itemButton16, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
wxButton* itemButton17 = new wxButton( itemDialog1, wxID_OK, _(
"&OK" ), wxDefaultPosition, wxDefaultSize, 0 );
"&OK" ), wxDefaultPosition, wxDefaultSize, 0 );
itemButton17->SetForegroundColour( wxColour( 196, 0, 0 ) );
itemBoxSizer15->Add( itemButton17, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
......@@ -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,52 +300,28 @@ 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( m_CurrentSheet->m_AssociatedScreen )
{
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;
}
}
}
if ( (FileName != m_CurrentSheet->GetFileName()) && 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_Parent->GetScreen()->ClearUndoRedoList();
m_CurrentSheet->ChangeFileName(m_Parent, FileName);
}
}
msg = m_FileNameSize->GetValue();
m_CurrentSheet->m_FileNameSize =
ReturnValueFromString( g_UnitMetric,
msg, m_Parent->m_InternalUnits );
msg, m_Parent->m_InternalUnits );
m_CurrentSheet->m_SheetName = m_SheetNameWin->GetValue();
msg = m_SheetNameSize->GetValue();
m_CurrentSheet->m_SheetNameSize =
ReturnValueFromString( g_UnitMetric,
msg, m_Parent->m_InternalUnits );
msg, m_Parent->m_InternalUnits );
if( ( m_CurrentSheet->m_SheetName.IsEmpty() ) )
{
......@@ -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;
......@@ -489,9 +474,9 @@ static void DeplaceSheet( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
if( Sheet->m_Flags & IS_RESIZED )
{
Sheet->m_Size.x = MAX( s_SheetMindx,
screen->m_Curseur.x - Sheet->m_Pos.x );
screen->m_Curseur.x - Sheet->m_Pos.x );
Sheet->m_Size.y = MAX( s_SheetMindy,
screen->m_Curseur.y - Sheet->m_Pos.y );
screen->m_Curseur.y - Sheet->m_Pos.y );
SheetLabel = Sheet->m_Label;
while( SheetLabel )
{
......@@ -500,7 +485,7 @@ static void DeplaceSheet( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
SheetLabel = (DrawSheetLabelStruct*) SheetLabel->Pnext;
}
}
else /* Move Sheet */
else /* Move Sheet */
{
move_vector.x = screen->m_Curseur.x - Sheet->m_Pos.x;
move_vector.y = screen->m_Curseur.y - Sheet->m_Pos.y;
......@@ -523,12 +508,12 @@ static void ExitSheet( WinEDA_DrawPanel* Panel, wxDC* DC )
return;
/* Deplacement composant en cours */
if( Sheet->m_Flags & IS_NEW ) /* Nouveau Placement en cours, on l'efface */
if( Sheet->m_Flags & IS_NEW ) /* Nouveau Placement en cours, on l'efface */
{
RedrawOneStruct( Panel, DC, Sheet, g_XorMode );
SAFE_DELETE( Sheet );
}
else if( Sheet->m_Flags & IS_RESIZED ) /* resize en cours: on l'annule */
else if( Sheet->m_Flags & IS_RESIZED ) /* resize en cours: on l'annule */
{
RedrawOneStruct( Panel, DC, Sheet, g_XorMode );
Sheet->m_Size.x = s_OldPos.x;
......@@ -536,7 +521,7 @@ static void ExitSheet( WinEDA_DrawPanel* Panel, wxDC* DC )
RedrawOneStruct( Panel, DC, Sheet, GR_DEFAULT_DRAWMODE );
Sheet->m_Flags = 0;
}
else if( Sheet->m_Flags & IS_MOVED ) /* move en cours: on l'annule */
else if( Sheet->m_Flags & IS_MOVED ) /* move en cours: on l'annule */
{
wxPoint curspos = Screen->m_Curseur;
Panel->m_Parent->GetScreen()->m_Curseur = s_OldPos;
......
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