kicad/eeschema/files-io.cpp

157 lines
4.3 KiB
C++
Raw Normal View History

2007-09-30 02:37:06 +00:00
/****************************/
/* EESCHEMA - files-io.cpp */
/****************************/
#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"
/* Fonctions locales */
/****************************************************************/
2007-09-30 02:37:06 +00:00
void WinEDA_SchematicFrame::Save_File( wxCommandEvent& event )
/****************************************************************/
2007-09-30 02:37:06 +00:00
/* Commands to save shepatic project or the current page.
2007-09-30 02:37:06 +00:00
*/
{
2007-09-30 02:37:06 +00:00
int id = event.GetId();
switch( id )
{
case ID_SAVE_PROJECT: /* Update Schematic File */
SaveProject( this );
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-09-30 02:37:06 +00:00
bool WinEDA_SchematicFrame::LoadOneSheet( SCH_SCREEN* screen, const wxString& filename )
/******************************************************************************************/
{
2007-09-30 02:37:06 +00:00
wxString FullFileName = filename;
if( screen->EEDrawList != NULL )
{
if( !IsOK( this, _( "Clear SubHierarchy ?" ) ) )
return FALSE;
}
if( FullFileName.IsEmpty() )
{
wxString mask;
mask = wxT( "*" ) + g_SchExtBuffer;
FullFileName = EDA_FileSelector( _( "Schematic files:" ),
wxEmptyString, /* default path */
screen->m_FileName, /* default filename */
g_SchExtBuffer, /* extension par defaut */
mask, /* Masque d'affichage */
this,
wxFD_OPEN,
FALSE
);
if( FullFileName.IsEmpty() )
return FALSE;
}
ClearProjectDrawList( screen, TRUE );
screen->m_FileName = FullFileName;
LoadOneEEFile( screen, FullFileName );
screen->SetModify();
if( GetScreen() == screen )
Refresh( TRUE );
return TRUE;
}
2007-09-30 02:37:06 +00:00
/****************************************************/
2007-09-30 02:37:06 +00:00
void SaveProject( WinEDA_SchematicFrame* frame )
/****************************************************/
2007-09-30 02:37:06 +00:00
/* Sauvegarde toutes les feuilles du projet
2007-09-30 02:37:06 +00:00
* et cr<EFBFBD>e une librairie archive des composants, de nom <root_name>.chche.lib
*/
{
2007-09-30 02:37:06 +00:00
SCH_SCREEN* screen_tmp;
wxString LibArchiveFileName;
if( frame == NULL )
return;
2007-09-30 02:37:06 +00:00
screen_tmp = frame->GetScreen();
2007-09-30 02:37:06 +00:00
EDA_ScreenList ScreenList( NULL );
2007-09-30 02:37:06 +00:00
for( ActiveScreen = ScreenList.GetFirst();
ActiveScreen != NULL;
ActiveScreen = ScreenList.GetNext() )
{
frame->m_CurrentScreen = ActiveScreen;
frame->SaveEEFile( NULL, FILE_SAVE_AS );
}
2007-09-30 02:37:06 +00:00
frame->m_CurrentScreen = ActiveScreen = screen_tmp;
2007-09-30 02:37:06 +00:00
/* Creation du fichier d'archivage composants en repertoire courant */
LibArchiveFileName = MakeFileName( wxEmptyString, ScreenSch->m_FileName, wxEmptyString );
ChangeFileNameExt( LibArchiveFileName, wxEmptyString );
/* mise a jour extension */
LibArchiveFileName += wxT( ".cache" ) + g_LibExtBuffer;
LibArchive( frame, LibArchiveFileName );
}
2007-09-30 02:37:06 +00:00
/************************/
int CountCmpNumber()
/************************/
2007-09-30 02:37:06 +00:00
/* Routine retournant le nombre de composants dans le schema,
2007-09-30 02:37:06 +00:00
* powers non comprises */
{
2007-09-30 02:37:06 +00:00
BASE_SCREEN* Window;
EDA_BaseStruct* Phead;
int Nb = 0;
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;
}