Commit bf688ea1 authored by charras's avatar charras

eeschema: code cleaning

parent 2057c815
......@@ -15,6 +15,7 @@ set(EESCHEMA_SRCS
class_drawsheet.cpp
class_hierarchical_PIN_sheet.cpp
class_pin.cpp
class_library.cpp
class_schematic_items.cpp
class_screen.cpp
class_text-label.cpp
......@@ -56,7 +57,6 @@ set(EESCHEMA_SRCS
hotkeys.cpp
libalias.cpp
libarch.cpp
libclass.cpp
libedit.cpp
libedit_onleftclick.cpp
libedit_onrightclick.cpp
......
......@@ -45,8 +45,21 @@ public:
public:
LibraryStruct( int type, const wxString& name, const wxString& fullname );
~LibraryStruct();
bool WriteHeader( FILE* file );
/**
* Function SaveLibrary
* writes the data structures for this object out to 2 file
* the library in "*.lib" format.
* the doc file in "*.dcm" format.
* creates a backup file for each file (.bak and .bck)
* @param aFullFileName The full lib filename.
* @return bool - true if success writing else false.
*/
bool SaveLibrary( const wxString& aFullFileName );
bool ReadHeader( FILE* file, int* LineNum );
private:
bool WriteHeader( FILE* file );
};
......@@ -73,8 +86,15 @@ public:
return wxT( "LibCmpEntry" );
}
bool WriteDescr( FILE* File );
/**
* Function SaveLibrary
* writes the data structures for this object out to 2 FILE in "*.lib" and ".dcm" format.
* the main file (.lib) is the library content (set of components)
* the second file (.dcm)is the auxiliary file that contents the keywords and description for components)
* @param FullFileName the new full filename (*.lib).
* @return bool - true if success writing else false.
*/
bool SaveLibrary( const wxString& FullFileName );
};
......
......@@ -761,9 +761,9 @@ int LibDrawPin::ReturnPinDrawOrient( int TransMat[2][2] )
}
/****************************************************/
void LibDrawPin::ReturnPinStringNum( wxString& buffer )
/****************************************************/
/***********************************************************/
void LibDrawPin::ReturnPinStringNum( wxString& buffer ) const
/***********************************************************/
/* fill the buffer with pin num as a wxString
* Pin num is coded as a long
......@@ -772,7 +772,7 @@ void LibDrawPin::ReturnPinStringNum( wxString& buffer )
{
char ascii_buf[5];
strncpy( ascii_buf, (char*) &m_PinNum, 4 );
memcpy(ascii_buf, &m_PinNum , 4);
ascii_buf[4] = 0;
buffer = CONV_FROM_UTF8( ascii_buf );
......
......@@ -151,7 +151,7 @@ public:
* @param aOffset = offset to draw
* @param aColor = -1 to use the normal body item color, or use this color if >= 0
* @param aDrawMode = GR_OR, GR_XOR, ...
* @param aData = pointer used to pass others parametres, depending on body items.
* @param aData = value or pointer used to pass others parametres, depending on body items.
* used for some items to force to force no fill mode
* ( has meaning only for items what can be filled ). used in printing or moving objects mode
* or to pass refernce to the lib component for pins
......@@ -160,6 +160,14 @@ public:
virtual void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
int aDrawMode, void * aData, int aTransformMatrix[2][2] ) = 0;
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) const = 0;
void Display_Infos_DrawEntry( WinEDA_DrawFrame* frame );
};
......@@ -189,15 +197,21 @@ public:
{
return wxT( "LibDrawPin" );
}
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) const;
LibDrawPin* GenCopy();
bool WriteDescr( FILE* File );
void Display_Infos( WinEDA_DrawFrame* frame );
wxPoint ReturnPinEndPoint();
int ReturnPinDrawOrient( int TransMat[2][2] );
void ReturnPinStringNum( wxString& buffer );
void ReturnPinStringNum( wxString& buffer ) const;
void SetPinNumFromString( wxString& buffer );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
......@@ -234,10 +248,16 @@ public:
{
return wxT( "LibDrawArc" );
}
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) const;
LibDrawArc* GenCopy();
bool WriteDescr( FILE* File );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
int aDrawMode, void * aData, int aTransformMatrix[2][2] );
};
......@@ -257,10 +277,16 @@ public:
{
return wxT( "LibDrawCircle" );
}
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) const;
LibDrawCircle* GenCopy();
bool WriteDescr( FILE* File );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
int aDrawMode, void * aData, int aTransformMatrix[2][2] );
};
......@@ -287,10 +313,16 @@ public:
{
return wxT( "LibDrawText" );
}
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) const;
LibDrawText* GenCopy();
bool WriteDescr( FILE* File );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
int aDrawMode, void * aData, int aTransformMatrix[2][2] );
};
......@@ -311,10 +343,16 @@ public:
{
return wxT( "LibDrawSquare" );
}
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) const;
LibDrawSquare* GenCopy();
bool WriteDescr( FILE* File );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
int aDrawMode, void * aData, int aTransformMatrix[2][2] );
};
......@@ -334,10 +372,16 @@ public:
{
return wxT( "LibDrawSegment" );
}
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) const;
LibDrawSegment* GenCopy();
bool WriteDescr( FILE* File );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
int aDrawMode, void * aData, int aTransformMatrix[2][2] );
};
......@@ -365,10 +409,16 @@ public:
return wxT( "LibDrawPolyline" );
}
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) const;
LibDrawPolyline* GenCopy();
void AddPoint( const wxPoint& point );
bool WriteDescr( FILE* File );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
int aDrawMode, void * aData, int aTransformMatrix[2][2] );
};
......@@ -406,11 +456,17 @@ public:
{
return wxT( "LibDrawField" );
}
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) const;
LibDrawField* GenCopy();
void Copy( LibDrawField* Target );
bool WriteDescr( FILE* File );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
int aDrawMode, void * aData, int aTransformMatrix[2][2] );
};
......
......@@ -18,12 +18,11 @@
//#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
/* Fonctions locales */
/* Descr component <DUMMY> used when a component is not found in library,
* to draw a dummy shape*/
/*
/* Local functions */
/* Descr component <DUMMY> used when a component is not found in library,
* to draw a dummy shape
* This component is a 400 mils square with the text ??
* DEF DUMMY U 0 40 Y Y 1 0 N
* F0 "U" 0 -350 60 H V
......@@ -34,9 +33,7 @@
* ENDDRAW
* ENDDEF
*/
static EDA_LibComponentStruct* DummyCmp;
static void CreateDummyCmp();
static void DrawLibPartAux( WinEDA_DrawPanel * panel, wxDC * DC,
SCH_COMPONENT * Component,
EDA_LibComponentStruct * Entry,
......@@ -45,6 +42,8 @@ static void DrawLibPartAux( WinEDA_DrawPanel * panel, wxDC * DC,
int Multi, int convert,
int DrawMode, int Color = -1, bool DrawPinText = TRUE );
/* Local variables */
static EDA_LibComponentStruct* DummyCmp;
/***************************************************************************/
wxPoint TransformCoordinate( int aTransformMatrix[2][2], wxPoint& aPosition )
......@@ -66,7 +65,7 @@ wxPoint TransformCoordinate( int aTransformMatrix[2][2], wxPoint& aPosition )
/******************************/
static void CreateDummyCmp()
void CreateDummyCmp()
/******************************/
{
DummyCmp = new EDA_LibComponentStruct( NULL );
......
......@@ -88,7 +88,6 @@ void WinEDA_LibeditFrame::ExportOnePart( bool create_lib )
{
wxString Name, mask;
LibraryStruct* NewLib, * LibTmp, * CurLibTmp;
int err;
if( CurrentLibEntry == NULL )
{
......@@ -131,7 +130,7 @@ void WinEDA_LibeditFrame::ExportOnePart( bool create_lib )
/* Sauvegarde du composant: */
CurrentLib = NewLib;
SaveOnePartInMemory();
err = SaveOneLibrary( this, Name, NewLib );
bool success = NewLib->SaveLibrary( Name );
/* Suppression de la librarie temporaire */
FreeCmpLibrary( this, NewLib->m_Name );
......@@ -139,7 +138,7 @@ void WinEDA_LibeditFrame::ExportOnePart( bool create_lib )
CurrentLib = CurLibTmp;
wxString msg;
if( create_lib && (err == 0) )
if( create_lib && success )
{
msg = Name + _( "0k" );
DisplayInfo( this,
......
......@@ -95,18 +95,13 @@ const wxChar * Text;
{
if ( ListEntry[ii] == NULL ) // Composant non trouv� en librairie
{
continue;
}
if ( ii == 0 )
continue;
}
if ( (ii == 0) || ( ListEntry[ii-1] != ListEntry[ii] ) )
{
WriteOneLibEntry(frame, ArchiveFile, ListEntry[ii]);
WriteOneLibEntry(ArchiveFile, ListEntry[ii]);
if( DocFile ) WriteOneDocLibEntry(DocFile, ListEntry[ii]);
}
else if ( ListEntry[ii-1] != ListEntry[ii] )
{
WriteOneLibEntry(frame, ArchiveFile, ListEntry[ii]);
if( DocFile ) WriteOneDocLibEntry(DocFile, ListEntry[ii]);
}
}
/* Generation fin de fichier */
......
......@@ -222,7 +222,6 @@ void WinEDA_LibeditFrame::SaveActiveLibrary()
*/
{
wxString Name, msg;
int err;
if(CurrentLib == NULL)
{
......@@ -234,11 +233,11 @@ int err;
msg = _("Modify Library File \"") + Name + _("\"?");
if( ! IsOK(this, msg) ) return;
err = SaveOneLibrary(this, Name, CurrentLib);
bool success = CurrentLib->SaveLibrary( Name );
MsgPanel->EraseMsgBox();
if ( err )
if ( ! success )
{
msg = _("Error while saving Library File \"") + Name + _("\".");
Affiche_1_Parametre(this, 1, wxT(" *** ERROR : **"), msg,BLUE);
......
......@@ -26,7 +26,7 @@ OBJECTS = eeschema.o\
class_hierarchical_PIN_sheet.o\
class_text-label.o\
component_class.o\
libclass.o\
class_library.o\
dialog_options.o\
tool_lib.o\
tool_sch.o\
......
......@@ -229,7 +229,7 @@ LibEDA_BaseStruct * CopyDrawEntryStruct( wxWindow * frame, LibEDA_BaseStruct * D
Retourne:
Pointeur sur la structure creee (ou NULL si impossible) */
int WriteOneLibEntry(wxWindow * frame, FILE * ExportFile, EDA_LibComponentStruct * LibEntry);
int WriteOneLibEntry( FILE * ExportFile, EDA_LibComponentStruct * LibEntry);
/* Routine d'ecriture du composant pointe par LibEntry
dans le fichier ExportFile( qui doit etre deja ouvert)
return: FALSE si Ok, TRUE si err write */
......@@ -246,21 +246,6 @@ int WriteOneDocLibEntry(FILE * ExportFile, EDA_LibComponentStruct * LibEntry);
1 si err write */
int SaveOneLibrary(wxWindow * frame, const wxString & FullFileName, LibraryStruct * Library);
/* Sauvegarde en fichier la librairie pointee par Library, sous le nom
FullFileName.
2 fichiers sont crees
- La librarie
- le fichier de documentation
une sauvegarde .bak de l'ancien fichier librairie est cree
une sauvegarde .bck de l'ancien fichier documentation est cree
return:
0 si OK
1 si erreur */
/***************/
/* SYMBEDIT.CPP */
/***************/
......
......@@ -2,7 +2,7 @@
/* EESchema - eesavlib.cpp */
/****************************/
/* Write Routines to save schematic libraries and library components (::WriteDescr() members)
/* Write Routines to save schematic libraries and library components (::Save() members)
*/
#include "fctsys.h"
......@@ -27,7 +27,7 @@ static bool WriteLibEntryDateAndTime( FILE* ExportFile,
static int fill_tab[3] = { 'N', 'F', 'f' };
/***********************************************/
bool LibDrawArc::WriteDescr( FILE* ExportFile )
bool LibDrawArc::Save( FILE* ExportFile ) const
/***********************************************/
/* format
......@@ -46,12 +46,12 @@ bool LibDrawArc::WriteDescr( FILE* ExportFile )
m_Unit, m_Convert,
m_Width, fill_tab[m_Fill],
m_ArcStart.x, m_ArcStart.y, m_ArcEnd.x, m_ArcEnd.y );
return FALSE;
return true;
}
/***************************************************/
bool LibDrawCircle::WriteDescr( FILE* ExportFile )
bool LibDrawCircle::Save( FILE* ExportFile ) const
/***************************************************/
{
fprintf( ExportFile, "C %d %d %d %d %d %d %c\n",
......@@ -59,12 +59,12 @@ bool LibDrawCircle::WriteDescr( FILE* ExportFile )
m_Rayon,
m_Unit, m_Convert,
m_Width, fill_tab[m_Fill] );
return FALSE;
return true;
}
/************************************************/
bool LibDrawText::WriteDescr( FILE* ExportFile )
bool LibDrawText::Save( FILE* ExportFile ) const
/************************************************/
{
wxString text = m_Text;
......@@ -77,24 +77,24 @@ bool LibDrawText::WriteDescr( FILE* ExportFile )
m_Size.x, m_Type,
m_Unit, m_Convert,
CONV_TO_UTF8( text ) );
return FALSE;
return true;
}
/***************************************************/
bool LibDrawSquare::WriteDescr( FILE* ExportFile )
bool LibDrawSquare::Save( FILE* ExportFile ) const
/***************************************************/
{
fprintf( ExportFile, "S %d %d %d %d %d %d %d %c\n",
m_Pos.x, m_Pos.y, m_End.x, m_End.y,
m_Unit, m_Convert,
m_Width, fill_tab[m_Fill] );
return FALSE;
return true;
}
/************************************************/
bool LibDrawPin::WriteDescr( FILE* ExportFile )
bool LibDrawPin::Save( FILE* ExportFile ) const
/************************************************/
{
wxString StringPinNum;
......@@ -145,12 +145,12 @@ bool LibDrawPin::WriteDescr( FILE* ExportFile )
fprintf( ExportFile, "V" );
fprintf( ExportFile, "\n" );
return FALSE;
return true;
}
/****************************************************/
bool LibDrawPolyline::WriteDescr( FILE* ExportFile )
bool LibDrawPolyline::Save( FILE* ExportFile ) const
/****************************************************/
{
int ii, * ptpoly;
......@@ -167,12 +167,22 @@ bool LibDrawPolyline::WriteDescr( FILE* ExportFile )
}
fprintf( ExportFile, " %c\n", fill_tab[m_Fill] );
return FALSE;
return true;
}
/****************************************************/
bool LibDrawSegment::Save( FILE* ExportFile ) const
/****************************************************/
{
fprintf( ExportFile, "L %d %d %d",
m_Unit, m_Convert,
m_Width );
return true;
}
/**************************************************/
bool LibDrawField::WriteDescr( FILE* ExportFile )
bool LibDrawField::Save( FILE* ExportFile ) const
/**************************************************/
{
int hjustify, vjustify;
......@@ -203,7 +213,7 @@ bool LibDrawField::WriteDescr( FILE* ExportFile )
fprintf( ExportFile, " \"%s\"", CONV_TO_UTF8( m_Name ) );
fprintf( ExportFile, "\n" );
return FALSE;
return true;
}
......@@ -341,10 +351,9 @@ EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame, EDA_LibComponentStr
}
/********************************************************/
int WriteOneLibEntry( wxWindow* frame, FILE* ExportFile,
EDA_LibComponentStruct* LibEntry )
/********************************************************/
/*************************************************************************/
int WriteOneLibEntry( FILE* ExportFile, EDA_LibComponentStruct* LibEntry )
/*************************************************************************/
/* Routine d'ecriture du composant pointe par LibEntry
* dans le fichier ExportFile( qui doit etre deja ouvert)
......@@ -384,15 +393,15 @@ int WriteOneLibEntry( wxWindow* frame, FILE* ExportFile,
WriteLibEntryDateAndTime( ExportFile, LibEntry );
/* Position / orientation / visibilite des champs */
LibEntry->m_Prefix.WriteDescr( ExportFile );
LibEntry->m_Name.WriteDescr( ExportFile );
LibEntry->m_Prefix.Save( ExportFile );
LibEntry->m_Name.Save( ExportFile );
for( Field = LibEntry->Fields; Field!= NULL;
Field = (LibDrawField*) Field->Pnext )
{
if( Field->m_Text.IsEmpty() && Field->m_Name.IsEmpty() )
continue;
Field->WriteDescr( ExportFile );
Field->Save( ExportFile );
}
/* Sauvegarde de la ligne "ALIAS" */
......@@ -429,48 +438,7 @@ int WriteOneLibEntry( wxWindow* frame, FILE* ExportFile,
DrawEntry = LibEntry->m_Drawings;
while( DrawEntry )
{
switch( DrawEntry->Type() )
{
case COMPONENT_ARC_DRAW_TYPE:
#define DRAWSTRUCT ( (LibDrawArc*) DrawEntry )
DRAWSTRUCT->WriteDescr( ExportFile );
break;
case COMPONENT_CIRCLE_DRAW_TYPE:
#undef DRAWSTRUCT
#define DRAWSTRUCT ( (LibDrawCircle*) DrawEntry )
DRAWSTRUCT->WriteDescr( ExportFile );
break;
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
#undef DRAWSTRUCT
#define DRAWSTRUCT ( (LibDrawText*) DrawEntry )
DRAWSTRUCT->WriteDescr( ExportFile );
break;
case COMPONENT_RECT_DRAW_TYPE:
#undef DRAWSTRUCT
#define DRAWSTRUCT ( (LibDrawSquare*) DrawEntry )
DRAWSTRUCT->WriteDescr( ExportFile );
break;
case COMPONENT_PIN_DRAW_TYPE:
#undef DRAWSTRUCT
#define DRAWSTRUCT ( (LibDrawPin*) DrawEntry )
DRAWSTRUCT->WriteDescr( ExportFile );
break;
case COMPONENT_POLYLINE_DRAW_TYPE:
#undef DRAWSTRUCT
#define DRAWSTRUCT ( (LibDrawPolyline*) DrawEntry )
DRAWSTRUCT->WriteDescr( ExportFile );
break;
default:
DisplayError( frame, wxT( "Save Lib: Unknown Draw Type" ) );
break;
}
DrawEntry->Save( ExportFile );
DrawEntry = DrawEntry->Next();
}
fprintf( ExportFile, "ENDDRAW\n" );
......@@ -517,104 +485,97 @@ int WriteOneDocLibEntry( FILE* ExportFile, EDA_LibComponentStruct* LibEntry )
/*********************************************************************************/
int SaveOneLibrary( wxWindow* frame, const wxString& FullFileName, LibraryStruct* Library )
bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
/*********************************************************************************/
/* Sauvegarde en fichier la librairie pointee par Library, sous le nom
* FullFileName.
* 2 fichiers sont crees
* - La librarie
* - le fichier de documentation
*
* une sauvegarde .bak de l'ancien fichier librairie est cree
* une sauvegarde .bck de l'ancien fichier documentation est cree
*
* return:
* 0 si OK
* 1 si erreur
/**
* Function SaveLibrary
* writes the data structures for this object out to 2 file
* the library in "*.lib" format.
* the doc file in "*.dcm" format.
* creates a backup file for each file (.bak and .bck)
* @param aFullFileName The full lib filename.
* @return bool - true if success writing else false.
*/
{
FILE* SaveFile, * SaveDocFile;
FILE* libfile, *docfile;
EDA_LibComponentStruct* LibEntry;
char Line[1024];
int err = 1;
wxString Name, DocName, BakName, msg;
wxString libname, docname, backupname, msg;
if( Library == NULL )
return err;
libname = FullFileName;
Name = FullFileName;
/* L'ancien fichier lib est renomme en .bak */
if( wxFileExists( Name ) )
/* the old .lib file is renamed .bak */
if( wxFileExists( libname ) )
{
BakName = Name; ChangeFileNameExt( BakName, wxT( ".bak" ) );
wxRemoveFile( BakName );
if( !wxRenameFile( Name, BakName ) )
backupname = libname; ChangeFileNameExt( backupname, wxT( ".bak" ) );
wxRemoveFile( backupname );
if( !wxRenameFile( libname, backupname ) )
{
msg = wxT( "Failed to rename old lib file " ) + BakName;
DisplayError( frame, msg, 20 );
msg = wxT( "Failed to rename old lib file " ) + backupname;
DisplayError( NULL, msg, 20 );
}
}
DocName = Name; ChangeFileNameExt( DocName, DOC_EXT );
docname = FullFileName; ChangeFileNameExt( docname, DOC_EXT );
/* L'ancien fichier doc lib est renomme en .bck */
if( wxFileExists( DocName ) )
if( wxFileExists( docname ) )
{
BakName = DocName; ChangeFileNameExt( BakName, wxT( ".bck" ) );
wxRemoveFile( BakName );
if( !wxRenameFile( DocName, BakName ) )
backupname = docname; ChangeFileNameExt( backupname, wxT( ".bck" ) );
wxRemoveFile( backupname );
if( !wxRenameFile( docname, backupname ) )
{
msg = wxT( "Failed to save old doc lib file " ) + BakName;
DisplayError( frame, msg, 20 );
msg = wxT( "Failed to save old doc lib file " ) + backupname;
DisplayError( NULL, msg, 20 );
}
}
SaveFile = wxFopen( Name, wxT( "wt" ) );
if( SaveFile == NULL )
{
msg = wxT( "Failed to create Lib File " ) + Name;
DisplayError( frame, msg, 20 );
return err;
libfile = wxFopen( libname, wxT( "wt" ) );
if( libfile == NULL )
{
msg = wxT( "Failed to create Lib File " ) + libname;
DisplayError( NULL, msg, 20 );
return false;
}
SaveDocFile = wxFopen( DocName, wxT( "wt" ) );
if( SaveDocFile == NULL )
docfile = wxFopen( docname, wxT( "wt" ) );
if( docfile == NULL )
{
msg = wxT( "Failed to create DocLib File " ) + DocName;
DisplayError( frame, msg, 20 );
return err;
msg = wxT( "Failed to create DocLib File " ) + docname;
DisplayError( NULL, msg, 20 );
}
Library->m_Modified = 0;
m_Modified = 0;
/* Creation de l'entete de la librairie */
Library->m_TimeStamp = GetTimeStamp();
Library->WriteHeader( SaveFile );
fprintf( SaveDocFile, "%s Date: %s\n", DOCFILE_IDENT,
DateAndTime( Line ) );
m_TimeStamp = GetTimeStamp();
WriteHeader( libfile );
/* Sauvegarde des composant: */
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Library->m_Entries, FALSE );
LibEntry = (EDA_LibComponentStruct*) PQFirst( &m_Entries, FALSE );
char Line[256];
fprintf( docfile, "%s Date: %s\n", DOCFILE_IDENT,
DateAndTime( Line ) );
bool success = true;
while( LibEntry )
{
err = WriteOneLibEntry( frame, SaveFile, LibEntry );
err = WriteOneDocLibEntry( SaveDocFile, LibEntry );
if ( WriteOneLibEntry( libfile, LibEntry ) != 0 )
success = false;
if ( docfile )
if ( WriteOneDocLibEntry( docfile, LibEntry ) != 0 )
success = false;
LibEntry = (EDA_LibComponentStruct*)
PQNext( Library->m_Entries, LibEntry, NULL );
PQNext( m_Entries, LibEntry, NULL );
}
fprintf( SaveFile, "#\n#End Library\n" );
fprintf( SaveDocFile, "#\n#End Doc Library\n" );
fclose( SaveFile );
fclose( SaveDocFile );
return err;
fprintf( libfile, "#\n#End Library\n" );
if ( docfile )
fprintf( docfile, "#\n#End Doc Library\n" );
fclose( libfile );
fclose( docfile );
return success;
}
......
......@@ -137,7 +137,6 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
{
EDA_LibComponentStruct* LibEntry = CurrentLibEntry;
int Unit = CurrentUnit, convert = CurrentConvert;
int SymbUnit, SymbConvert;
LibEDA_BaseStruct* DrawEntry;
wxString FullFileName, mask;
wxString msg;
......@@ -196,8 +195,8 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
1, 0 /* unused */, 'N' );
/* Position / orientation / visibilite des champs */
LibEntry->m_Prefix.WriteDescr( ExportFile );
LibEntry->m_Name.WriteDescr( ExportFile );
LibEntry->m_Prefix.Save( ExportFile );
LibEntry->m_Name.Save( ExportFile );
DrawEntry = LibEntry->m_Drawings;
if( DrawEntry )
......@@ -211,55 +210,7 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
if( convert && DrawEntry->m_Convert && (DrawEntry->m_Convert != convert) )
continue;
/* .Unit , . Convert est laisse a 0 ou mis a 1 */
SymbUnit = DrawEntry->m_Unit; if( SymbUnit > 1 )
SymbUnit = 1;
SymbConvert = DrawEntry->m_Convert;
if( SymbConvert > 1 )
SymbConvert = 1;
switch( DrawEntry->Type() )
{
case COMPONENT_ARC_DRAW_TYPE:
#define DRAWSTRUCT ( (LibDrawArc*) DrawEntry )
DRAWSTRUCT->WriteDescr( ExportFile );
break;
case COMPONENT_CIRCLE_DRAW_TYPE:
#undef DRAWSTRUCT
#define DRAWSTRUCT ( (LibDrawCircle*) DrawEntry )
DRAWSTRUCT->WriteDescr( ExportFile );
break;
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
#undef DRAWSTRUCT
#define DRAWSTRUCT ( (LibDrawText*) DrawEntry )
DRAWSTRUCT->WriteDescr( ExportFile );
break;
case COMPONENT_RECT_DRAW_TYPE:
#undef DRAWSTRUCT
#define DRAWSTRUCT ( (LibDrawSquare*) DrawEntry )
DRAWSTRUCT->WriteDescr( ExportFile );
break;
case COMPONENT_PIN_DRAW_TYPE:
#undef DRAWSTRUCT
#define DRAWSTRUCT ( (LibDrawPin*) DrawEntry )
if( DRAWSTRUCT->m_Attributs & PINNOTDRAW )
break;
DRAWSTRUCT->WriteDescr( ExportFile );
break;
case COMPONENT_POLYLINE_DRAW_TYPE:
#undef DRAWSTRUCT
#define DRAWSTRUCT ( (LibDrawPolyline*) DrawEntry )
DRAWSTRUCT->WriteDescr( ExportFile );
break;
default:
;
}
DrawEntry->Save( ExportFile );
}
fprintf( ExportFile, "ENDDRAW\n" );
}
......
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