2007-09-30 02:37:06 +00:00
|
|
|
/****************************/
|
|
|
|
/* EESCHEMA - files-io.cpp */
|
|
|
|
/****************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
#include "id.h"
|
|
|
|
|
2008-02-27 19:38:16 +00:00
|
|
|
#include "schframe.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Fonctions locales */
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************/
|
2007-09-30 02:37:06 +00:00
|
|
|
void WinEDA_SchematicFrame::Save_File( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
/****************************************************************/
|
2007-09-30 02:37:06 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
/* Commands to save project or the current page.
|
2007-09-30 02:37:06 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-30 02:37:06 +00:00
|
|
|
int id = event.GetId();
|
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
|
|
|
case ID_SAVE_PROJECT: /* Update Schematic File */
|
2008-02-12 21:12:46 +00:00
|
|
|
SaveProject( );
|
2007-09-30 02:37:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SAVE_ONE_SHEET: /* Update Schematic File */
|
|
|
|
SaveEEFile( NULL, FILE_SAVE_AS );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_SAVE_ONE_SHEET_AS: /* Save EED (new name) */
|
|
|
|
SaveEEFile( NULL, FILE_SAVE_NEW );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DisplayError( this, wxT( "WinEDA_SchematicFrame::Save_File Internal Error" ) );
|
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************************/
|
2008-02-12 21:12:46 +00:00
|
|
|
//bool WinEDA_SchematicFrame::LoadOneSheet(DrawSheetStruct* sheet, const wxString& filename )
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************************************************************************/
|
2008-02-12 21:12:46 +00:00
|
|
|
//{
|
|
|
|
// return FALSE;
|
|
|
|
//when is this used? and why?
|
|
|
|
/*
|
|
|
|
//this must be called with a non-null pointer screen pointer, clearly.
|
|
|
|
//also note that this is for reading in a *root* file
|
2007-09-30 02:37:06 +00:00
|
|
|
wxString FullFileName = filename;
|
|
|
|
|
|
|
|
if( FullFileName.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxString mask;
|
|
|
|
mask = wxT( "*" ) + g_SchExtBuffer;
|
|
|
|
FullFileName = EDA_FileSelector( _( "Schematic files:" ),
|
2008-02-12 21:12:46 +00:00
|
|
|
wxEmptyString, //default path
|
2008-02-26 19:19:54 +00:00
|
|
|
sheet->m_AssociatedScreen->m_FileName,// default filename
|
2008-02-12 21:12:46 +00:00
|
|
|
g_SchExtBuffer, // extension par defaut
|
|
|
|
mask, // Masque d'affichage
|
2007-09-30 02:37:06 +00:00
|
|
|
this,
|
|
|
|
wxFD_OPEN,
|
|
|
|
FALSE
|
|
|
|
);
|
|
|
|
if( FullFileName.IsEmpty() )
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearProjectDrawList( screen, TRUE );
|
2008-02-12 21:12:46 +00:00
|
|
|
printf("in LoadOneScreen setting screen filename: %s \n", (const char*) FullFileName.mb_str() );
|
2007-09-30 02:37:06 +00:00
|
|
|
screen->m_FileName = FullFileName;
|
2008-02-12 21:12:46 +00:00
|
|
|
LoadDrawSheet( DrawSheetStruct * sheet, filename);
|
2007-09-30 02:37:06 +00:00
|
|
|
screen->SetModify();
|
|
|
|
|
|
|
|
if( GetScreen() == screen )
|
|
|
|
Refresh( TRUE );
|
|
|
|
return TRUE;
|
2008-02-12 21:12:46 +00:00
|
|
|
*/
|
|
|
|
//}
|
|
|
|
|
|
|
|
/************************************************************************************/
|
|
|
|
int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNew )
|
|
|
|
/************************************************************************************/
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Load an entire project
|
|
|
|
* ( schematic root file and its subhierarchies, the configuration and the libs
|
|
|
|
* which are not already loaded)
|
|
|
|
*/
|
|
|
|
SCH_SCREEN* screen;
|
|
|
|
wxString FullFileName, msg;
|
|
|
|
bool LibCacheExist = FALSE;
|
|
|
|
|
|
|
|
EDA_ScreenList ScreenList;
|
|
|
|
|
|
|
|
for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
|
|
|
|
{
|
|
|
|
if( screen->IsModify() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( screen )
|
|
|
|
{
|
|
|
|
if( !IsOK( this, _( "Clear Schematic Hierarchy (modified!)?" ) ) )
|
|
|
|
return FALSE;
|
2008-02-26 19:19:54 +00:00
|
|
|
if( g_RootSheet->m_AssociatedScreen->m_FileName != g_DefaultSchematicFileName )
|
|
|
|
SetLastProject( g_RootSheet->m_AssociatedScreen->m_FileName );
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FullFileName = FileName;
|
|
|
|
if( ( FullFileName.IsEmpty() ) && !IsNew )
|
|
|
|
{
|
|
|
|
wxString mask = wxT( "*" ) + g_SchExtBuffer;
|
|
|
|
FullFileName = EDA_FileSelector( _( "Schematic files:" ),
|
|
|
|
wxEmptyString, /* Chemin par defaut */
|
|
|
|
wxEmptyString, /* nom fichier par defaut */
|
|
|
|
g_SchExtBuffer, /* extension par defaut */
|
|
|
|
mask, /* Masque d'affichage */
|
|
|
|
this,
|
|
|
|
wxFD_OPEN,
|
|
|
|
TRUE
|
|
|
|
);
|
|
|
|
if( FullFileName.IsEmpty() )
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(g_RootSheet){
|
|
|
|
SAFE_DELETE(g_RootSheet);
|
|
|
|
}
|
|
|
|
CreateScreens();
|
|
|
|
screen = (SCH_SCREEN*)GetScreen();
|
|
|
|
|
|
|
|
wxSetWorkingDirectory( wxPathOnly( FullFileName ) );
|
|
|
|
GetScreen()->m_FileName = FullFileName;
|
2008-02-28 19:27:25 +00:00
|
|
|
g_RootSheet->SetFileName(FullFileName);
|
2008-02-12 21:12:46 +00:00
|
|
|
Affiche_Message( wxEmptyString );
|
|
|
|
MsgPanel->EraseMsgBox();
|
|
|
|
|
|
|
|
memset( &g_EESchemaVar, 0, sizeof(g_EESchemaVar) );
|
|
|
|
|
|
|
|
GetScreen()->ClrModify();
|
2008-02-26 19:19:54 +00:00
|
|
|
//m_CurrentSheet->m_AssociatedScreen->Pnext = NULL; should be by default
|
2008-02-12 21:12:46 +00:00
|
|
|
|
|
|
|
if( IsNew )
|
|
|
|
{
|
|
|
|
screen->m_CurrentSheetDesc = &g_Sheet_A4;
|
|
|
|
screen->SetZoom( 32 );
|
|
|
|
screen->m_ScreenNumber = screen->m_NumberOfScreen = 1;
|
|
|
|
screen->m_Title = wxT( "noname.sch" );
|
|
|
|
GetScreen()->m_FileName = screen->m_Title;
|
|
|
|
screen->m_Company.Empty();
|
|
|
|
screen->m_Commentaire1.Empty();
|
|
|
|
screen->m_Commentaire2.Empty();
|
|
|
|
screen->m_Commentaire3.Empty();
|
|
|
|
screen->m_Commentaire4.Empty();
|
|
|
|
Read_Config( wxEmptyString, TRUE );
|
|
|
|
Zoom_Automatique( TRUE );
|
|
|
|
ReDrawPanel();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rechargement de la configuration:
|
|
|
|
msg = _( "Ready\nWorking dir: \n" ) + wxGetCwd();
|
|
|
|
PrintMsg( msg );
|
|
|
|
|
|
|
|
Read_Config( wxEmptyString, FALSE );
|
|
|
|
|
|
|
|
// Delete old caches.
|
|
|
|
LibraryStruct* nextlib, * lib = g_LibraryList;
|
|
|
|
for( ; lib != NULL; lib = nextlib )
|
|
|
|
{
|
|
|
|
nextlib = lib->m_Pnext;
|
|
|
|
if( lib->m_IsLibCache )
|
|
|
|
FreeCmpLibrary( this, lib->m_Name );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( IsNew )
|
|
|
|
{
|
|
|
|
ReDrawPanel();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loading the project library cache
|
|
|
|
wxString FullLibName;
|
|
|
|
wxString shortfilename;
|
2008-02-26 19:19:54 +00:00
|
|
|
wxSplitPath( g_RootSheet->m_AssociatedScreen->m_FileName, NULL, &shortfilename, NULL );
|
2008-02-12 21:12:46 +00:00
|
|
|
FullLibName << wxT( "." ) << STRING_DIR_SEP << shortfilename << wxT( ".cache" ) <<
|
|
|
|
g_LibExtBuffer;
|
|
|
|
if( wxFileExists( FullLibName ) )
|
|
|
|
{
|
|
|
|
wxString libname;
|
|
|
|
libname = FullLibName;
|
|
|
|
ChangeFileNameExt( libname, wxEmptyString );
|
|
|
|
msg = wxT( "Load " ) + FullLibName;
|
|
|
|
LibraryStruct* LibCache = LoadLibraryName( this, FullLibName, libname );
|
|
|
|
if( LibCache )
|
|
|
|
{
|
|
|
|
LibCache->m_IsLibCache = TRUE;
|
|
|
|
msg += wxT( " OK" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
msg += wxT( " ->Error" );
|
|
|
|
PrintMsg( msg );
|
|
|
|
LibCacheExist = TRUE;
|
|
|
|
}
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
if( !wxFileExists( g_RootSheet->m_AssociatedScreen->m_FileName ) && !LibCacheExist ) // Nouveau projet prpbablement
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "File %s not found (new project ?)" ),
|
2008-02-26 19:19:54 +00:00
|
|
|
g_RootSheet->m_AssociatedScreen->m_FileName.GetData() );
|
2008-02-12 21:12:46 +00:00
|
|
|
DisplayInfo( this, msg, 20 );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//load the project.
|
2008-02-26 19:19:54 +00:00
|
|
|
SAFE_DELETE(g_RootSheet->m_AssociatedScreen);
|
2008-02-28 19:27:25 +00:00
|
|
|
bool diag = g_RootSheet->Load(this);
|
2008-02-12 21:12:46 +00:00
|
|
|
|
|
|
|
/* Reaffichage ecran de base (ROOT) si necessaire */
|
|
|
|
ActiveScreen = GetScreen();
|
|
|
|
Zoom_Automatique( FALSE );
|
|
|
|
DrawPanel->Refresh( TRUE );
|
2008-02-28 19:27:25 +00:00
|
|
|
return diag;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
/**********************************************************/
|
|
|
|
SCH_SCREEN * WinEDA_SchematicFrame::CreateNewScreen(
|
|
|
|
SCH_SCREEN * OldScreen, int TimeStamp)
|
|
|
|
/**********************************************************/
|
|
|
|
/* Routine de creation ( par allocation memoire ) d'un nouvel ecran
|
|
|
|
cet ecran est en chainage arriere avec OldScreen
|
|
|
|
la valeur TimeStamp est attribuee au parametre NewScreen->TimeStamp
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
SCH_SCREEN * NewScreen;
|
|
|
|
|
|
|
|
NewScreen = new SCH_SCREEN(SCHEMATIC_FRAME);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
NewScreen->SetRefreshReq();
|
|
|
|
if(OldScreen) NewScreen->m_Company = OldScreen->m_Company;
|
|
|
|
NewScreen->m_TimeStamp = TimeStamp;
|
|
|
|
|
|
|
|
NewScreen->Pback = OldScreen;
|
|
|
|
|
|
|
|
return(NewScreen);
|
|
|
|
}
|
2007-09-30 02:37:06 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/****************************************************/
|
2008-02-12 21:12:46 +00:00
|
|
|
void WinEDA_SchematicFrame::SaveProject( )
|
2007-06-05 12:10:51 +00:00
|
|
|
/****************************************************/
|
2007-09-30 02:37:06 +00:00
|
|
|
|
2008-02-29 12:33:07 +00:00
|
|
|
/* Saves the entire project and creates an archive for components
|
|
|
|
* the library archive name is <root_name>.cache.lib
|
2007-09-30 02:37:06 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-02-29 12:33:07 +00:00
|
|
|
SCH_SCREEN* screen;
|
2007-09-30 02:37:06 +00:00
|
|
|
wxString LibArchiveFileName;
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
EDA_ScreenList ScreenList;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
for( screen = ScreenList.GetFirst(); screen != NULL;
|
|
|
|
screen = ScreenList.GetNext() )
|
2007-09-30 02:37:06 +00:00
|
|
|
{
|
2008-02-29 12:33:07 +00:00
|
|
|
printf("SaveEEFile, %s\n", CONV_TO_UTF8(screen->m_FileName) );
|
2008-02-12 21:12:46 +00:00
|
|
|
SaveEEFile( screen, FILE_SAVE_AS );
|
2007-09-30 02:37:06 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-09-30 02:37:06 +00:00
|
|
|
/* Creation du fichier d'archivage composants en repertoire courant */
|
2008-02-12 21:12:46 +00:00
|
|
|
LibArchiveFileName = MakeFileName( wxEmptyString, GetScreen()->m_FileName, wxEmptyString );
|
2007-09-30 02:37:06 +00:00
|
|
|
ChangeFileNameExt( LibArchiveFileName, wxEmptyString );
|
|
|
|
|
|
|
|
/* mise a jour extension */
|
|
|
|
LibArchiveFileName += wxT( ".cache" ) + g_LibExtBuffer;
|
2008-02-12 21:12:46 +00:00
|
|
|
LibArchive( this, LibArchiveFileName );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-30 02:37:06 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
int CountCmpNumber()
|
2007-06-05 12:10:51 +00:00
|
|
|
/************************/
|
2007-09-30 02:37:06 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Routine retournant le nombre de composants dans le schema,
|
2007-09-30 02:37:06 +00:00
|
|
|
* powers non comprises */
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
return g_RootSheet->ComponentCount();
|
|
|
|
/*
|
2007-09-30 02:37:06 +00:00
|
|
|
BASE_SCREEN* Window;
|
|
|
|
EDA_BaseStruct* Phead;
|
|
|
|
int Nb = 0;
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
|
|
|
|
2007-09-30 02:37:06 +00:00
|
|
|
Window = ScreenSch;
|
|
|
|
while( Window )
|
|
|
|
{
|
|
|
|
for( Phead = Window->EEDrawList; Phead != NULL; Phead = Phead->Pnext )
|
|
|
|
{
|
|
|
|
if( Phead->Type() == DRAW_LIB_ITEM_STRUCT_TYPE )
|
|
|
|
{
|
|
|
|
DrawPartStruct* Cmp = (DrawPartStruct*) Phead;
|
|
|
|
if( Cmp->m_Field[VALUE].m_Text.GetChar( 0 ) != '#' )
|
|
|
|
Nb++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Window = (BASE_SCREEN*) Window->Pnext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Nb;
|
2008-02-12 21:12:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|