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,
......
......@@ -97,14 +97,9 @@ const wxChar * Text;
{
continue;
}
if ( ii == 0 )
if ( (ii == 0) || ( ListEntry[ii-1] != ListEntry[ii] ) )
{
WriteOneLibEntry(frame, ArchiveFile, ListEntry[ii]);
if( DocFile ) WriteOneDocLibEntry(DocFile, ListEntry[ii]);
}
else if ( ListEntry[ii-1] != ListEntry[ii] )
{
WriteOneLibEntry(frame, ArchiveFile, ListEntry[ii]);
WriteOneLibEntry(ArchiveFile, ListEntry[ii]);
if( DocFile ) WriteOneDocLibEntry(DocFile, ListEntry[ii]);
}
}
......
......@@ -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 */
/***************/
......
This diff is collapsed.
......@@ -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