Commit 34909473 authored by charras's avatar charras

eeschema: code cleaning

parent bf688ea1
......@@ -87,14 +87,12 @@ public:
}
/**
* 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).
* Function SaveDoc
* writes the doc info out to a FILE in "*.dcm" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool SaveLibrary( const wxString& FullFileName );
bool SaveDoc( FILE* aFile );
};
......@@ -131,6 +129,14 @@ public:
~EDA_LibComponentStruct();
void SortDrawItems();
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.lib" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile );
};
......
......@@ -18,8 +18,17 @@ void LibDrawPin::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffs
int aDrawMode, void* aData, int aTransformMatrix[2][2] )
/**********************************************************************************************/
{
if( ( m_Attributs & PINNOTDRAW ) && !g_ShowAllPins )
return;
// Invisibles pins are only drawn on request.
// But in libedit they are drawn in g_InvisibleItemColor because we must see them
if( ( m_Attributs & PINNOTDRAW ) )
{
if ( g_EDA_Appl->m_LibeditFrame && g_EDA_Appl->m_LibeditFrame->IsActive() )
aColor = g_InvisibleItemColor;
else if( !g_ShowAllPins )
return;
}
EDA_LibComponentStruct* Entry = ( (DrawPinPrms*) aData )->m_Entry;
bool DrawPinText = ( (DrawPinPrms*) aData )->m_DrawPinText;
......
......@@ -13,11 +13,7 @@
#include "trigo.h"
#include "protos.h"
#define UNVISIBLE_COLOR DARKGRAY
//#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
//#define DRAW_ARC_WITH_ANGLE // Used to select function to draw arcs
/* Local functions */
......@@ -129,7 +125,7 @@ void DrawLibEntry( WinEDA_DrawPanel* panel, wxDC* DC,
if( Color >= 0 )
color = Color;
else
color = UNVISIBLE_COLOR;
color = g_InvisibleItemColor;
}
else color = Color;
......@@ -146,7 +142,7 @@ void DrawLibEntry( WinEDA_DrawPanel* panel, wxDC* DC,
if( Color >= 0 )
color = Color;
else
color = UNVISIBLE_COLOR;
color = g_InvisibleItemColor;
}
else color = Color;
......@@ -164,7 +160,7 @@ void DrawLibEntry( WinEDA_DrawPanel* panel, wxDC* DC,
if( Color >= 0 )
color = Color;
else
color = UNVISIBLE_COLOR;
color = g_InvisibleItemColor;
}
else color = Color;
Field->Draw( panel, DC, aOffset, color, DrawMode, NULL, TransMat );
......
This diff is collapsed.
......@@ -60,7 +60,7 @@ const wxChar * Text;
{
Text = List[ii].m_Comp->m_ChipName.GetData();
Entry = FindLibPart(Text, wxEmptyString, FIND_ROOT);
ListEntry[ii] = Entry; // = NULL si Composant non trouv� en librairie
ListEntry[ii] = Entry; // = NULL component not found
}
MyFree(List);
......@@ -90,21 +90,22 @@ const wxChar * Text;
if( DocFile)
fprintf(DocFile,"%s %s\n", DOCFILE_IDENT, DateAndTime(Line));
/* Generation des elements */
/* Save components in file */
for ( ii = 0; ii < NbItems; ii++ )
{
if ( ListEntry[ii] == NULL ) // Composant non trouv� en librairie
if ( ListEntry[ii] == NULL ) // Not found in lib
{
continue;
}
if ( (ii == 0) || ( ListEntry[ii-1] != ListEntry[ii] ) )
{
WriteOneLibEntry(ArchiveFile, ListEntry[ii]);
if( DocFile ) WriteOneDocLibEntry(DocFile, ListEntry[ii]);
if ( ListEntry[ii]->Type == ROOT) // Must be always true, but just in case
ListEntry[ii]->Save(ArchiveFile);
if( DocFile )
ListEntry[ii]->SaveDoc(DocFile);
}
}
/* Generation fin de fichier */
fprintf(ArchiveFile,"#\n#EndLibrary\n");
fclose(ArchiveFile);
......
......@@ -85,7 +85,7 @@ wxString msg;
wxString CmpName;
EDA_LibComponentStruct *LibEntry = NULL;
if( ScreenLib->IsModify() )
if( g_ScreenLib->IsModify() )
{
if( ! IsOK(this, _("Current Part not saved.\nContinue?") ) ) return FALSE;
}
......@@ -96,7 +96,7 @@ EDA_LibComponentStruct *LibEntry = NULL;
i = GetNameOfPartToLoad(this, CurrentLib, CmpName);
if( i == 0) return FALSE;
ScreenLib->ClrModify();
g_ScreenLib->ClrModify();
CurrentDrawItem = NULL;
// Effacement ancien composant affich�
if( CurrentLibEntry)
......@@ -166,7 +166,7 @@ const wxChar * CmpName, *RootName = NULL;
BuildAliasData(Library, CurrentLibEntry);
ScreenLib->ClrModify();
g_ScreenLib->ClrModify();
g_AsDeMorgan = 0;
if( LookForConvertPart(CurrentLibEntry) > 1 ) g_AsDeMorgan = 1;
......@@ -564,7 +564,7 @@ bool NewCmp = TRUE;
}
CurrentLib->m_Modified = 1;
ScreenLib->ClrModify();
g_ScreenLib->ClrModify();
PQCompFunc((PQCompFuncType) LibraryEntryCompare);
......
......@@ -71,7 +71,7 @@ WinEDA_LibeditFrame::WinEDA_LibeditFrame( wxWindow* father,
// Give an icon
SetIcon( wxIcon( libedit_xpm ) );
SetBaseScreen( ScreenLib );
SetBaseScreen( g_ScreenLib );
GetSettings();
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
if( DrawPanel )
......
......@@ -59,10 +59,6 @@ void DrawLibraryDrawStruct(WinEDA_DrawPanel * aPanel, wxDC * aDC,
bool MapAngles(int *Angle1, int *Angle2, int TransMat[2][2]);
/**************/
/* EELIBS_DRAW_COMPONENTS.CPP */
/**************/
EDA_LibComponentStruct * Read_Component_Definition(WinEDA_DrawFrame * frame, char * Line,
FILE *f, int *LineNum);
/* Routine to Read a DEF/ENDDEF part entry from given open file. */
......@@ -229,22 +225,12 @@ LibEDA_BaseStruct * CopyDrawEntryStruct( wxWindow * frame, LibEDA_BaseStruct * D
Retourne:
Pointeur sur la structure creee (ou NULL si impossible) */
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 */
EDA_LibComponentStruct * CopyLibEntryStruct (wxWindow * frame, EDA_LibComponentStruct * OldEntry);
/* Routine de copie d'une partlib
Parametres d'entree: pointeur sur la structure de depart
Parametres de sortie: pointeur sur la structure creee */
int WriteOneDocLibEntry(FILE * ExportFile, EDA_LibComponentStruct * LibEntry);
/* Routine d'ecriture de la doc du composant pointe par LibEntry
dans le fichier ExportFile( qui doit etre deja ouvert)
return: 0 si Ok
1 si err write */
/***************/
/* SYMBEDIT.CPP */
......@@ -254,11 +240,6 @@ void SuppressDuplicateDrawItem(EDA_LibComponentStruct * LibEntry);
frequente lorsque l'on charge des symboles predessines plusieurs fois
pour definir un composant */
/***************/
/* SYMBTEXT.CPP */
/***************/
/**************/
/* NETLIST.CPP */
/**************/
......
......@@ -2,7 +2,7 @@
/* EESchema - eesavlib.cpp */
/****************************/
/* Write Routines to save schematic libraries and library components (::Save() members)
/* Functions to save schematic libraries and library components (::Save() members)
*/
#include "fctsys.h"
......@@ -350,137 +350,132 @@ EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame, EDA_LibComponentStr
return NewStruct;
}
/*************************************************************************/
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: 0 si Ok
* -1 si err write
* 1 si composant non ecrit ( type ALIAS )
/************************************************/
bool EDA_LibComponentStruct::Save( FILE* aFile )
/***********************************************/
/**
* 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.
*/
#define UNUSED 0
{
LibEDA_BaseStruct* DrawEntry;
LibDrawField* Field;
if( LibEntry->Type != ROOT )
return 1;
if( Type != ROOT ) // should not happen, but just in case
return false;
/* Creation du commentaire donnant le nom du composant */
fprintf( ExportFile, "#\n# %s\n#\n", CONV_TO_UTF8( LibEntry->m_Name.m_Text ) );
/* First line: it s a comment (component name for readers) */
fprintf( aFile, "#\n# %s\n#\n", CONV_TO_UTF8( m_Name.m_Text ) );
/* Generation des lignes utiles */
fprintf( ExportFile, "DEF" );
if( (LibEntry->m_Name.m_Attributs & TEXT_NO_VISIBLE) == 0 )
fprintf( ExportFile, " %s", CONV_TO_UTF8( LibEntry->m_Name.m_Text ) );
/* Save data */
fprintf( aFile, "DEF" );
if( (m_Name.m_Attributs & TEXT_NO_VISIBLE) == 0 )
fprintf( aFile, " %s", CONV_TO_UTF8( m_Name.m_Text ) );
else
fprintf( ExportFile, " ~%s", CONV_TO_UTF8( LibEntry->m_Name.m_Text ) );
fprintf( aFile, " ~%s", CONV_TO_UTF8( m_Name.m_Text ) );
if( !LibEntry->m_Prefix.m_Text.IsEmpty() )
fprintf( ExportFile, " %s", CONV_TO_UTF8( LibEntry->m_Prefix.m_Text ) );
if( !m_Prefix.m_Text.IsEmpty() )
fprintf( aFile, " %s", CONV_TO_UTF8( m_Prefix.m_Text ) );
else
fprintf( ExportFile, " ~" );
fprintf( ExportFile, " %d %d %c %c %d %c %c\n",
UNUSED, LibEntry->m_TextInside,
LibEntry->m_DrawPinNum ? 'Y' : 'N',
LibEntry->m_DrawPinName ? 'Y' : 'N',
LibEntry->m_UnitCount, LibEntry->m_UnitSelectionLocked ? 'L' : 'F',
LibEntry->m_Options == ENTRY_POWER ? 'P' : 'N' );
fprintf( aFile, " ~" );
fprintf( aFile, " %d %d %c %c %d %c %c\n",
UNUSED, m_TextInside,
m_DrawPinNum ? 'Y' : 'N',
m_DrawPinName ? 'Y' : 'N',
m_UnitCount, m_UnitSelectionLocked ? 'L' : 'F',
m_Options == ENTRY_POWER ? 'P' : 'N' );
WriteLibEntryDateAndTime( ExportFile, LibEntry );
WriteLibEntryDateAndTime( aFile, this );
/* Position / orientation / visibilite des champs */
LibEntry->m_Prefix.Save( ExportFile );
LibEntry->m_Name.Save( ExportFile );
/* Save fields */
m_Prefix.Save( aFile );
m_Name.Save( aFile );
for( Field = LibEntry->Fields; Field!= NULL;
for( Field = Fields; Field!= NULL;
Field = (LibDrawField*) Field->Pnext )
{
if( Field->m_Text.IsEmpty() && Field->m_Name.IsEmpty() )
continue;
Field->Save( ExportFile );
Field->Save( aFile );
}
/* Sauvegarde de la ligne "ALIAS" */
if( LibEntry->m_AliasList.GetCount() != 0 )
/* Save the alias list: a line starting by "ALIAS" */
if( m_AliasList.GetCount() != 0 )
{
fprintf( ExportFile, "ALIAS" );
fprintf( aFile, "ALIAS" );
unsigned ii;
for( ii = 0; ii < LibEntry->m_AliasList.GetCount(); ii++ )
fprintf( ExportFile, " %s", CONV_TO_UTF8( LibEntry->m_AliasList[ii] ) );
for( ii = 0; ii < m_AliasList.GetCount(); ii++ )
fprintf( aFile, " %s", CONV_TO_UTF8( m_AliasList[ii] ) );
fprintf( ExportFile, "\n" );
fprintf( aFile, "\n" );
}
/* Write the footprint filter list */
if( LibEntry->m_FootprintList.GetCount() != 0 )
if( m_FootprintList.GetCount() != 0 )
{
fprintf( ExportFile, "$FPLIST\n" );
fprintf( aFile, "$FPLIST\n" );
unsigned ii;
for( ii = 0; ii < LibEntry->m_FootprintList.GetCount(); ii++ )
fprintf( ExportFile, " %s\n", CONV_TO_UTF8( LibEntry->m_FootprintList[ii] ) );
for( ii = 0; ii < m_FootprintList.GetCount(); ii++ )
fprintf( aFile, " %s\n", CONV_TO_UTF8( m_FootprintList[ii] ) );
fprintf( ExportFile, "$ENDFPLIST\n" );
fprintf( aFile, "$ENDFPLIST\n" );
}
/* Sauvegarde des elements de trace */
DrawEntry = LibEntry->m_Drawings;
if( LibEntry->m_Drawings )
/* Save graphics items (including pins) */
if( m_Drawings )
{
/* we sort the draw items, in order to have an edition more easy,
* when a file editing "by hand" is made */
LibEntry->SortDrawItems();
SortDrawItems();
fprintf( ExportFile, "DRAW\n" );
DrawEntry = LibEntry->m_Drawings;
fprintf( aFile, "DRAW\n" );
DrawEntry = m_Drawings;
while( DrawEntry )
{
DrawEntry->Save( ExportFile );
DrawEntry->Save( aFile );
DrawEntry = DrawEntry->Next();
}
fprintf( ExportFile, "ENDDRAW\n" );
fprintf( aFile, "ENDDRAW\n" );
}
fprintf( ExportFile, "ENDDEF\n" );
fprintf( aFile, "ENDDEF\n" );
return 0;
return true;
}
/*************************************************************************/
int WriteOneDocLibEntry( FILE* ExportFile, EDA_LibComponentStruct* LibEntry )
/*************************************************************************/
/* Routine d'ecriture de la doc du composant pointe par LibEntry
* dans le fichier ExportFile( qui doit etre deja ouvert)
* return: 0 si Ok
* 1 si err write
* Cependant, si i tous les Pointeurs sur textes sont nulls ( pas de Doc )
* rien ne sera ecrit.
/***************************************/
bool LibCmpEntry::SaveDoc( FILE* aFile )
/***************************************/
/**
* Function SaveDoc
* writes the doc info out to a FILE in "*.dcm" format.
* Only non empty fields are written.
* If all fielsd are empty, does not write anything
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
{
if( ( LibEntry->m_Doc.IsEmpty() )
&& ( LibEntry->m_KeyWord.IsEmpty() )
&& ( LibEntry->m_DocFile.IsEmpty() ) )
return 0;
if( m_Doc.IsEmpty() && m_KeyWord.IsEmpty() && m_DocFile.IsEmpty() )
return true;
/* Generation des lignes utiles */
fprintf( ExportFile, "#\n$CMP %s\n", CONV_TO_UTF8( LibEntry->m_Name.m_Text ) );
fprintf( aFile, "#\n$CMP %s\n", CONV_TO_UTF8( m_Name.m_Text ) );
if( !LibEntry->m_Doc.IsEmpty() )
fprintf( ExportFile, "D %s\n", CONV_TO_UTF8( LibEntry->m_Doc ) );
if( ! m_Doc.IsEmpty() )
fprintf( aFile, "D %s\n", CONV_TO_UTF8( m_Doc ) );
if( !LibEntry->m_KeyWord.IsEmpty() )
fprintf( ExportFile, "K %s\n", CONV_TO_UTF8( LibEntry->m_KeyWord ) );
if( ! m_KeyWord.IsEmpty() )
fprintf( aFile, "K %s\n", CONV_TO_UTF8( m_KeyWord ) );
if( !LibEntry->m_DocFile.IsEmpty() )
fprintf( ExportFile, "F %s\n", CONV_TO_UTF8( LibEntry->m_DocFile ) );
if( ! m_DocFile.IsEmpty() )
fprintf( aFile, "F %s\n", CONV_TO_UTF8( m_DocFile ) );
fprintf( ExportFile, "$ENDCMP\n" );
return 0;
fprintf( aFile, "$ENDCMP\n" );
return true;
}
......@@ -560,11 +555,16 @@ bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
bool success = true;
while( LibEntry )
{
if ( WriteOneLibEntry( libfile, LibEntry ) != 0 )
success = false;
if ( LibEntry->Type == ROOT )
{
if ( ! LibEntry->Save( libfile ) )
success = false;
}
if ( docfile )
if ( WriteOneDocLibEntry( docfile, LibEntry ) != 0 )
{
if ( ! LibEntry->SaveDoc( docfile ) )
success = false;
}
LibEntry = (EDA_LibComponentStruct*)
PQNext( m_Entries, LibEntry, NULL );
......
......@@ -275,10 +275,10 @@ void WinEDA_SchematicFrame::CreateScreens()
m_CurrentSheet->Clear();
m_CurrentSheet->Push( g_RootSheet );
if( ScreenLib == NULL )
ScreenLib = new SCH_SCREEN( LIBEDITOR_FRAME );
ScreenLib->SetZoom( 4 );
ScreenLib->m_UndoRedoCountMax = 10;
if( g_ScreenLib == NULL )
g_ScreenLib = new SCH_SCREEN( LIBEDITOR_FRAME );
g_ScreenLib->SetZoom( 4 );
g_ScreenLib->m_UndoRedoCountMax = 10;
}
......@@ -356,9 +356,7 @@ void WinEDA_SchematicFrame::OnCloseWindow( wxCloseEvent& Event )
/*****************************************************************************
*
* Enable or disable some tools according to current conditions
*
*****************************************************************************/
void WinEDA_SchematicFrame::SetToolbars()
{
......@@ -451,21 +449,27 @@ int WinEDA_SchematicFrame::BestZoom()
return bestzoom;
}
/**************************************************************/
void WinEDA_SchematicFrame::OnAnnotate( wxCommandEvent& event )
/**************************************************************/
{
WinEDA_AnnotateFrame* dlg = new WinEDA_AnnotateFrame( this );
dlg->ShowModal();
dlg->Destroy();
}
/*********************************************************/
void WinEDA_SchematicFrame::OnErc( wxCommandEvent& event )
/*********************************************************/
{
WinEDA_ErcFrame* dlg = new WinEDA_ErcFrame( this );
dlg->ShowModal();
dlg->Destroy();
}
/*******************************************************************/
void WinEDA_SchematicFrame::OnCreateNetlist( wxCommandEvent& event )
/*******************************************************************/
{
int i;
......@@ -481,14 +485,18 @@ void WinEDA_SchematicFrame::OnCreateNetlist( wxCommandEvent& event )
// If a plugin is removed or added, rebuild and reopen the new dialog
}
/**********************************************************************/
void WinEDA_SchematicFrame::OnCreateBillOfMaterials( wxCommandEvent & )
/**********************************************************************/
{
WinEDA_Build_BOM_Frame* dlg = new WinEDA_Build_BOM_Frame( this );
dlg->ShowModal();
dlg->Destroy();
}
/*******************************************************************/
void WinEDA_SchematicFrame::OnFindItems( wxCommandEvent& event )
/*******************************************************************/
{
this->DrawPanel->m_IgnoreMouseEvents = TRUE;
WinEDA_FindFrame* dlg = new WinEDA_FindFrame( this );
......@@ -497,7 +505,9 @@ void WinEDA_SchematicFrame::OnFindItems( wxCommandEvent& event )
this->DrawPanel->m_IgnoreMouseEvents = FALSE;
}
/***************************************************************/
void WinEDA_SchematicFrame::OnLoadFile( wxCommandEvent& event )
/***************************************************************/
{
int i = event.GetId() - ID_LOAD_FILE_1;
......@@ -505,23 +515,31 @@ void WinEDA_SchematicFrame::OnLoadFile( wxCommandEvent& event )
SetToolbars();
}
/*******************************************************************/
void WinEDA_SchematicFrame::OnLoadStuffFile( wxCommandEvent& event )
/*******************************************************************/
{
ReadInputStuffFile( );
DrawPanel->Refresh();
}
/****************************************************************/
void WinEDA_SchematicFrame::OnNewProject( wxCommandEvent& event )
/****************************************************************/
{
LoadOneEEProject( wxEmptyString, true );
}
/*****************************************************************/
void WinEDA_SchematicFrame::OnLoadProject( wxCommandEvent& event )
/*****************************************************************/
{
LoadOneEEProject( wxEmptyString, false );
}
/****************************************************************/
void WinEDA_SchematicFrame::OnOpenPcbnew( wxCommandEvent& event )
/****************************************************************/
{
wxString Line = g_RootSheet->m_AssociatedScreen->m_FileName;
......@@ -535,7 +553,9 @@ void WinEDA_SchematicFrame::OnOpenPcbnew( wxCommandEvent& event )
ExecuteFile( this, PCBNEW_EXE );
}
/***************************************************************/
void WinEDA_SchematicFrame::OnOpenCvpcb( wxCommandEvent& event )
/***************************************************************/
{
wxString Line = g_RootSheet->m_AssociatedScreen->m_FileName;
......@@ -549,7 +569,9 @@ void WinEDA_SchematicFrame::OnOpenCvpcb( wxCommandEvent& event )
ExecuteFile( this, CVPCB_EXE );
}
/*************************************************************************/
void WinEDA_SchematicFrame::OnOpenLibraryViewer( wxCommandEvent& event )
/*************************************************************************/
{
if( m_Parent->m_ViewlibFrame )
{
......@@ -564,7 +586,9 @@ void WinEDA_SchematicFrame::OnOpenLibraryViewer( wxCommandEvent& event )
}
}
/*************************************************************************/
void WinEDA_SchematicFrame::OnOpenLibraryEditor( wxCommandEvent& event )
/*************************************************************************/
{
if( m_Parent->m_LibeditFrame )
{
......@@ -578,7 +602,7 @@ void WinEDA_SchematicFrame::OnOpenLibraryEditor( wxCommandEvent& event )
wxT( "Library Editor" ),
wxPoint( -1, -1 ),
wxSize( 600, 400 ) );
ActiveScreen = ScreenLib;
ActiveScreen = g_ScreenLib;
m_Parent->m_LibeditFrame->AdjustScrollBars();
}
}
......
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