Commit 6c01c554 authored by charras's avatar charras

code cleanup, better comments and comments translation

parent 589873f3
/****************************************************************************/
/* string.cpp */
/* ROLE: fonctions complementaires de traitement de chaines de caracteres */
/****************************************************************************/
/*********************************************/
/* string.cpp */
/* some useful functions to handle strings */
/*********************************************/
#include "fctsys.h"
#include <time.h>
......@@ -13,9 +13,9 @@
int ReadDelimitedText( char* dest, char* source, int NbMaxChar )
/*********************************************************************/
/* read a double-qute delimited text in source and put in in dest,
/* read a double-quote delimited text from source and put it in in dest,
* read NbMaxChar bytes max
* return the byte count read in source
* return the char count read from source
*/
{
int ii, jj, flag = 0;
......
This diff is collapsed.
This diff is collapsed.
......@@ -371,9 +371,6 @@ int DrawSheetStruct::ComponentCount()
/*******************************************************************/
{
//count our own components, without the power components.
/* Routine retournant le nombre de composants dans le schema,
* powers non comprises */
int n = 0;
if( m_AssociatedScreen )
......@@ -678,7 +675,7 @@ DrawSheetPath::DrawSheetPath()
}
int DrawSheetPath::Cmp( DrawSheetPath& d )
int DrawSheetPath::Cmp( const DrawSheetPath& d ) const
{
if( m_numSheets > d.m_numSheets )
return 1;
......
......@@ -66,7 +66,7 @@ public:
*/
WX_DEFINE_ARRAY( DrawSheetStruct *, SheetGrowArray );
class DrawSheetStruct : public SCH_ITEM /* Gestion de la hierarchie */
class DrawSheetStruct : public SCH_ITEM
{
public:
wxString m_SheetName; /*this is equivalent to C101 for components:
......@@ -76,13 +76,13 @@ private:
* but need it here for loading after
* reading the sheet description from file. */
public:
int m_SheetNameSize; /* Size (height) of the text, used to draw the name */
int m_FileNameSize; /* Size (height) of the text, used to draw the name */
int m_SheetNameSize; /* Size (height) of the text, used to draw the sheet name */
int m_FileNameSize; /* Size (height) of the text, used to draw the file name */
wxPoint m_Pos;
wxSize m_Size; /* Position and Size of sheet symbol */
int m_Layer;
Hierarchical_PIN_Sheet_Struct* m_Label; /* Points de connection, linked list.*/
int m_NbLabel; /* Nombre de points de connexion */
int m_NbLabel; /* Pins sheet (corresponding to hierarchical labels) count */
SCH_SCREEN* m_AssociatedScreen; /* Associated Screen which handle the physical data
* In complex hierarchies we can have many DrawSheetStruct using the same data
*/
......@@ -149,7 +149,7 @@ public:
DrawSheetPath();
~DrawSheetPath() { };
void Clear() { m_numSheets = 0; }
int Cmp( DrawSheetPath& d );
int Cmp( const DrawSheetPath& d ) const;
DrawSheetStruct* Last();
SCH_SCREEN* LastScreen();
EDA_BaseStruct* LastDrawList();
......
......@@ -134,9 +134,9 @@ public:
bool aRunBrowser);
void GenereListeOfItems(const wxString & FullFileName, bool aIncludeSubComponents );
void CreateExportList(const wxString & FullFileName, bool aIncludeSubComponents);
int PrintComponentsListByRef( FILE * f, ListComponent * List, int NbItems,
int PrintComponentsListByRef( FILE * f, OBJ_CMP_TO_LIST * List, int NbItems,
bool CompactForm, bool aIncludeSubComponents );
int PrintComponentsListByVal( FILE *f, ListComponent * List, int NbItems,
int PrintComponentsListByVal( FILE *f, OBJ_CMP_TO_LIST * List, int NbItems,
bool aIncludeSubComponents);
void PrintFieldData(FILE * f, SCH_COMPONENT * DrawLibItem, bool CompactForm = FALSE);
void SavePreferences();
......
......@@ -319,7 +319,7 @@ void WinEDA_ErcFrame::TestErc( wxCommandEvent& event )
/* Reset du flag m_FlagOfConnection, utilise par la suite */
for( NetItemRef = g_TabObjNet; NetItemRef < Lim; NetItemRef++ )
NetItemRef->m_FlagOfConnection = (IsConnectType) 0;
NetItemRef->m_FlagOfConnection = UNCONNECTED;
NetNbItems = 0;
MinConn = NOC;
......@@ -692,7 +692,7 @@ static void TestOthersItems( WinEDA_DrawPanel* panel, wxDC* DC,
if( NetItemTst->m_FlagOfConnection == 0 )
{
Diagnose( panel, DC, NetItemRef, NetItemTst, 0, erc );
NetItemTst->m_FlagOfConnection = (IsConnectType) 1;
NetItemTst->m_FlagOfConnection = NOCONNECT;
}
}
}
......
/**************************************************************/
/* libarch.cc */
/* Module de generation du fichier d'archivage des composants */
/**************************************************************/
/**************************************************************/
/* libarch.cc */
/* Module de generation du fichier d'archivage des composants */
/**************************************************************/
#include <algorithm> // to use sort vector
#include <vector>
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "program.h"
......@@ -14,132 +15,102 @@
#include "protos.h"
/* Imported functions */
int BuildComponentsListFromSchematic( ListComponent* List );
/* Local functions*/
static int TriListEntry(EDA_LibComponentStruct **Objet1, EDA_LibComponentStruct **Objet2);
static bool TriListEntry( const EDA_LibComponentStruct* Objet1,
const EDA_LibComponentStruct* Objet2 );
/*******************************************************************/
bool LibArchive(wxWindow * frame, const wxString & ArchFullFileName)
bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName )
/*******************************************************************/
/*
Creation du fichier librairie contenant tous les composants utilis�s dans
le projet en cours
retourne TRUE si fichier cr��
*/
* Creates a library that contains all components used in the whole hierarchy
* return true if success
*/
{
wxString DocFileName, msg;
char Line[256];
FILE *ArchiveFile, *DocFile;
ListComponent * List;
EDA_LibComponentStruct ** ListEntry, *Entry;
int ii, NbItems;
const wxChar * Text;
/* Creation de la liste des elements */
NbItems = BuildComponentsListFromSchematic(NULL ); // Comptage des composants
if ( NbItems == 0 ) return FALSE;
List = (ListComponent *) MyZMalloc( NbItems * sizeof( ListComponent ) );
if (List == NULL ) return FALSE;
/* Calcul de la liste des composants */
BuildComponentsListFromSchematic(List);
/* Calcul de la liste des Entrees de librairie
et Remplacement des alias par les composants "Root" */
ListEntry = (EDA_LibComponentStruct ** )
MyZMalloc( NbItems * sizeof(EDA_LibComponentStruct *) );
if (ListEntry == NULL ) return FALSE;
for ( ii = 0; ii < NbItems; ii++ )
{
Text = List[ii].m_Comp->m_ChipName.GetData();
Entry = FindLibPart(Text, wxEmptyString, FIND_ROOT);
ListEntry[ii] = Entry; // = NULL component not found
}
MyFree(List);
qsort( ListEntry, NbItems, sizeof(EDA_LibComponentStruct *),
(int(*)(const void*, const void*))TriListEntry);
/* mise a jour extension fichier doc associe */
DocFileName = ArchFullFileName;
ChangeFileNameExt(DocFileName, wxT(".bck"));
if ((ArchiveFile = wxFopen(ArchFullFileName, wxT("wt"))) == NULL)
{
MyFree(ListEntry);
msg = _("Failed to create archive lib file ") + ArchFullFileName;
DisplayError(frame, msg);
return FALSE;
}
if ((DocFile = wxFopen(DocFileName, wxT("wt"))) == NULL)
{
msg = _("Failed to create doc lib file ") + DocFileName;
DisplayError(frame, msg);
}
fprintf(ArchiveFile,"%s %s\n#\n", LIBFILE_IDENT,DateAndTime(Line));
if( DocFile)
fprintf(DocFile,"%s %s\n", DOCFILE_IDENT, DateAndTime(Line));
/* Save components in file */
for ( ii = 0; ii < NbItems; ii++ )
{
if ( ListEntry[ii] == NULL ) // Not found in lib
{
continue;
wxString DocFileName, msg;
char Line[256];
FILE* ArchiveFile, * DocFile;
EDA_LibComponentStruct* Entry;
std::vector <EDA_LibComponentStruct*> ListEntry;
EDA_ScreenList s_list;
// examine all screens used and build the list of components found in lib
for( SCH_SCREEN* screen = s_list.GetFirst(); screen != NULL; screen = s_list.GetNext() )
{
for( SCH_ITEM* SchItem = screen->EEDrawList; SchItem; SchItem = SchItem->Next() )
{
if( SchItem->Type() != TYPE_SCH_COMPONENT )
continue;
SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) SchItem;
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
if( Entry ) // if NULL : component not found
ListEntry.push_back( Entry );
}
if ( (ii == 0) || ( ListEntry[ii-1] != 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);
}
}
fprintf(ArchiveFile,"#\n#EndLibrary\n");
fclose(ArchiveFile);
if( DocFile )
{
fprintf(DocFile,"#\n#End Doc Library\n");
fclose(DocFile);
}
MyFree(ListEntry);
return TRUE;
}
/***********************************************************/
static int TriListEntry(EDA_LibComponentStruct **Objet1,
EDA_LibComponentStruct **Objet2)
/***********************************************************/
/* Routine de comparaison pour le tri du Tableau par qsort()
Les composants sont tries par LibName
*/
{
int ii;
const wxString * Text1, *Text2;
}
sort( ListEntry.begin(), ListEntry.end(), TriListEntry );
/* calculate the file name for the associated doc file */
DocFileName = ArchFullFileName;
ChangeFileNameExt( DocFileName, DOC_EXT );
if( ( ArchiveFile = wxFopen( ArchFullFileName, wxT( "wt" ) ) ) == NULL )
{
msg = _( "Failed to create archive lib file " ) + ArchFullFileName;
DisplayError( frame, msg );
return FALSE;
}
if( ( DocFile = wxFopen( DocFileName, wxT( "wt" ) ) ) == NULL )
{
msg = _( "Failed to create doc lib file " ) + DocFileName;
DisplayError( frame, msg );
}
fprintf( ArchiveFile, "%s %s\n#\n", LIBFILE_IDENT, DateAndTime( Line ) );
if( DocFile )
fprintf( DocFile, "%s %s\n", DOCFILE_IDENT, DateAndTime( Line ) );
/* Save components in file */
for( unsigned ii = 0; ii < ListEntry.size(); ii++ )
{
if( (ii == 0) || ( ListEntry[ii - 1] != 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 );
}
}
if( (*Objet1 == NULL) && (*Objet2 == NULL ) ) return(0);
if( *Objet1 == NULL) return(-1);
if( *Objet2 == NULL) return(1);
fprintf( ArchiveFile, "#\n#EndLibrary\n" );
fclose( ArchiveFile );
Text1 = &(*Objet1)->m_Name.m_Text;
Text2 = &(*Objet2)->m_Name.m_Text;
if( DocFile )
{
fprintf( DocFile, "#\n#End Doc Library\n" );
fclose( DocFile );
}
ii = Text1->CmpNoCase(* Text2);
return(ii);
return TRUE;
}
/***********************************************************************************************/
bool TriListEntry( const EDA_LibComponentStruct* Objet1, const EDA_LibComponentStruct* Objet2 )
/***********************************************************************************************/
/* Compare function for sort()
* lib components are sorted by name
*/
{
int ii;
ii = Objet1->m_Name.m_Text.CmpNoCase( Objet2->m_Name.m_Text );
return ii < 0;
}
......@@ -539,7 +539,7 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with
EDA_BaseStruct* DrawList;
SCH_COMPONENT* Component;
int ii;
ListComponent* CmpList = NULL;
OBJ_CMP_TO_LIST* CmpList = NULL;
int CmpListCount = 0, CmpListSize = 1000;
DateAndTime( Buf );
......@@ -571,18 +571,18 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with
{
if( CmpList == NULL )
{
CmpList = (ListComponent*)
MyZMalloc( sizeof(ListComponent) * CmpListSize );
CmpList = (OBJ_CMP_TO_LIST*)
MyZMalloc( sizeof(OBJ_CMP_TO_LIST) * CmpListSize );
}
if( CmpListCount >= CmpListSize )
{
CmpListSize += 1000;
CmpList = (ListComponent*) realloc(
CmpList = (OBJ_CMP_TO_LIST*) realloc(
CmpList,
sizeof(ListComponent) * CmpListSize );
sizeof(OBJ_CMP_TO_LIST) * CmpListSize );
}
CmpList[CmpListCount].m_Comp = Component;
strcpy( CmpList[CmpListCount].m_Ref, Component->GetRef( sheet ).mb_str() );
CmpList[CmpListCount].m_RootCmp = Component;
strcpy( CmpList[CmpListCount].m_Reference, Component->GetRef( sheet ).mb_str() );
CmpListCount++;
}
}
......@@ -643,19 +643,19 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with
EDA_LibComponentStruct* Entry;
for( ii = 0; ii < CmpListCount; ii++ )
{
Component = CmpList[ii].m_Comp;
Component = CmpList[ii].m_RootCmp;
Entry = FindLibPart( Component->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
//Line.Printf(_("%s"), CmpList[ii].m_Ref);
//Line.Replace( wxT( " " ), wxT( "_" ) );
unsigned int i;
for( i = 0; i<sizeof(CmpList[ii].m_Ref) && CmpList[ii].m_Ref[i]; i++ )
for( i = 0; i<sizeof(CmpList[ii].m_Reference) && CmpList[ii].m_Reference[i]; i++ )
{
if( CmpList[ii].m_Ref[i] == ' ' )
CmpList[ii].m_Ref[i] = '_';
if( CmpList[ii].m_Reference[i] == ' ' )
CmpList[ii].m_Reference[i] = '_';
}
fprintf( f, "$component %s\n", CmpList[ii].m_Ref );
fprintf( f, "$component %s\n", CmpList[ii].m_Reference );
/* Write the footprint list */
for( unsigned int jj = 0; jj < Entry->m_FootprintList.GetCount(); jj++ )
{
......
......@@ -1200,13 +1200,13 @@ static void SetUnconnectedFlag( ObjetNetListStruct* ListObj, int NbItems )
ObjetNetListStruct* NetItemRef, * NetItemTst, * ItemPtr;
ObjetNetListStruct* NetStart, * NetEnd, * Lim;
int Nb;
IsConnectType StateFlag;
ConnectType StateFlag;
NetStart = NetEnd = ListObj;
NetItemRef = NetStart;
Nb = 0;
StateFlag = UNCONNECT;
StateFlag = UNCONNECTED;
Lim = ListObj + NbItems;
for( ; NetItemRef < Lim; NetItemRef++ )
......@@ -1233,7 +1233,7 @@ static void SetUnconnectedFlag( ObjetNetListStruct* ListObj, int NbItems )
return;
/* Start Analyse Nouveau Net */
StateFlag = UNCONNECT;
StateFlag = UNCONNECTED;
NetStart = NetItemTst;
continue;
}
......
......@@ -52,8 +52,8 @@ enum NetObjetType { /* Type des objets de Net */
};
enum IsConnectType { /* Valeur du Flag de connection */
UNCONNECT, /* Pin ou Label non connecte */
enum ConnectType { /* Valeur du Flag de connection */
UNCONNECTED = 0, /* Pin ou Label non connecte */
NOCONNECT, /* Pin volontairement non connectee (Symb. NoConnect utilise) */
PAD_CONNECT /* connexion normale */
};
......@@ -76,7 +76,7 @@ public:
int m_BusNetCode; /* pour connexions type bus */
int m_Member; /* pour les labels type BUSWIRE ( labels de bus eclate )
* numero de membre */
IsConnectType m_FlagOfConnection;
ConnectType m_FlagOfConnection;
DrawSheetPath m_SheetListInclude; /* sheet that the hierarchal label connects to.*/
long m_PinNum; /* numero de pin( 4 octets -> 4 codes ascii) */
const wxString* m_Label; /* Tous types Labels:pointeur sur la wxString definissant le label */
......@@ -92,45 +92,59 @@ public:
};
/* Structures pour memo et liste des elements */
struct ListLabel
/* object used in annotation to handle a list of components in schematic
* because in a complex hierarchy, a component is used more than once,
* and its reference is depending on the sheet path
* for the same component, we must create a flat list of components
* used in nelist generation, BOM generation and annotation
*/
class OBJ_CMP_TO_LIST
{
int m_LabelType;
void* m_Label;
char m_SheetPath[256];
};
public:
SCH_COMPONENT* m_RootCmp; // the component in schematic
EDA_LibComponentStruct* m_Entry; // the source component in library
int m_Unit; /* Selected part (For multi parts per package) depending on sheet path */
DrawSheetPath m_SheetPath; /* the sheet path for this component */
unsigned long m_TimeStamp; /* unique identification number depending on sheet path */
bool m_IsNew; /* true for not yet annotated components */
wxString* m_Value; /* Component value (same for all instances) */
char m_Reference[32]; /* Component reference prefix, without number (for IC1, this is IC) ) */
int m_NumRef; /* Reference number (for IC1, this is 1) ) depending on sheet path*/
int m_Flag; /* flag for computations */
public:
// Used to create lists of components BOM, netlist generation)
struct ListComponent
{
SCH_COMPONENT* m_Comp; // pointer on the component in schematic
char m_Ref[32]; // component reference
int m_Unit; // Unit value, for multiple parts per package
//have to store it here since the object references will be duplicated.
DrawSheetPath m_SheetList; //composed of UIDs
OBJ_CMP_TO_LIST()
{
m_RootCmp = NULL;
m_Entry = NULL;
m_Unit = 0;
m_TimeStamp = 0;
m_IsNew = false;
m_Value = NULL;
m_Reference[0] = 0;
m_NumRef = 0;
m_Flag = 0;
}
int CompareValue( const OBJ_CMP_TO_LIST& item ) const
{
return m_Value->CmpNoCase( *item.m_Value );
}
int CompareRef( const OBJ_CMP_TO_LIST& item ) const
{
return strnicmp( m_Reference, item.m_Reference, 32 );
}
bool IsPartsLocked( )
{
return m_Entry->m_UnitSelectionLocked;
}
};
/* Structure decrivant 1 composant de la schematique (for annotation ) */
struct CmpListStruct
{
public:
SCH_COMPONENT* m_Cmp; /* Pointeur sur le composant */
int m_NbParts; /* Nombre de parts par boitier */
bool m_PartsLocked; // For multi part components: True if the part cannot be changed
int m_Unit; /* Numero de part */
DrawSheetPath m_SheetList;
unsigned long m_TimeStamp; /* unique identification number */
int m_IsNew; /* != 0 pour composants non annotes */
char m_TextValue[32]; /* Valeur */
char m_TextRef[32]; /* Reference ( hors numero ) */
int m_NumRef; /* Numero de reference */
int m_Flag; /* flag pour calculs internes */
wxPoint m_Pos; /* position components */
char m_Path[256]; // the 'path' of the object in the sheet hierarchy.
};
/* Global Variables */
eda_global int g_NbrObjNet;
......
......@@ -40,7 +40,7 @@ void InstallCmpeditFrame(WinEDA_SchematicFrame * parent, wxPoint & pos,
/******************************/
int LibraryEntryCompare(EDA_LibComponentStruct *LE1, EDA_LibComponentStruct *LE2);
int NumOfLibraries();
EDA_LibComponentStruct *FindLibPart(const wxChar *Name, const wxString & LibName, int Alias);
EDA_LibComponentStruct *FindLibPart(const wxChar *Name, const wxString & LibName, int Alias = FIND_ROOT);
void DrawingLibInGhost(WinEDA_DrawPanel * panel, wxDC * DC, EDA_LibComponentStruct *LibEntry,
SCH_COMPONENT * DrawLibItem, int PartX, int PartY,
......
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