Commit 64e9e168 authored by dickelbeck's avatar dickelbeck

virtual BOARD_ITEM::Save()

parent a67a4f7e
...@@ -4,17 +4,33 @@ Started 2007-June-11 ...@@ -4,17 +4,33 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with Please add newer entries at the top, list the date and your name with
email address. email address.
2007-Oct-30 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
+ pcbnew
added BOARD_ITEM::Save() and to all derived classes as well. Made virtual
and removed all UI code from these utility functions.
removed WriteDesc() functions from all BOARD_ITEM derived classes, although
Keeping old ones in commented out form for a while for reference.
@todo: delete these from *.cpp files eventually.
zones.cpp, clean up in prep for enhancements.
+ gerbview
fixed bug which came about when BOARD::~BOARD() started deleting the objects
that a BOARD owns. export_to_pcbnew.cpp was not consistent with this
design and was crashing. Also, export_to_pcbnew.cpp now uses the simple
BOARD::Save() function. It was another place to maintain the PCB file format,
rather than simply putting that knowledge into one place like BOARD::Save().
2007-Oct-30 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr> 2007-Oct-30 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================ ================================================================================
+cvpcb: listboxes.cpp problem solved: exists only under windows +cvpcb: listboxes.cpp problem solved: exists only under windows
now apply to windows only, because this Workaround creates a problem undex linux now apply to windows only, because this Workaround creates a problem undex linux
+others: +others:
some very minor problems solved some very minor problems solved
+eeschema: +eeschema:
in B.O.M.: the footprint field can be added to the field list in B.O.M.: the footprint field can be added to the field list
2007-Oct-29 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr> 2007-Oct-29 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================ ================================================================================
+cvpcb: listboxes.cpp problem solved: Workaround for a curious bug in wxWidgets: +cvpcb: listboxes.cpp problem solved: Workaround for a curious bug in wxWidgets:
...@@ -33,12 +49,10 @@ email address. ...@@ -33,12 +49,10 @@ email address.
+ all: + all:
remove unused files. remove unused files.
some translations some translations
+cvpcb: +cvpcb:
set flag wxFRAME_FLOAT_ON_PARENT when create the footprint 3D frame and the set flag wxFRAME_FLOAT_ON_PARENT when create the footprint 3D frame and the
display frame display frame
minor other changes minor other changes
+ pcbnew: + pcbnew:
Use collector class to locate items in modedit. Use collector class to locate items in modedit.
This is a big enhancement, This is a big enhancement,
......
...@@ -58,7 +58,7 @@ void EDA_BaseStruct::InitVars() ...@@ -58,7 +58,7 @@ void EDA_BaseStruct::InitVars()
/* Gestion de l'etat (status) de la structure (active, deleted..) */ /* Gestion de l'etat (status) de la structure (active, deleted..) */
int EDA_BaseStruct::GetState( int type ) int EDA_BaseStruct::GetState( int type ) const
{ {
return m_Status & type; return m_Status & type;
} }
......
...@@ -125,7 +125,7 @@ static bool WriteGeneralDescrPcb( BOARD* Pcb, FILE* File ) ...@@ -125,7 +125,7 @@ static bool WriteGeneralDescrPcb( BOARD* Pcb, FILE* File )
/*******************************************************************/ /*******************************************************************/
static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File, static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* aFile,
int* LayerLookUpTable ) int* LayerLookUpTable )
/*******************************************************************/ /*******************************************************************/
...@@ -136,20 +136,17 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File, ...@@ -136,20 +136,17 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File,
* @return 1 if OK, 0 if fail * @return 1 if OK, 0 if fail
*/ */
{ {
char Line[256]; char line[256];
TRACK* track; TRACK* track;
TRACK* next_track; BOARD* gerberPcb = frame->m_Pcb;
BOARD_ITEM* PtStruct; BOARD* pcb;
BOARD_ITEM* NextStruct;
BOARD* GerberPcb = frame->m_Pcb;
BOARD* Pcb;
wxBeginBusyCursor(); wxBeginBusyCursor();
/* Create an image of gerber data */ // create an image of gerber data
Pcb = new BOARD( NULL, frame ); pcb = new BOARD( NULL, frame );
for( track = GerberPcb->m_Track; track != NULL; track = (TRACK*) track->Pnext ) for( track = gerberPcb->m_Track; track; track = track->Next() )
{ {
int layer = track->GetLayer(); int layer = track->GetLayer();
int pcb_layer_number = LayerLookUpTable[layer]; int pcb_layer_number = LayerLookUpTable[layer];
...@@ -158,23 +155,23 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File, ...@@ -158,23 +155,23 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File,
if( pcb_layer_number > CMP_N ) if( pcb_layer_number > CMP_N )
{ {
DRAWSEGMENT* drawitem = new DRAWSEGMENT( NULL, TYPEDRAWSEGMENT ); DRAWSEGMENT* drawitem = new DRAWSEGMENT( pcb, TYPEDRAWSEGMENT );
drawitem->SetLayer( pcb_layer_number ); drawitem->SetLayer( pcb_layer_number );
drawitem->m_Start = track->m_Start; drawitem->m_Start = track->m_Start;
drawitem->m_End = track->m_End; drawitem->m_End = track->m_End;
drawitem->m_Width = track->m_Width; drawitem->m_Width = track->m_Width;
drawitem->Pnext = Pcb->m_Drawings; drawitem->Pnext = pcb->m_Drawings;
Pcb->m_Drawings = drawitem; pcb->m_Drawings = drawitem;
} }
else else
{ {
TRACK* newtrack; TRACK* newtrack;
// replace spots with vias when possible // replace spots with vias when possible
if( (track->m_Shape == S_SPOT_CIRCLE) if( track->m_Shape == S_SPOT_CIRCLE
|| (track->m_Shape == S_SPOT_RECT) || track->m_Shape == S_SPOT_RECT
|| (track->m_Shape == S_SPOT_OVALE) ) || track->m_Shape == S_SPOT_OVALE )
{ {
newtrack = new SEGVIA( (const SEGVIA&) *track ); newtrack = new SEGVIA( (const SEGVIA&) *track );
...@@ -198,19 +195,20 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File, ...@@ -198,19 +195,20 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File,
newtrack->SetLayer( pcb_layer_number ); newtrack->SetLayer( pcb_layer_number );
} }
newtrack->Insert( Pcb, NULL ); newtrack->Insert( pcb, NULL );
} }
} }
// delete redundant vias // delete redundant vias
for( track = Pcb->m_Track; track != NULL; track = track->Next() ) for( track = pcb->m_Track; track; track = track->Next() )
{ {
if( track->m_Shape != VIA_THROUGH ) if( track->m_Shape != VIA_THROUGH )
continue; continue;
// Search and delete others vias // Search and delete others vias
TRACK* next_track;
TRACK* alt_track = track->Next(); TRACK* alt_track = track->Next();
for( ; alt_track != NULL; alt_track = next_track ) for( ; alt_track; alt_track = next_track )
{ {
next_track = alt_track->Next(); next_track = alt_track->Next();
if( alt_track->m_Shape != VIA_THROUGH ) if( alt_track->m_Shape != VIA_THROUGH )
...@@ -229,54 +227,16 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File, ...@@ -229,54 +227,16 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File,
setlocale( LC_NUMERIC, "C" ); setlocale( LC_NUMERIC, "C" );
// write the PCB heading // write the PCB heading
fprintf( File, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB, fprintf( aFile, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB,
DateAndTime( Line ) ); DateAndTime( line ) );
WriteGeneralDescrPcb( Pcb, File ); WriteGeneralDescrPcb( pcb, aFile );
WriteSetup( File, Pcb ); WriteSetup( aFile, pcb );
// write the useful part of the pcb // write the useful part of the pcb
PtStruct = Pcb->m_Drawings; pcb->Save( aFile );
for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
{
switch( PtStruct->Type() )
{
case TYPETEXTE:
( (TEXTE_PCB*) PtStruct )->WriteTextePcbDescr( File );
break;
case TYPEDRAWSEGMENT:
( (DRAWSEGMENT*) PtStruct )->WriteDrawSegmentDescr( File );
break;
default:
break;
}
}
fprintf( File, "$TRACK\n" );
for( track = Pcb->m_Track; track != NULL; track = (TRACK*) track->Pnext )
{
track->WriteTrackDescr( File );
}
fprintf( File, "$EndTRACK\n" );
fprintf( File, "$EndBOARD\n" );
// Delete the copy
for( PtStruct = Pcb->m_Drawings; PtStruct != NULL; PtStruct = NextStruct )
{
NextStruct = PtStruct->Next();
delete PtStruct;
}
for( track = Pcb->m_Track; track != NULL; track = next_track )
{
next_track = (TRACK*) track->Pnext;
delete track;
}
delete Pcb; // the destructor should destroy all owned sub-objects
delete pcb;
setlocale( LC_NUMERIC, "" ); // revert to the current locale setlocale( LC_NUMERIC, "" ); // revert to the current locale
wxEndBusyCursor(); wxEndBusyCursor();
......
...@@ -191,7 +191,7 @@ public: ...@@ -191,7 +191,7 @@ public:
/* Gestion de l'etat (status) de la structure (active, deleted..) */ /* Gestion de l'etat (status) de la structure (active, deleted..) */
int GetState( int type ); int GetState( int type ) const;
void SetState( int type, int state ); void SetState( int type, int state );
int ReturnStatus() const { return m_Status; } int ReturnStatus() const { return m_Status; }
...@@ -490,6 +490,17 @@ public: ...@@ -490,6 +490,17 @@ public:
* @todo: make this virtual and split into each derived class * @todo: make this virtual and split into each derived class
*/ */
const char** MenuIcon() const; const char** MenuIcon() const;
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) const = 0;
}; };
......
...@@ -289,6 +289,15 @@ public: ...@@ -289,6 +289,15 @@ public:
EQUIPOT* FindNet( int aNetcode ) const; EQUIPOT* FindNet( int aNetcode ) const;
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
/** /**
* Function GetClass * Function GetClass
* returns the class name. * returns the class name.
...@@ -370,7 +379,15 @@ public: ...@@ -370,7 +379,15 @@ public:
~DRAWSEGMENT(); ~DRAWSEGMENT();
// Read/write data // Read/write data
bool WriteDrawSegmentDescr( FILE* File );
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
bool ReadDrawSegmentDescr( FILE* File, int* LineNum ); bool ReadDrawSegmentDescr( FILE* File, int* LineNum );
/* remove this from the linked list */ /* remove this from the linked list */
......
...@@ -576,6 +576,73 @@ EQUIPOT* BOARD::FindNet( int anetcode ) const ...@@ -576,6 +576,73 @@ EQUIPOT* BOARD::FindNet( int anetcode ) const
} }
bool BOARD::Save( FILE* aFile ) const
{
bool rc = false;
BOARD_ITEM* item;
// save the nets
for( item = m_Equipots; item; item=item->Next() )
if( !item->Save( aFile ) )
goto out;
// save the modules
for( item = m_Modules; item; item=item->Next() )
if( !item->Save( aFile ) )
goto out;
for( item = m_Drawings; item; item=item->Next() )
{
switch( item->Type() )
{
case TYPETEXTE:
case TYPEDRAWSEGMENT:
case TYPEMIRE:
case TYPECOTATION:
if( !item->Save( aFile ) )
goto out;
break;
case TYPEMARQUEUR: // do not save MARKERs, they can be regenerated easily
break;
default:
// future: throw exception here
#if defined(DEBUG)
printf( "BOARD::Save() ignoring draw type %d\n", item->Type() );
#endif
break;
}
}
// save the tracks & vias
fprintf( aFile, "$TRACK\n" );
for( item = m_Track; item; item=item->Next() )
if( !item->Save( aFile ) )
goto out;
fprintf( aFile, "$EndTRACK\n" );
// save the zones
fprintf( aFile, "$ZONE\n" );
for( item = m_Zone; item; item=item->Next() )
if( !item->Save( aFile ) )
goto out;
fprintf( aFile, "$EndZONE\n" );
if( fprintf( aFile, "$EndBOARD\n" ) != sizeof("$EndBOARD\n")-1 )
goto out;
rc = true; // wrote all OK
out:
return rc;
}
#if defined(DEBUG) #if defined(DEBUG)
/** /**
......
...@@ -227,6 +227,7 @@ bool COTATION::ReadCotationDescr( FILE* File, int* LineNum ) ...@@ -227,6 +227,7 @@ bool COTATION::ReadCotationDescr( FILE* File, int* LineNum )
} }
#if 0
/**************************************************/ /**************************************************/
bool COTATION::WriteCotationDescr( FILE* File ) bool COTATION::WriteCotationDescr( FILE* File )
/**************************************************/ /**************************************************/
...@@ -285,6 +286,73 @@ bool COTATION::WriteCotationDescr( FILE* File ) ...@@ -285,6 +286,73 @@ bool COTATION::WriteCotationDescr( FILE* File )
return 1; return 1;
} }
#endif
bool COTATION::Save( FILE* aFile ) const
{
if( GetState( DELETED ) )
return true;
bool rc = false;
if( fprintf( aFile, "$COTATION\n" ) != sizeof("$COTATION\n")-1 )
goto out;
fprintf( aFile, "Ge %d %d %lX\n", m_Shape, m_Layer, m_TimeStamp );
fprintf( aFile, "Va %d\n", m_Value );
if( !m_Text->m_Text.IsEmpty() )
fprintf( aFile, "Te \"%s\"\n", CONV_TO_UTF8( m_Text->m_Text ) );
else
fprintf( aFile, "Te \"?\"\n" );
fprintf( aFile, "Po %d %d %d %d %d %d %d\n",
m_Text->m_Pos.x, m_Text->m_Pos.y,
m_Text->m_Size.x, m_Text->m_Size.y,
m_Text->m_Width, m_Text->m_Orient,
m_Text->m_Miroir );
fprintf( aFile, "Sb %d %d %d %d %d %d\n", S_SEGMENT,
Barre_ox, Barre_oy,
Barre_fx, Barre_fy, m_Width );
fprintf( aFile, "Sd %d %d %d %d %d %d\n", S_SEGMENT,
TraitD_ox, TraitD_oy,
TraitD_fx, TraitD_fy, m_Width );
fprintf( aFile, "Sg %d %d %d %d %d %d\n", S_SEGMENT,
TraitG_ox, TraitG_oy,
TraitG_fx, TraitG_fy, m_Width );
fprintf( aFile, "S1 %d %d %d %d %d %d\n", S_SEGMENT,
FlecheD1_ox, FlecheD1_oy,
FlecheD1_fx, FlecheD1_fy, m_Width );
fprintf( aFile, "S2 %d %d %d %d %d %d\n", S_SEGMENT,
FlecheD2_ox, FlecheD2_oy,
FlecheD2_fx, FlecheD2_fy, m_Width );
fprintf( aFile, "S3 %d %d %d %d %d %d\n", S_SEGMENT,
FlecheG1_ox, FlecheG1_oy,
FlecheG1_fx, FlecheG1_fy, m_Width );
fprintf( aFile, "S4 %d %d %d %d %d %d\n", S_SEGMENT,
FlecheG2_ox, FlecheG2_oy,
FlecheG2_fx, FlecheG2_fy, m_Width );
if( fprintf( aFile, "$EndCOTATION\n" ) != sizeof("$EndCOTATION\n")-1 )
goto out;
rc = true;
out:
return rc;
}
/************************************************************************/ /************************************************************************/
......
...@@ -29,7 +29,14 @@ public: ...@@ -29,7 +29,14 @@ public:
~COTATION(); ~COTATION();
bool ReadCotationDescr( FILE* File, int* LineNum ); bool ReadCotationDescr( FILE* File, int* LineNum );
bool WriteCotationDescr( FILE* File );
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
/* supprime du chainage la structure Struct */ /* supprime du chainage la structure Struct */
void UnLink(); void UnLink();
......
...@@ -298,6 +298,7 @@ void EDGE_MODULE::Display_Infos( WinEDA_DrawFrame* frame ) ...@@ -298,6 +298,7 @@ void EDGE_MODULE::Display_Infos( WinEDA_DrawFrame* frame )
} }
#if 0 // replaced by Save()
/*****************************************/ /*****************************************/
int EDGE_MODULE::WriteDescr( FILE* File ) int EDGE_MODULE::WriteDescr( FILE* File )
/*****************************************/ /*****************************************/
...@@ -358,6 +359,59 @@ int EDGE_MODULE::WriteDescr( FILE* File ) ...@@ -358,6 +359,59 @@ int EDGE_MODULE::WriteDescr( FILE* File )
return NbLigne; return NbLigne;
} }
#endif
bool EDGE_MODULE::Save( FILE* aFile ) const
{
int ret = -1;
switch( m_Shape )
{
case S_SEGMENT:
ret = fprintf( aFile, "DS %d %d %d %d %d %d\n",
m_Start0.x, m_Start0.y,
m_End0.x, m_End0.y,
m_Width, m_Layer );
break;
case S_CIRCLE:
ret = fprintf( aFile, "DC %d %d %d %d %d %d\n",
m_Start0.x, m_Start0.y,
m_End0.x, m_End0.y,
m_Width, m_Layer );
break;
case S_ARC:
ret = fprintf( aFile, "DA %d %d %d %d %d %d %d\n",
m_Start0.x, m_Start0.y,
m_End0.x, m_End0.y,
m_Angle,
m_Width, m_Layer );
break;
case S_POLYGON:
ret = fprintf( aFile, "DP %d %d %d %d %d %d %d\n",
m_Start0.x, m_Start0.y,
m_End0.x, m_End0.y,
m_PolyCount,
m_Width, m_Layer );
int* pInt;
pInt = m_PolyList;
for( int i=0; i<m_PolyCount; ++i, pInt+=2 )
fprintf( aFile, "Dl %d %d\n", pInt[0], pInt[1] );
break;
default:
// future: throw an exception here
printf( "%s unexpected EDGE_MODULE::m_Shape: %d\n", __func__, m_Shape );
break;
}
return (ret > 5);
}
/****************************************************************/ /****************************************************************/
......
...@@ -34,8 +34,14 @@ public: ...@@ -34,8 +34,14 @@ public:
void Copy( EDGE_MODULE* source ); // copy structure void Copy( EDGE_MODULE* source ); // copy structure
/* Reading and writing data on files */ /**
int WriteDescr( FILE* File ); * Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
int ReadDescr( char* Line, FILE* File, int* LineNum = NULL ); int ReadDescr( char* Line, FILE* File, int* LineNum = NULL );
// Mise a jour des coordon�s pour l'affichage // Mise a jour des coordon�s pour l'affichage
......
...@@ -106,6 +106,7 @@ int EQUIPOT:: ReadEquipotDescr( FILE* File, int* LineNum ) ...@@ -106,6 +106,7 @@ int EQUIPOT:: ReadEquipotDescr( FILE* File, int* LineNum )
} }
#if 0 // replaced by Save()
/********************************************/ /********************************************/
int EQUIPOT:: WriteEquipotDescr( FILE* File ) int EQUIPOT:: WriteEquipotDescr( FILE* File )
/********************************************/ /********************************************/
...@@ -121,6 +122,32 @@ int EQUIPOT:: WriteEquipotDescr( FILE* File ) ...@@ -121,6 +122,32 @@ int EQUIPOT:: WriteEquipotDescr( FILE* File )
fprintf( File, "$EndEQUIPOT\n" ); fprintf( File, "$EndEQUIPOT\n" );
return 1; return 1;
} }
#endif
bool EQUIPOT::Save( FILE* aFile ) const
{
if( GetState( DELETED ) )
return true;
bool rc = false;
fprintf( aFile, "$EQUIPOT\n" );
fprintf( aFile, "Na %d \"%.16s\"\n", GetNet(), CONV_TO_UTF8( m_Netname ) );
fprintf( aFile, "St %s\n", "~" );
if( m_ForceWidth )
fprintf( aFile, "Lw %d\n", m_ForceWidth );
if( fprintf( aFile, "$EndEQUIPOT\n" ) != sizeof("$EndEQUIPOT\n")-1 )
goto out;
rc = true;
out:
return rc;
}
#if defined(DEBUG) #if defined(DEBUG)
/** /**
......
...@@ -33,7 +33,15 @@ public: ...@@ -33,7 +33,15 @@ public:
/* Readind and writing data on files */ /* Readind and writing data on files */
int ReadEquipotDescr( FILE* File, int* LineNum ); int ReadEquipotDescr( FILE* File, int* LineNum );
int WriteEquipotDescr( FILE* File );
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
/** /**
* Function GetNet * Function GetNet
......
...@@ -33,6 +33,20 @@ public: ...@@ -33,6 +33,20 @@ public:
void Display_Infos( WinEDA_DrawFrame* frame ); void Display_Infos( WinEDA_DrawFrame* frame );
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const
{
// not implemented, this is here to satisfy BOARD_ITEM::Save()
// "pure" virtual-ness
return true;
}
/** /**
* Function HitTest * Function HitTest
* tests if the given wxPoint is within the bounds of this object. * tests if the given wxPoint is within the bounds of this object.
......
...@@ -94,6 +94,7 @@ bool MIREPCB::ReadMirePcbDescr( FILE* File, int* LineNum ) ...@@ -94,6 +94,7 @@ bool MIREPCB::ReadMirePcbDescr( FILE* File, int* LineNum )
} }
#if 0 // replaced by Save()
/************************************************/ /************************************************/
bool MIREPCB::WriteMirePcbDescr( FILE* File ) bool MIREPCB::WriteMirePcbDescr( FILE* File )
/************************************************/ /************************************************/
...@@ -109,6 +110,34 @@ bool MIREPCB::WriteMirePcbDescr( FILE* File ) ...@@ -109,6 +110,34 @@ bool MIREPCB::WriteMirePcbDescr( FILE* File )
fprintf( File, "$EndMIREPCB\n" ); fprintf( File, "$EndMIREPCB\n" );
return TRUE; return TRUE;
} }
#endif
bool MIREPCB::Save( FILE* aFile ) const
{
if( GetState( DELETED ) )
return true;
bool rc = false;
if( fprintf( aFile, "$MIREPCB\n" ) != sizeof("$MIREPCB\n")-1 )
goto out;
fprintf( aFile, "Po %X %d %d %d %d %d %8.8lX\n",
m_Shape, m_Layer,
m_Pos.x, m_Pos.y,
m_Size, m_Width, m_TimeStamp );
if( fprintf( aFile, "$EndMIREPCB\n" ) != sizeof("$EndMIREPCB\n")-1 )
goto out;
rc = true;
out:
return rc;
}
/**********************************************************/ /**********************************************************/
......
...@@ -19,7 +19,14 @@ public: ...@@ -19,7 +19,14 @@ public:
MIREPCB( BOARD_ITEM* StructFather ); MIREPCB( BOARD_ITEM* StructFather );
~MIREPCB(); ~MIREPCB();
bool WriteMirePcbDescr( FILE* File ); /**
* Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
bool ReadMirePcbDescr( FILE* File, int* LineNum ); bool ReadMirePcbDescr( FILE* File, int* LineNum );
/* supprime du chainage la structure Struct */ /* supprime du chainage la structure Struct */
......
...@@ -345,6 +345,7 @@ void MODULE::DrawEdgesOnly( WinEDA_DrawPanel* panel, wxDC* DC, ...@@ -345,6 +345,7 @@ void MODULE::DrawEdgesOnly( WinEDA_DrawPanel* panel, wxDC* DC,
} }
#if 0
/*************************************/ /*************************************/
int MODULE::WriteDescr( FILE* File ) int MODULE::WriteDescr( FILE* File )
/*************************************/ /*************************************/
...@@ -489,10 +490,110 @@ int MODULE::WriteDescr( FILE* File ) ...@@ -489,10 +490,110 @@ int MODULE::WriteDescr( FILE* File )
NbLigne++; NbLigne++;
return NbLigne; return NbLigne;
} }
#endif
bool MODULE::Save( FILE* aFile ) const
{
char statusTxt[8];
BOARD_ITEM* item;
if( GetState( DELETED ) )
return true;
bool rc = false;
fprintf( aFile, "$MODULE %s\n", CONV_TO_UTF8( m_LibRef ) );
// Generation des coord et caracteristiques
memset( statusTxt, 0, sizeof(statusTxt) );
if( IsLocked() )
statusTxt[0] = 'F';
else
statusTxt[0] = '~';
if( m_ModuleStatus & MODULE_is_PLACED )
statusTxt[1] = 'P';
else
statusTxt[1] = '~';
fprintf( aFile, "Po %d %d %d %d %8.8lX %8.8lX %s\n",
m_Pos.x, m_Pos.y,
m_Orient, m_Layer, m_LastEdit_Time,
m_TimeStamp, statusTxt );
fprintf( aFile, "Li %s\n", CONV_TO_UTF8( m_LibRef ) );
if( !m_Doc.IsEmpty() )
{
fprintf( aFile, "Cd %s\n", CONV_TO_UTF8( m_Doc ) );
}
if( !m_KeyWord.IsEmpty() )
{
fprintf( aFile, "Kw %s\n", CONV_TO_UTF8( m_KeyWord ) );
}
fprintf( aFile, "Sc %8.8lX\n", m_TimeStamp );
fprintf( aFile, "Op %X %X 0\n", m_CntRot90, m_CntRot180 );
// attributes
if( m_Attributs != MOD_DEFAULT )
{
fprintf( aFile, "At " );
if( m_Attributs & MOD_CMS )
fprintf( aFile, "SMD " );
if( m_Attributs & MOD_VIRTUAL )
fprintf( aFile, "VIRTUAL " );
fprintf( aFile, "\n" );
}
// save reference
if( !m_Reference->Save( aFile ) )
goto out;
// save value
if( !m_Value->Save( aFile ) )
goto out;
// save drawing elements
for( item=m_Drawings; item; item=item->Next() )
{
switch( item->Type() )
{
case TYPETEXTEMODULE:
case TYPEEDGEMODULE:
if( !item->Save( aFile ) )
goto out;
break;
default:
#if defined(DEBUG)
printf( "MODULE::Save() ignoring type %d\n", item->Type() );
#endif
break;
}
}
// save the pads
for( item=m_Pads; item; item=item->Next() )
if( !item->Save( aFile ) )
goto out;
// Generation des informations de trac�3D
Write_3D_Descr( aFile );
fprintf( aFile, "$EndMODULE %s\n", CONV_TO_UTF8( m_LibRef ) );
rc = true;
out:
return rc;
}
/***************************************/ /***************************************/
int MODULE::Write_3D_Descr( FILE* File ) int MODULE::Write_3D_Descr( FILE* File ) const
/***************************************/ /***************************************/
/* Sauvegarde de la description 3D du MODULE /* Sauvegarde de la description 3D du MODULE
......
...@@ -116,8 +116,16 @@ public: ...@@ -116,8 +116,16 @@ public:
/* Reading and writing data on files */ /* Reading and writing data on files */
int WriteDescr( FILE* File );
int Write_3D_Descr( FILE* File ); /**
* Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
int Write_3D_Descr( FILE* File ) const;
int ReadDescr( FILE* File, int* LineNum = NULL ); int ReadDescr( FILE* File, int* LineNum = NULL );
int Read_3D_Descr( FILE* File, int* LineNum = NULL ); int Read_3D_Descr( FILE* File, int* LineNum = NULL );
......
...@@ -763,6 +763,8 @@ int D_PAD::ReadDescr( FILE* File, int* LineNum ) ...@@ -763,6 +763,8 @@ int D_PAD::ReadDescr( FILE* File, int* LineNum )
} }
#if 0
/***********************************/ /***********************************/
int D_PAD::WriteDescr( FILE* File ) int D_PAD::WriteDescr( FILE* File )
/***********************************/ /***********************************/
...@@ -849,6 +851,92 @@ int D_PAD::WriteDescr( FILE* File ) ...@@ -849,6 +851,92 @@ int D_PAD::WriteDescr( FILE* File )
NbLigne++; NbLigne++;
return NbLigne; return NbLigne;
} }
#endif
bool D_PAD::Save( FILE* aFile ) const
{
int cshape;
const char* texttype;
if( GetState( DELETED ) )
return true;
bool rc = false;
// check the return values for first and last fprints() in this function
if( fprintf( aFile, "$PAD\n" ) != sizeof("$PAD\n")-1 )
goto out;
switch( m_PadShape )
{
case CIRCLE:
cshape = 'C'; break;
case RECT:
cshape = 'R'; break;
case OVALE:
cshape = 'O'; break;
case TRAPEZE:
cshape = 'T'; break;
default:
cshape = 'C';
DisplayError( NULL, _( "Unknown Pad shape" ) );
break;
}
fprintf( aFile, "Sh \"%.4s\" %c %d %d %d %d %d\n",
m_Padname, cshape, m_Size.x, m_Size.y,
m_DeltaSize.x, m_DeltaSize.y, m_Orient );
fprintf( aFile, "Dr %d %d %d", m_Drill.x, m_Offset.x, m_Offset.y );
if( m_DrillShape == OVALE )
{
fprintf( aFile, " %c %d %d", 'O', m_Drill.x, m_Drill.y );
}
fprintf( aFile, "\n" );
switch( m_Attribut )
{
case STANDARD:
texttype = "STD"; break;
case SMD:
texttype = "SMD"; break;
case CONN:
texttype = "CONN"; break;
case P_HOLE:
texttype = "HOLE"; break;
case MECA:
texttype = "MECA"; break;
default:
texttype = "STD";
DisplayError( NULL, wxT( "Invalid Pad attribute" ) );
break;
}
fprintf( aFile, "At %s N %8.8X\n", texttype, m_Masque_Layer );
fprintf( aFile, "Ne %d \"%s\"\n", GetNet(), CONV_TO_UTF8( m_Netname ) );
fprintf( aFile, "Po %d %d\n", m_Pos0.x, m_Pos0.y );
if( fprintf( aFile, "$EndPAD\n" ) != sizeof("$EndPAD\n")-1 )
goto out;
rc = true;
out:
return rc;
}
/******************************************************/ /******************************************************/
......
...@@ -77,7 +77,15 @@ public: ...@@ -77,7 +77,15 @@ public:
/* Reading and writing data on files */ /* Reading and writing data on files */
int ReadDescr( FILE* File, int* LineNum = NULL ); int ReadDescr( FILE* File, int* LineNum = NULL );
int WriteDescr( FILE* File );
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
/* drawing functions */ /* drawing functions */
void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode ); void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode );
......
...@@ -112,6 +112,7 @@ int TEXTE_PCB::ReadTextePcbDescr( FILE* File, int* LineNum ) ...@@ -112,6 +112,7 @@ int TEXTE_PCB::ReadTextePcbDescr( FILE* File, int* LineNum )
} }
#if 0 // replaced by Save()
/**************************************************/ /**************************************************/
int TEXTE_PCB::WriteTextePcbDescr( FILE* File ) int TEXTE_PCB::WriteTextePcbDescr( FILE* File )
/**************************************************/ /**************************************************/
...@@ -129,6 +130,36 @@ int TEXTE_PCB::WriteTextePcbDescr( FILE* File ) ...@@ -129,6 +130,36 @@ int TEXTE_PCB::WriteTextePcbDescr( FILE* File )
fprintf( File, "$EndTEXTPCB\n" ); fprintf( File, "$EndTEXTPCB\n" );
return 1; return 1;
} }
#endif
bool TEXTE_PCB::Save( FILE* aFile ) const
{
if( GetState( DELETED ) )
return true;
if( m_Text.IsEmpty() )
return true;
bool rc = false;
if( fprintf( aFile, "$TEXTPCB\n" ) != sizeof("$TEXTPCB\n")-1 )
goto out;
fprintf( aFile, "Te \"%s\"\n", CONV_TO_UTF8( m_Text ) );
fprintf( aFile, "Po %d %d %d %d %d %d\n",
m_Pos.x, m_Pos.y, m_Size.x, m_Size.y, m_Width, m_Orient );
fprintf( aFile, "De %d %d %lX %d\n", m_Layer, m_Miroir, m_TimeStamp, 0 );
if( fprintf( aFile, "$EndTEXTPCB\n" ) != sizeof("$EndTEXTPCB\n")-1 )
goto out;
rc = true;
out:
return rc;
}
/**********************************************************************/ /**********************************************************************/
......
...@@ -24,8 +24,14 @@ public: ...@@ -24,8 +24,14 @@ public:
// File Operations: // File Operations:
int ReadTextePcbDescr( FILE* File, int* LineNum ); int ReadTextePcbDescr( FILE* File, int* LineNum );
int WriteTextePcbDescr( FILE* File );
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
/** /**
* Function Display_Infos * Function Display_Infos
......
...@@ -71,6 +71,28 @@ TEXTE_MODULE::~TEXTE_MODULE() ...@@ -71,6 +71,28 @@ TEXTE_MODULE::~TEXTE_MODULE()
} }
bool TEXTE_MODULE::Save( FILE* aFile ) const
{
MODULE* parent = (MODULE*) GetParent();
int orient = m_Orient;
if( parent )
orient += parent->m_Orient;
int ret = fprintf( aFile, "T%d %d %d %d %d %d %d %c %c %d \"%.16s\"\n",
m_Type,
m_Pos0.x, m_Pos0.y,
m_Size.y, m_Size.x,
orient,
m_Width,
m_Miroir ? 'N' : 'M', m_NoShow ? 'I' : 'V',
GetLayer(),
CONV_TO_UTF8( m_Text ) );
return (ret > 20);
}
void TEXTE_MODULE::Copy( TEXTE_MODULE* source ) // copy structure void TEXTE_MODULE::Copy( TEXTE_MODULE* source ) // copy structure
{ {
if( source == NULL ) if( source == NULL )
......
...@@ -47,9 +47,15 @@ public: ...@@ -47,9 +47,15 @@ public:
void SetLocalCoord(); // mise a jour des coordonn�s relatives void SetLocalCoord(); // mise a jour des coordonn�s relatives
// a partir des coord absolues de trac� /**
/* Reading and writing data on files */ * Function Save
int WriteDescr( FILE* File ); * writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
int ReadDescr( FILE* File, int* LineNum = NULL ); int ReadDescr( FILE* File, int* LineNum = NULL );
/* drawing functions */ /* drawing functions */
......
...@@ -535,6 +535,7 @@ TRACK* TRACK::GetEndNetCode( int NetCode ) ...@@ -535,6 +535,7 @@ TRACK* TRACK::GetEndNetCode( int NetCode )
} }
#if 0 // replaced by Save()
/********************************************/ /********************************************/
bool TRACK::WriteTrackDescr( FILE* File ) bool TRACK::WriteTrackDescr( FILE* File )
/********************************************/ /********************************************/
...@@ -558,6 +559,29 @@ bool TRACK::WriteTrackDescr( FILE* File ) ...@@ -558,6 +559,29 @@ bool TRACK::WriteTrackDescr( FILE* File )
return TRUE; return TRUE;
} }
#endif
bool TRACK::Save( FILE* aFile ) const
{
int type = 0;
if( Type() == TYPEVIA )
type = 1;
if( GetState( DELETED ) )
return true;
fprintf( aFile, "Po %d %d %d %d %d %d %d\n", m_Shape,
m_Start.x, m_Start.y, m_End.x, m_End.y, m_Width, m_Drill );
fprintf( aFile, "De %d %d %d %lX %X\n",
m_Layer, type, GetNet(),
m_TimeStamp, ReturnStatus() );
return true;
}
/*********************************************************************/ /*********************************************************************/
......
...@@ -59,8 +59,15 @@ public: ...@@ -59,8 +59,15 @@ public:
/* supprime du chainage la structure Struct */ /* supprime du chainage la structure Struct */
void UnLink(); void UnLink();
// Read/write data
bool WriteTrackDescr( FILE* File ); /**
* Function Save
* writes the data structures for this object out to a FILE in "*.pcb" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
/** /**
* Function Insert * Function Insert
......
...@@ -102,7 +102,7 @@ void DRAWSEGMENT::Copy( DRAWSEGMENT* source ) ...@@ -102,7 +102,7 @@ void DRAWSEGMENT::Copy( DRAWSEGMENT* source )
m_TimeStamp = source->m_TimeStamp; m_TimeStamp = source->m_TimeStamp;
} }
#if 0 // replaced by Save()
/********************************************************/ /********************************************************/
bool DRAWSEGMENT::WriteDrawSegmentDescr( FILE* File ) bool DRAWSEGMENT::WriteDrawSegmentDescr( FILE* File )
/********************************************************/ /********************************************************/
...@@ -121,6 +121,36 @@ bool DRAWSEGMENT::WriteDrawSegmentDescr( FILE* File ) ...@@ -121,6 +121,36 @@ bool DRAWSEGMENT::WriteDrawSegmentDescr( FILE* File )
fprintf( File, "$EndDRAWSEGMENT\n" ); fprintf( File, "$EndDRAWSEGMENT\n" );
return TRUE; return TRUE;
} }
#endif
bool DRAWSEGMENT::Save( FILE* aFile ) const
{
if( GetState( DELETED ) )
return true;
bool rc = false;
if( fprintf( aFile, "$DRAWSEGMENT\n" ) != sizeof("%DRAWSEGMENT\n")-1 )
goto out;
fprintf( aFile, "Po %d %d %d %d %d %d\n",
m_Shape,
m_Start.x, m_Start.y,
m_End.x, m_End.y, m_Width );
fprintf( aFile, "De %d %d %d %lX %X\n",
m_Layer, m_Type, m_Angle,
m_TimeStamp, ReturnStatus() );
if( fprintf( aFile, "$EndDRAWSEGMENT\n" ) != sizeof("$EndDRAWSEGMENT\n")-1 )
goto out;
rc = true;
out:
return rc;
}
/******************************************************************/ /******************************************************************/
......
...@@ -234,7 +234,7 @@ int WinEDA_PcbFrame::LoadOnePcbFile( const wxString& FullFileName, wxDC * DC, bo ...@@ -234,7 +234,7 @@ int WinEDA_PcbFrame::LoadOnePcbFile( const wxString& FullFileName, wxDC * DC, bo
g_SaveTime = time( NULL ); g_SaveTime = time( NULL );
#if 0 && defined(DEBUG) #if 1 && defined(DEBUG)
// note this seems to freeze up pcbnew when run under the kicad project // note this seems to freeze up pcbnew when run under the kicad project
// manager. runs fine from command prompt. // manager. runs fine from command prompt.
// output the board object tree to stdout: // output the board object tree to stdout:
......
...@@ -1070,7 +1070,7 @@ int WinEDA_PcbFrame::ReadPcbFile( wxDC* DC, FILE* File, bool Append ) ...@@ -1070,7 +1070,7 @@ int WinEDA_PcbFrame::ReadPcbFile( wxDC* DC, FILE* File, bool Append )
#ifdef PCBNEW #ifdef PCBNEW
/***************************************************/ /***************************************************/
int WinEDA_PcbFrame::SavePcbFormatAscii( FILE* File ) int WinEDA_PcbFrame::SavePcbFormatAscii( FILE* aFile )
/****************************************************/ /****************************************************/
/* Routine de sauvegarde du PCB courant sous format ASCII /* Routine de sauvegarde du PCB courant sous format ASCII
...@@ -1079,139 +1079,35 @@ int WinEDA_PcbFrame::SavePcbFormatAscii( FILE* File ) ...@@ -1079,139 +1079,35 @@ int WinEDA_PcbFrame::SavePcbFormatAscii( FILE* File )
* 0 si sauvegarde non faite * 0 si sauvegarde non faite
*/ */
{ {
int ii, NbModules, nseg; bool rc;
float Pas; char line[256];
char Line[256];
EQUIPOT* Equipot;
TRACK* PtSegm;
EDA_BaseStruct* PtStruct;
MODULE* Module;
wxBeginBusyCursor();
m_Pcb->m_Status_Pcb &= ~CONNEXION_OK; m_Pcb->m_Status_Pcb &= ~CONNEXION_OK;
/* Calcul du nombre des modules */ wxBeginBusyCursor();
PtStruct = (EDA_BaseStruct*) m_Pcb->m_Modules;
NbModules = 0;
for( ; PtStruct != NULL; PtStruct = PtStruct->Pnext )
NbModules++;
// Switch the locale to standard C (needed to print floating point numbers like 1.3) // Switch the locale to standard C (needed to print floating point numbers like 1.3)
setlocale( LC_NUMERIC, "C" ); setlocale( LC_NUMERIC, "C" );
/* Ecriture de l'entete PCB : */
fprintf( File, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB,
DateAndTime( Line ) );
WriteGeneralDescrPcb( File );
WriteSheetDescr( m_CurrentScreen, File );
WriteSetup( File, this );
/* Ecriture des donnes utiles du pcb */
Equipot = m_Pcb->m_Equipots;
Pas = 100.0;
if( m_Pcb->m_NbNets )
Pas /= m_Pcb->m_NbNets;
for( ii = 0; Equipot != NULL; ii++, Equipot = (EQUIPOT*) Equipot->Pnext )
{
Equipot->WriteEquipotDescr( File );
DisplayActivity( (int) ( Pas * ii ), wxT( "Equipot:" ) );
}
Pas = 100.0;
if( NbModules )
Pas /= NbModules;
Module = m_Pcb->m_Modules;
for( ii = 1; Module != NULL; Module = Module->Next(), ii++ )
{
Module->WriteDescr( File );
DisplayActivity( (int) (ii * Pas), wxT( "Modules:" ) );
}
/* sortie des inscriptions du PCB: */
PtStruct = m_Pcb->m_Drawings;
for( ; PtStruct != NULL; PtStruct = PtStruct->Pnext )
{
switch( PtStruct->Type() )
{
case TYPETEXTE:
( (TEXTE_PCB*) PtStruct )->WriteTextePcbDescr( File );
break;
case TYPEDRAWSEGMENT:
( (DRAWSEGMENT*) PtStruct )->WriteDrawSegmentDescr( File );
break;
case TYPEMIRE:
( (MIREPCB*) PtStruct )->WriteMirePcbDescr( File );
break;
case TYPECOTATION: /* Ecriture de l'entete PCB : */
( (COTATION*) PtStruct )->WriteCotationDescr( File ); fprintf( aFile, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB,
break; DateAndTime( line ) );
case TYPEMARQUEUR: /* sauvegarde inutile */
break;
default:
DisplayError( this, wxT( "Unknown Draw Type" ) );
break;
}
}
Pas = 100.0;
if( m_Pcb->m_NbSegmTrack )
Pas /= (m_Pcb->m_NbSegmTrack);
fprintf( File, "$TRACK\n" );
PtSegm = m_Pcb->m_Track;
DisplayActivity( 0, wxT( "Tracks:" ) );
for( nseg = 0, ii = 0; PtSegm != NULL; ii++, PtSegm = (TRACK*) PtSegm->Pnext )
{
( (TRACK*) PtSegm )->WriteTrackDescr( File );
if( nseg != (int) ( ii * Pas) )
{
nseg = (int) ( ii * Pas);
DisplayActivity( nseg, wxT( "Tracks:" ) );
}
}
fprintf( File, "$EndTRACK\n" );
fprintf( File, "$ZONE\n" );
PtSegm = (TRACK*) m_Pcb->m_Zone;
ii = m_Pcb->m_NbSegmZone;
Pas = 100.0; WriteGeneralDescrPcb( aFile );
if( ii ) WriteSheetDescr( m_CurrentScreen, aFile );
Pas /= ii; WriteSetup( aFile, this );
PtSegm = m_Pcb->m_Zone; rc = m_Pcb->Save( aFile );
DisplayActivity( 0, wxT( "Zones:" ) );
for( nseg = 0, ii = 0; PtSegm != NULL; ii++, PtSegm = (TRACK*) PtSegm->Pnext )
{
( (TRACK*) PtSegm )->WriteTrackDescr( File );
if( nseg != (int) ( ii * Pas) )
{
nseg = (int) ( ii * Pas);
DisplayActivity( nseg, wxT( "Zones:" ) );
}
}
fprintf( File, "$EndZONE\n" );
fprintf( File, "$EndBOARD\n" );
setlocale( LC_NUMERIC, "" ); // revert to the current locale setlocale( LC_NUMERIC, "" ); // revert to the current locale
wxEndBusyCursor(); wxEndBusyCursor();
if( !rc )
DisplayError( this, wxT( "Unable to save PCB file" ) );
else
Affiche_Message( wxEmptyString ); Affiche_Message( wxEmptyString );
return 1;
return rc;
} }
#endif #endif
/***************************************/ /***************************************/
/* Gestion de la LIBRAIRIE des MODULES */ /* Gestion de la LIBRAIRIE des MODULES */
/***************************************/ /***************************************/
/* Fichier LIBRAIRI.CPP */ /* Fichier LIBRAIRI.CPP */
#include "fctsys.h" #include "fctsys.h"
#include "gr_basic.h" #include "gr_basic.h"
...@@ -13,38 +13,39 @@ ...@@ -13,38 +13,39 @@
#include "protos.h" #include "protos.h"
/* /*
Format de l'entete de la Librairie: * Format de l'entete de la Librairie:
chaine ENTETE-LIBRAIRIE date-heure * chaine ENTETE-LIBRAIRIE date-heure
$INDEX * $INDEX
liste des noms modules ( 1 nom par ligne) * liste des noms modules ( 1 nom par ligne)
$EndINDEX * $EndINDEX
liste des descriptions des Modules * liste des descriptions des Modules
$EndLIBRARY * $EndLIBRARY
*/ */
#define OLD_EXT wxT(".bak") #define OLD_EXT wxT( ".bak" )
#define FILETMP_EXT wxT(".$$$") #define FILETMP_EXT wxT( ".$$$" )
/* Fonctions locales */ /* Fonctions locales */
static bool CreateDocLibrary(const wxString & LibName); static bool CreateDocLibrary( const wxString& LibName );
/*********************************************************/ /*********************************************************/
MODULE * WinEDA_ModuleEditFrame::Import_Module(wxDC * DC) MODULE* WinEDA_ModuleEditFrame::Import_Module( wxDC* DC )
/*********************************************************/ /*********************************************************/
/* /*
Importation de modules Hors librairie * Importation de modules Hors librairie
Lit 1 fichier type Empreinte et place le module sur PCB * Lit 1 fichier type Empreinte et place le module sur PCB
*/ */
{ {
int NbLine = 0; int NbLine = 0;
char Line[1024]; char Line[1024];
wxString CmpFullFileName; wxString CmpFullFileName;
FILE * dest; FILE* dest;
MODULE * module = NULL; MODULE* module = NULL;
/* Lecture Fichier module */ /* Lecture Fichier module */
CmpFullFileName = EDA_FileSelector( _("Import Module:"), CmpFullFileName = EDA_FileSelector( _( "Import Module:" ),
wxEmptyString, /* Chemin par defaut */ wxEmptyString, /* Chemin par defaut */
wxEmptyString, /* nom fichier par defaut */ wxEmptyString, /* nom fichier par defaut */
EXT_CMP, /* extension par defaut */ EXT_CMP, /* extension par defaut */
...@@ -54,33 +55,36 @@ MODULE * module = NULL; ...@@ -54,33 +55,36 @@ MODULE * module = NULL;
TRUE TRUE
); );
if ( CmpFullFileName == wxEmptyString ) return NULL; if( CmpFullFileName == wxEmptyString )
return NULL;
if ( (dest = wxFopen(CmpFullFileName, wxT("rt")) ) == NULL ) if( ( dest = wxFopen( CmpFullFileName, wxT( "rt" ) ) ) == NULL )
{ {
wxString msg; wxString msg;
msg.Printf( _("File <%s> not found"), CmpFullFileName.GetData()); msg.Printf( _( "File <%s> not found" ), CmpFullFileName.GetData() );
DisplayError(this, msg) ; DisplayError( this, msg );
return NULL; return NULL;
} }
/* Lecture Entete */ /* Lecture Entete */
GetLine(dest, Line, &NbLine); GetLine( dest, Line, &NbLine );
if(strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0) if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
{ {
DisplayError(this, _("Not a module file")); DisplayError( this, _( "Not a module file" ) );
return NULL; return NULL;
} }
/* Lecture du fichier: recherche du debut de la descr module */ /* Lecture du fichier: recherche du debut de la descr module */
while( GetLine(dest, Line, &NbLine) != NULL) while( GetLine( dest, Line, &NbLine ) != NULL )
{ {
if(strnicmp( Line,"$MODULE",7) == 0) break; if( strnicmp( Line, "$MODULE", 7 ) == 0 )
break;
} }
module = new MODULE(m_Pcb); module = new MODULE( m_Pcb );
module->ReadDescr(dest, &NbLine);
fclose(dest); module->ReadDescr( dest, &NbLine );
fclose( dest );
/* Mise a jour du chainage */ /* Mise a jour du chainage */
if( m_Pcb->m_Modules ) if( m_Pcb->m_Modules )
...@@ -92,27 +96,30 @@ MODULE * module = NULL; ...@@ -92,27 +96,30 @@ MODULE * module = NULL;
m_Pcb->m_Modules = module; m_Pcb->m_Modules = module;
/* Affichage des caracteristiques : */ /* Affichage des caracteristiques : */
module->Display_Infos(this); module->Display_Infos( this );
Place_Module(module, DC) ; Place_Module( module, DC );
m_Pcb->m_Status_Pcb = 0 ; m_Pcb->m_Status_Pcb = 0;
build_liste_pads(); build_liste_pads();
return module; return module;
} }
/************************************************************************/ /************************************************************************/
void WinEDA_ModuleEditFrame::Export_Module(MODULE* ptmod, bool createlib) void WinEDA_ModuleEditFrame::Export_Module( MODULE* ptmod, bool createlib )
/************************************************************************/ /************************************************************************/
/* /*
Genere 1 fichier type Empreinte a partir de la description du module sur PCB * Genere 1 fichier type Empreinte a partir de la description du module sur PCB
*/ */
{ {
wxString FullFileName, Mask( wxT("*") ); wxString FullFileName, Mask( wxT( "*" ) );
char Line[1025]; char Line[1025];
FILE * dest; FILE* dest;
wxString msg, path; wxString msg, path;
if ( ptmod == NULL ) return; if( ptmod == NULL )
return;
ptmod->m_LibRef = ptmod->m_Reference->m_Text; ptmod->m_LibRef = ptmod->m_Reference->m_Text;
FullFileName = ptmod->m_LibRef; FullFileName = ptmod->m_LibRef;
...@@ -120,8 +127,9 @@ wxString msg, path; ...@@ -120,8 +127,9 @@ wxString msg, path;
Mask += createlib ? LibExtBuffer : EXT_CMP; Mask += createlib ? LibExtBuffer : EXT_CMP;
if ( createlib ) path = g_RealLibDirBuffer; if( createlib )
FullFileName = EDA_FileSelector( createlib ? _("Create lib") : _("Export Module:"), path = g_RealLibDirBuffer;
FullFileName = EDA_FileSelector( createlib ? _( "Create lib" ) : _( "Export Module:" ),
path, /* Chemin par defaut */ path, /* Chemin par defaut */
FullFileName, /* nom fichier par defaut */ FullFileName, /* nom fichier par defaut */
createlib ? LibExtBuffer : EXT_CMP, /* extension par defaut */ createlib ? LibExtBuffer : EXT_CMP, /* extension par defaut */
...@@ -131,221 +139,235 @@ wxString msg, path; ...@@ -131,221 +139,235 @@ wxString msg, path;
TRUE TRUE
); );
if ( FullFileName.IsEmpty() ) return; if( FullFileName.IsEmpty() )
return;
if ( createlib && wxFileExists(FullFileName) ) if( createlib && wxFileExists( FullFileName ) )
{ {
msg.Printf( _("File %s exists, OK to replace ?"), msg.Printf( _( "File %s exists, OK to replace ?" ),
FullFileName.GetData()); FullFileName.GetData() );
if( ! IsOK(this, msg) ) return; if( !IsOK( this, msg ) )
return;
} }
/* Generation du fichier Empreinte */ /* Generation du fichier Empreinte */
if ( (dest = wxFopen(FullFileName, wxT("wt")) ) == NULL ) if( ( dest = wxFopen( FullFileName, wxT( "wt" ) ) ) == NULL )
{ {
msg.Printf( _("Unable to create <%s>"),FullFileName.GetData()) ; msg.Printf( _( "Unable to create <%s>" ), FullFileName.GetData() );
DisplayError(this, msg) ; DisplayError( this, msg );
return ; return;
} }
fprintf(dest,"%s %s\n", ENTETE_LIBRAIRIE, DateAndTime(Line)); fprintf( dest, "%s %s\n", ENTETE_LIBRAIRIE, DateAndTime( Line ) );
fputs("$INDEX\n",dest); fputs( "$INDEX\n", dest );
fprintf(dest,"%s\n", CONV_TO_UTF8(ptmod->m_LibRef) ); fprintf( dest, "%s\n", CONV_TO_UTF8( ptmod->m_LibRef ) );
fputs("$EndINDEX\n",dest); fputs( "$EndINDEX\n", dest );
m_Pcb->m_Modules->WriteDescr(dest); m_Pcb->m_Modules->Save( dest );
fputs("$EndLIBRARY\n",dest); fputs( "$EndLIBRARY\n", dest );
fclose(dest) ; fclose( dest );
msg.Printf( _("Module exported in file <%s>"),FullFileName.GetData()) ; msg.Printf( _( "Module exported in file <%s>" ), FullFileName.GetData() );
DisplayInfo(this, msg) ; DisplayInfo( this, msg );
} }
/**********************************************************/ /**********************************************************/
void WinEDA_ModuleEditFrame::Delete_Module_In_Library(const void WinEDA_ModuleEditFrame::Delete_Module_In_Library( const
wxString & libname) wxString& libname )
/**********************************************************/ /**********************************************************/
{ {
int ii, NoFound = 1, LineNum = 0; int ii, NoFound = 1, LineNum = 0;
char Line[1024], Name[256]; char Line[1024], Name[256];
wxString NewLib, OldLib; wxString NewLib, OldLib;
FILE * dest, * lib_module; FILE* dest, * lib_module;
wxString CmpName, msg; wxString CmpName, msg;
/* Demande du nom du composant a supprimer */ /* Demande du nom du composant a supprimer */
CmpName = Select_1_Module_From_List( this, libname, wxEmptyString, wxEmptyString ); CmpName = Select_1_Module_From_List( this, libname, wxEmptyString, wxEmptyString );
if( CmpName == wxEmptyString ) return; if( CmpName == wxEmptyString )
return;
/* Confirmation */ /* Confirmation */
msg.Printf( _("Ok to delete module %s in library %s"), msg.Printf( _( "Ok to delete module %s in library %s" ),
CmpName.GetData(), libname.GetData() ); CmpName.GetData(), libname.GetData() );
if( !IsOK(this, msg) ) return; if( !IsOK( this, msg ) )
return;
OldLib = libname; OldLib = libname;
if ((lib_module = wxFopen( OldLib, wxT("rt"))) == NULL ) if( ( lib_module = wxFopen( OldLib, wxT( "rt" ) ) ) == NULL )
{ {
wxString msg; wxString msg;
msg = _("Library ") + OldLib + _(" not found"); msg = _( "Library " ) + OldLib + _( " not found" );
DisplayError(this, msg); DisplayError( this, msg );
return; return;
} }
/* lecture entete */ /* lecture entete */
GetLine(lib_module,Line, &LineNum) ; GetLine( lib_module, Line, &LineNum );
if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0) if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
{ {
DisplayError(this, _("Not a Library file")); DisplayError( this, _( "Not a Library file" ) );
fclose(lib_module); fclose( lib_module );
return; return;
} }
/* lecture des nom des composants */ /* lecture des nom des composants */
while( GetLine(lib_module, Line, &LineNum) ) while( GetLine( lib_module, Line, &LineNum ) )
{ {
if( strnicmp( Line, "$INDEX",6) == 0 ) if( strnicmp( Line, "$INDEX", 6 ) == 0 )
{ {
while( GetLine(lib_module, Line, &LineNum) ) while( GetLine( lib_module, Line, &LineNum ) )
{ {
StrPurge(Line); StrPurge( Line );
msg = CONV_FROM_UTF8(Line); msg = CONV_FROM_UTF8( Line );
if( CmpName.CmpNoCase(msg) == 0) /* composant trouve */ if( CmpName.CmpNoCase( msg ) == 0 ) /* composant trouve */
{ {
NoFound = 0; break; NoFound = 0; break;
} }
if( strnicmp( Line, "$EndINDEX",9) == 0 ) break; if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
break;
} }
} }
if( strnicmp( Line, "$EndINDEX",9) == 0 ) break; if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
break;
} }
if( NoFound ) if( NoFound )
{ {
fclose(lib_module); fclose( lib_module );
msg.Printf( _("Module [%s] not found"), CmpName.GetData() ); msg.Printf( _( "Module [%s] not found" ), CmpName.GetData() );
DisplayError(this, msg); DisplayError( this, msg );
return ; return;
} }
/* Creation de la nouvelle librairie */ /* Creation de la nouvelle librairie */
NewLib = OldLib; NewLib = OldLib;
ChangeFileNameExt(NewLib,FILETMP_EXT); ChangeFileNameExt( NewLib, FILETMP_EXT );
if ((dest = wxFopen(NewLib, wxT("wt") )) == NULL ) if( ( dest = wxFopen( NewLib, wxT( "wt" ) ) ) == NULL )
{ {
fclose(lib_module) ; fclose( lib_module );
wxString msg; wxString msg;
msg = _("Unable to create ") + NewLib; msg = _( "Unable to create " ) + NewLib;
DisplayError(this, msg); DisplayError( this, msg );
return; return;
} }
wxBeginBusyCursor(); wxBeginBusyCursor();
/* Creation de l'entete avec nouvelle date */ /* Creation de l'entete avec nouvelle date */
fprintf(dest,ENTETE_LIBRAIRIE); fprintf( dest, ENTETE_LIBRAIRIE );
fprintf(dest," %s\n$INDEX\n", DateAndTime(Line) ); fprintf( dest, " %s\n$INDEX\n", DateAndTime( Line ) );
fseek(lib_module,0,0); GetLine(lib_module, Line, &ii); fseek( lib_module, 0, 0 ); GetLine( lib_module, Line, &ii );
while(GetLine(lib_module,Line, &ii)) while( GetLine( lib_module, Line, &ii ) )
{ {
if ( strnicmp(Line,"$M",2 ) == 0 ) break; if( strnicmp( Line, "$M", 2 ) == 0 )
if ( strnicmp(Line,"$INDEX",6 ) == 0 ) break;
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
{ {
while(GetLine(lib_module,Line, &ii)) while( GetLine( lib_module, Line, &ii ) )
{ {
if ( strnicmp(Line,"$EndINDEX",9 ) == 0 ) break; if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
StrPurge(Line); break;
msg = CONV_FROM_UTF8(Line); StrPurge( Line );
if( CmpName.CmpNoCase(msg) != 0 ) msg = CONV_FROM_UTF8( Line );
fprintf(dest,"%s\n",Line); if( CmpName.CmpNoCase( msg ) != 0 )
fprintf( dest, "%s\n", Line );
} }
} }
if ( strnicmp(Line,"$EndINDEX",9 ) == 0 ) break; if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
break;
} }
fprintf(dest,"$EndINDEX\n"); fprintf( dest, "$EndINDEX\n" );
/* Copie des modules */ /* Copie des modules */
while( GetLine(lib_module, Line, &LineNum) ) while( GetLine( lib_module, Line, &LineNum ) )
{ {
StrPurge(Line); StrPurge( Line );
if( strnicmp( Line, "$MODULE", 7) == 0 ) if( strnicmp( Line, "$MODULE", 7 ) == 0 )
{ {
sscanf(Line+7," %s", Name); sscanf( Line + 7, " %s", Name );
msg = CONV_FROM_UTF8(Name); msg = CONV_FROM_UTF8( Name );
if( msg.CmpNoCase(CmpName) == 0 ) if( msg.CmpNoCase( CmpName ) == 0 )
{ {
/* suppression ancien module */ /* suppression ancien module */
while( GetLine(lib_module, Line, &LineNum) ) while( GetLine( lib_module, Line, &LineNum ) )
{ {
if( strnicmp( Line, "$EndMODULE", 9) == 0 ) break; if( strnicmp( Line, "$EndMODULE", 9 ) == 0 )
break;
} }
continue; continue;
} }
} }
fprintf(dest, "%s\n", Line); fprintf( dest, "%s\n", Line );
} }
fclose(lib_module); fclose( lib_module );
fclose(dest) ; fclose( dest );
wxEndBusyCursor(); wxEndBusyCursor();
/* Le fichier ancienne librairie est renommee en .bak */ /* Le fichier ancienne librairie est renommee en .bak */
wxString BakFilename = OldLib; wxString BakFilename = OldLib;
ChangeFileNameExt( BakFilename, OLD_EXT); ChangeFileNameExt( BakFilename, OLD_EXT );
if( wxFileExists(BakFilename) ) wxRemoveFile(BakFilename); if( wxFileExists( BakFilename ) )
wxRemoveFile( BakFilename );
if( ! wxRenameFile(OldLib, BakFilename) ) if( !wxRenameFile( OldLib, BakFilename ) )
{ {
DisplayError(this, wxT("Librairi.cpp: rename .bak err")); DisplayError( this, wxT( "Librairi.cpp: rename .bak err" ) );
return; return;
} }
/* Le fichier temporaire est renommee comme l'ancienne Lib */ /* Le fichier temporaire est renommee comme l'ancienne Lib */
if( ! wxRenameFile(NewLib,OldLib) ) if( !wxRenameFile( NewLib, OldLib ) )
{ {
DisplayError(this, wxT("Librairi.cpp: rename err 2") ); DisplayError( this, wxT( "Librairi.cpp: rename err 2" ) );
return; return;
} }
msg.Printf( _("Component %s deleted in library %s"), CmpName.GetData(), OldLib.GetData() ) ; msg.Printf( _( "Component %s deleted in library %s" ), CmpName.GetData(), OldLib.GetData() );
Affiche_Message(msg) ; Affiche_Message( msg );
CreateDocLibrary(OldLib); CreateDocLibrary( OldLib );
} }
/***********************************************************************/ /***********************************************************************/
void WinEDA_BasePcbFrame::Archive_Modules(const wxString & LibName, void WinEDA_BasePcbFrame::Archive_Modules( const wxString& LibName,
bool NewModulesOnly) bool NewModulesOnly )
/***********************************************************************/ /***********************************************************************/
/* /*
Sauve en Librairie: * Sauve en Librairie:
tous les nouveaux modules ( c.a.d. les modules * tous les nouveaux modules ( c.a.d. les modules
n'existant pas deja (si NewModulesOnly == TRUE) * n'existant pas deja (si NewModulesOnly == TRUE)
tous les modules (si NewModulesOnly == FALSE) * tous les modules (si NewModulesOnly == FALSE)
*/ */
{ {
int ii, NbModules = 0; int ii, NbModules = 0;
float Pas; float Pas;
MODULE * Module; MODULE* Module;
wxString FullFileName = LibName; wxString FullFileName = LibName;
if ( m_Pcb->m_Modules == NULL ) if( m_Pcb->m_Modules == NULL )
{ {
DisplayInfo(this, _(" No modules to archive!") ); DisplayInfo( this, _( " No modules to archive!" ) );
return; return;
} }
if ( FullFileName.IsEmpty() ) if( FullFileName.IsEmpty() )
{ {
wxString Mask = wxT("*") + LibExtBuffer; wxString Mask = wxT( "*" ) + LibExtBuffer;
FullFileName = EDA_FileSelector( _("Library"), FullFileName = EDA_FileSelector( _( "Library" ),
g_RealLibDirBuffer, /* Chemin par defaut */ g_RealLibDirBuffer, /* Chemin par defaut */
FullFileName, /* nom fichier par defaut */ FullFileName, /* nom fichier par defaut */
LibExtBuffer, /* extension par defaut */ LibExtBuffer, /* extension par defaut */
...@@ -355,84 +377,91 @@ wxString FullFileName = LibName; ...@@ -355,84 +377,91 @@ wxString FullFileName = LibName;
TRUE TRUE
); );
if ( FullFileName.IsEmpty() ) return; if( FullFileName.IsEmpty() )
return;
} }
bool file_exists = wxFileExists(FullFileName); bool file_exists = wxFileExists( FullFileName );
if ( ! NewModulesOnly && file_exists ) if( !NewModulesOnly && file_exists )
{ {
wxString msg; wxString msg;
msg.Printf( _("File %s exists, OK to replace ?"), FullFileName.GetData()); msg.Printf( _( "File %s exists, OK to replace ?" ), FullFileName.GetData() );
if( ! IsOK(this, msg) ) return; if( !IsOK( this, msg ) )
return;
} }
DrawPanel->m_AbortRequest = FALSE; DrawPanel->m_AbortRequest = FALSE;
// Create a new, empty library if no old lib, or if archive all modules // Create a new, empty library if no old lib, or if archive all modules
if ( ! NewModulesOnly || ! file_exists ) if( !NewModulesOnly || !file_exists )
{ {
FILE * lib_module; FILE* lib_module;
if ((lib_module = wxFopen(FullFileName, wxT("w+t"))) == NULL ) if( ( lib_module = wxFopen( FullFileName, wxT( "w+t" ) ) ) == NULL )
{ {
wxString msg = _("Unable to create ") + FullFileName; wxString msg = _( "Unable to create " ) + FullFileName;
DisplayError(this, msg); DisplayError( this, msg );
return; return;
} }
char Line[256]; char Line[256];
fprintf(lib_module,"%s %s\n", ENTETE_LIBRAIRIE, DateAndTime(Line)); fprintf( lib_module, "%s %s\n", ENTETE_LIBRAIRIE, DateAndTime( Line ) );
fputs("$INDEX\n",lib_module); fputs( "$INDEX\n", lib_module );
fputs("$EndINDEX\n",lib_module); fputs( "$EndINDEX\n", lib_module );
fputs("$EndLIBRARY\n",lib_module); fputs( "$EndLIBRARY\n", lib_module );
fclose(lib_module) ; fclose( lib_module );
} }
/* Calcul du nombre de modules */ /* Calcul du nombre de modules */
Module = (MODULE *) m_Pcb->m_Modules; Module = (MODULE*) m_Pcb->m_Modules;
for( ;Module != NULL; Module = (MODULE *)Module->Pnext) NbModules++; for( ; Module != NULL; Module = (MODULE*) Module->Pnext )
NbModules++;
Pas = (float) 100 / NbModules; Pas = (float) 100 / NbModules;
DisplayActivity(0, wxEmptyString); DisplayActivity( 0, wxEmptyString );
Module = (MODULE *) m_Pcb->m_Modules; Module = (MODULE*) m_Pcb->m_Modules;
for( ii = 1 ;Module != NULL; ii++, Module = (MODULE *)Module->Pnext) for( ii = 1; Module != NULL; ii++, Module = (MODULE*) Module->Pnext )
{ {
if( Save_1_Module(FullFileName, Module, if( Save_1_Module( FullFileName, Module,
NewModulesOnly ? FALSE : TRUE, FALSE) == 0 ) break; NewModulesOnly ? FALSE : TRUE, FALSE ) == 0 )
DisplayActivity((int)( ii * Pas) , wxEmptyString); break;
DisplayActivity( (int) ( ii * Pas), wxEmptyString );
/* Tst demande d'arret de sauvegarde ( key ESCAPE actionnee ) */ /* Tst demande d'arret de sauvegarde ( key ESCAPE actionnee ) */
if( DrawPanel->m_AbortRequest ) break; if( DrawPanel->m_AbortRequest )
break;
} }
CreateDocLibrary(LibName); CreateDocLibrary( LibName );
} }
/*****************************************************************/ /*****************************************************************/
int WinEDA_BasePcbFrame::Save_1_Module(const wxString & LibName, int WinEDA_BasePcbFrame::Save_1_Module( const wxString& LibName,
MODULE* Module, bool Overwrite, bool DisplayDialog) MODULE* Module, bool Overwrite, bool DisplayDialog )
/*****************************************************************/ /*****************************************************************/
/*
sauve en Librairie le module Module:
si no_replace == TRUE, s'il est nouveau.
retourne /*
1 si OK * sauve en Librairie le module Module:
0 si abort ou probleme * si no_replace == TRUE, s'il est nouveau.
*/ *
* retourne
* 1 si OK
* 0 si abort ou probleme
*/
{ {
int newmodule, end; int newmodule, end;
int LineNum = 0, tmp; int LineNum = 0, tmp;
char Name[256], Line[1024]; char Name[256], Line[1024];
wxString Name_Cmp; wxString Name_Cmp;
wxString NewLib, OldLib, msg; wxString NewLib, OldLib, msg;
FILE * lib_module, *dest; FILE* lib_module, * dest;
bool added = TRUE; bool added = TRUE;
Module->Display_Infos(this); Module->Display_Infos( this );
if ( ! wxFileExists(LibName) ) if( !wxFileExists( LibName ) )
{ {
msg.Printf( _("Library %s not found"), LibName.GetData()); msg.Printf( _( "Library %s not found" ), LibName.GetData() );
DisplayError(this, msg); DisplayError( this, msg );
return 0; return 0;
} }
...@@ -442,198 +471,211 @@ bool added = TRUE; ...@@ -442,198 +471,211 @@ bool added = TRUE;
if( DisplayDialog ) if( DisplayDialog )
{ {
Get_Message(_("Name:"), Name_Cmp, this ) ; Get_Message( _( "Name:" ), Name_Cmp, this );
if( Name_Cmp.IsEmpty() ) return(0); if( Name_Cmp.IsEmpty() )
Name_Cmp.Trim(TRUE); return 0;
Name_Cmp.Trim(FALSE); Name_Cmp.Trim( TRUE );
Name_Cmp.Trim( FALSE );
Module->m_LibRef = Name_Cmp; Module->m_LibRef = Name_Cmp;
} }
if ((lib_module = wxFopen(LibName, wxT("rt"))) == NULL ) if( ( lib_module = wxFopen( LibName, wxT( "rt" ) ) ) == NULL )
{ {
msg.Printf( _("Unable to open %s"), LibName.GetData()); msg.Printf( _( "Unable to open %s" ), LibName.GetData() );
DisplayError(this, msg); DisplayError( this, msg );
return 0; return 0;
} }
/* lecture entete : ENTETE_LIBRAIRIE */ /* lecture entete : ENTETE_LIBRAIRIE */
GetLine(lib_module, Line, &LineNum) ; GetLine( lib_module, Line, &LineNum );
if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0) if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
{ {
fclose(lib_module) ; fclose( lib_module );
msg.Printf( _("File %s is not a eeschema library"), LibName.GetData()); msg.Printf( _( "File %s is not a eeschema library" ), LibName.GetData() );
DisplayError(this, msg); DisplayError( this, msg );
return(0); return 0;
} }
/* lecture des noms des composants - verif si le module est deja existant */ /* lecture des noms des composants - verif si le module est deja existant */
newmodule = 1; end = 0; newmodule = 1; end = 0;
while( !end && GetLine(lib_module, Line, &LineNum) ) while( !end && GetLine( lib_module, Line, &LineNum ) )
{ {
if( Line[0] != '$' ) continue; if( Line[0] != '$' )
if( strncmp( Line+1, "INDEX",5) != 0 ) continue; continue;
if( strncmp( Line + 1, "INDEX", 5 ) != 0 )
continue;
while( GetLine(lib_module, Line, &LineNum) ) while( GetLine( lib_module, Line, &LineNum ) )
{ {
if( strncmp( Line, "$EndINDEX",9) == 0 ) if( strncmp( Line, "$EndINDEX", 9 ) == 0 )
{ {
end = 1; break; end = 1; break;
} }
StrPurge(Line); StrPurge( Line );
msg = CONV_FROM_UTF8(Line); msg = CONV_FROM_UTF8( Line );
if( Name_Cmp.CmpNoCase(msg) == 0) /* composant trouve */ if( Name_Cmp.CmpNoCase( msg ) == 0 ) /* composant trouve */
{ {
added = FALSE; added = FALSE;
newmodule = 0; newmodule = 0;
if( DisplayDialog ) if( DisplayDialog )
{ {
msg = _("Module exists Line "); msg = _( "Module exists Line " );
msg << LineNum; msg << LineNum;
Affiche_Message(msg) ; Affiche_Message( msg );
} }
if( ! Overwrite) /* le module n'est pas a sauver car deja existant */ if( !Overwrite ) /* le module n'est pas a sauver car deja existant */
{ {
fclose(lib_module); return(1); fclose( lib_module ); return 1;
} }
end = 1; break; end = 1; break;
} }
} }
} }
fclose(lib_module);
fclose( lib_module );
/* Creation de la nouvelle librairie */ /* Creation de la nouvelle librairie */
if ((lib_module = wxFopen(LibName, wxT("rt"))) == NULL ) if( ( lib_module = wxFopen( LibName, wxT( "rt" ) ) ) == NULL )
{ {
DisplayError(this, wxT("Librairi.cpp: Error oldlib not found")); DisplayError( this, wxT( "Librairi.cpp: Error oldlib not found" ) );
return(0); return 0;
} }
NewLib = LibName; NewLib = LibName;
ChangeFileNameExt(NewLib, FILETMP_EXT); ChangeFileNameExt( NewLib, FILETMP_EXT );
if ((dest = wxFopen(NewLib, wxT("w+t"))) == NULL ) if( ( dest = wxFopen( NewLib, wxT( "w+t" ) ) ) == NULL )
{ {
fclose(lib_module) ; fclose( lib_module );
msg = _("Unable to create ") + NewLib; msg = _( "Unable to create " ) + NewLib;
DisplayError(this, msg); DisplayError( this, msg );
return(0); return 0;
} }
wxBeginBusyCursor() ; wxBeginBusyCursor();
/* Creation de l'entete avec nouvelle date */ /* Creation de l'entete avec nouvelle date */
fprintf(dest,ENTETE_LIBRAIRIE); fprintf( dest, ENTETE_LIBRAIRIE );
fprintf(dest," %s\n$INDEX\n", DateAndTime(Line) ); fprintf( dest, " %s\n$INDEX\n", DateAndTime( Line ) );
LineNum = 0; LineNum = 0;
GetLine(lib_module, Line, &LineNum); GetLine( lib_module, Line, &LineNum );
while(GetLine(lib_module,Line, &LineNum)) while( GetLine( lib_module, Line, &LineNum ) )
{ {
StrPurge(Line); StrPurge( Line );
if ( strnicmp(Line,"$M",2 ) == 0 ) break; if( strnicmp( Line, "$M", 2 ) == 0 )
if ( strnicmp(Line,"$INDEX",6 ) == 0 ) break;
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
{ {
while(GetLine(lib_module,Line, &LineNum)) while( GetLine( lib_module, Line, &LineNum ) )
{ {
if ( strnicmp(Line,"$EndINDEX",9 ) == 0 ) break; if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
fprintf(dest,"%s\n",Line); break;
fprintf( dest, "%s\n", Line );
} }
} }
if(newmodule) fprintf(dest,"%s\n",CONV_TO_UTF8(Name_Cmp) ); if( newmodule )
if ( strnicmp(Line,"$EndINDEX",0 ) == 0 ) break; fprintf( dest, "%s\n", CONV_TO_UTF8( Name_Cmp ) );
if( strnicmp( Line, "$EndINDEX", 0 ) == 0 )
break;
} }
fprintf(dest,"$EndINDEX\n"); fprintf( dest, "$EndINDEX\n" );
/* Copie des modules, jusqu'au module a supprimer */ /* Copie des modules, jusqu'au module a supprimer */
while( GetLine(lib_module, Line, &LineNum) ) while( GetLine( lib_module, Line, &LineNum ) )
{ {
StrPurge(Line); StrPurge( Line );
if( strnicmp( Line, "$EndLIBRARY", 8) == 0 ) continue; if( strnicmp( Line, "$EndLIBRARY", 8 ) == 0 )
if( strnicmp( Line, "$MODULE", 7) == 0 ) continue;
if( strnicmp( Line, "$MODULE", 7 ) == 0 )
{ {
sscanf(Line+7," %s", Name); sscanf( Line + 7, " %s", Name );
msg = CONV_FROM_UTF8(Name); msg = CONV_FROM_UTF8( Name );
if( msg.CmpNoCase(Name_Cmp) == 0 ) if( msg.CmpNoCase( Name_Cmp ) == 0 )
{ {
/* suppression ancien module */ /* suppression ancien module */
while( GetLine(lib_module, Line, &LineNum) ) while( GetLine( lib_module, Line, &LineNum ) )
{ {
if( strnicmp( Line, "$EndMODULE", 9) == 0 ) break; if( strnicmp( Line, "$EndMODULE", 9 ) == 0 )
break;
} }
continue; continue;
} }
} }
fprintf(dest,"%s\n",Line); fprintf( dest, "%s\n", Line );
} }
/* Ecriture du module ( en fin de librairie ) */ /* Ecriture du module ( en fin de librairie ) */
tmp = Module->m_TimeStamp; Module->m_TimeStamp = 0; tmp = Module->m_TimeStamp; Module->m_TimeStamp = 0;
Module->WriteDescr(dest); Module->Save( dest );
fprintf(dest,"$EndLIBRARY\n"); fprintf( dest, "$EndLIBRARY\n" );
Module->m_TimeStamp = tmp; Module->m_TimeStamp = tmp;
fclose(dest) ; fclose(lib_module) ; fclose( dest ); fclose( lib_module );
wxEndBusyCursor() ; wxEndBusyCursor();
/* L'ancien fichier librairie est renomme en .bak */ /* L'ancien fichier librairie est renomme en .bak */
OldLib = LibName; OldLib = LibName;
ChangeFileNameExt ( OldLib, OLD_EXT); ChangeFileNameExt( OldLib, OLD_EXT );
if( wxFileExists(OldLib) ) wxRemoveFile(OldLib); if( wxFileExists( OldLib ) )
wxRemoveFile( OldLib );
if ( ! wxRenameFile(LibName, OldLib ) ) if( !wxRenameFile( LibName, OldLib ) )
DisplayError(this, wxT("Librairi.cpp: rename .bak err") ); DisplayError( this, wxT( "Librairi.cpp: rename .bak err" ) );
/* Le nouveau fichier librairie est renomme */ /* Le nouveau fichier librairie est renomme */
if ( ! wxRenameFile(NewLib,LibName) ) if( !wxRenameFile( NewLib, LibName ) )
{ {
DisplayError(this, wxT("Librairi.cpp: rename NewLib err") ); DisplayError( this, wxT( "Librairi.cpp: rename NewLib err" ) );
return(0); return 0;
} }
CreateDocLibrary(OldLib); CreateDocLibrary( OldLib );
if ( DisplayDialog ) if( DisplayDialog )
{ {
msg = _("Component ") ; msg += Name_Cmp; msg = _( "Component " ); msg += Name_Cmp;
msg += added ? _(" added in ") : _(" replaced in "); msg += added ? _( " added in " ) : _( " replaced in " );
msg += LibName; msg += LibName;
Affiche_Message(msg); Affiche_Message( msg );
} }
return(1); return 1;
} }
/************************************************************************************/ /************************************************************************************/
MODULE * WinEDA_BasePcbFrame::Create_1_Module(wxDC * DC, const wxString & module_name) MODULE* WinEDA_BasePcbFrame::Create_1_Module( wxDC* DC, const wxString& module_name )
/************************************************************************************/ /************************************************************************************/
/* Creation d'un module : On place d'office les 2ers textes : /* Creation d'un module : On place d'office les 2ers textes :
1er = type REF: nom du module * 1er = type REF: nom du module
2eme = type VALEUR: "VAL**" * 2eme = type VALEUR: "VAL**"
Le module est insere en debut de liste des modules * Le module est insere en debut de liste des modules
*/ */
{ {
MODULE* Module ; MODULE* Module;
wxString Line; wxString Line;
wxPoint newpos; wxPoint newpos;
/* Demande du nom du nouveau module */ /* Demande du nom du nouveau module */
if ( module_name.IsEmpty() ) if( module_name.IsEmpty() )
{ {
if ( Get_Message( _("Module Reference:"), Line, this ) != 0 ) return NULL; if( Get_Message( _( "Module Reference:" ), Line, this ) != 0 )
return NULL;
} }
else
Line = module_name;
Line.Trim( TRUE );
Line.Trim( FALSE );
else Line = module_name; Module = new MODULE( m_Pcb );
Line.Trim(TRUE);
Line.Trim(FALSE);
Module = new MODULE(m_Pcb);
Module->Pnext = m_Pcb->m_Modules; Module->Pnext = m_Pcb->m_Modules;
Module->Pback = m_Pcb; Module->Pback = m_Pcb;
...@@ -644,28 +686,28 @@ wxPoint newpos; ...@@ -644,28 +686,28 @@ wxPoint newpos;
m_Pcb->m_Modules = Module; m_Pcb->m_Modules = Module;
/* Creation du module : On place d'office les 2 textes ref et val : /* Creation du module : On place d'office les 2 textes ref et val :
1er = type REF: nom du module * 1er = type REF: nom du module
2eme = type VALEUR: "VAL**" */ * 2eme = type VALEUR: "VAL**" */
/* Mise a jour des caract du nouveau module */ /* Mise a jour des caract du nouveau module */
newpos = m_CurrentScreen->m_Curseur; newpos = m_CurrentScreen->m_Curseur;
Module->SetPosition(newpos); Module->SetPosition( newpos );
Module->m_LastEdit_Time = time(NULL); Module->m_LastEdit_Time = time( NULL );
/* Mise a jour du nom de Librairie (reference libr) */ /* Mise a jour du nom de Librairie (reference libr) */
Module->m_LibRef = Line; Module->m_LibRef = Line;
/* Mise a jour de la reference: */ /* Mise a jour de la reference: */
Module->m_Reference->m_Text = Line; Module->m_Reference->m_Text = Line;
Module->m_Reference->SetWidth(ModuleTextWidth); Module->m_Reference->SetWidth( ModuleTextWidth );
Module->m_Reference->m_Size = ModuleTextSize; Module->m_Reference->m_Size = ModuleTextSize;
/* mise a jour de la valeurs */ /* mise a jour de la valeurs */
Module->m_Value->m_Text = wxT("VAL**"); Module->m_Value->m_Text = wxT( "VAL**" );
Module->m_Value->SetWidth(ModuleTextWidth); Module->m_Value->SetWidth( ModuleTextWidth );
Module->m_Value->m_Size = ModuleTextSize; Module->m_Value->m_Size = ModuleTextSize;
Module->Display_Infos(this); Module->Display_Infos( this );
return Module; return Module;
} }
...@@ -674,114 +716,117 @@ wxPoint newpos; ...@@ -674,114 +716,117 @@ wxPoint newpos;
void WinEDA_ModuleEditFrame::Select_Active_Library() void WinEDA_ModuleEditFrame::Select_Active_Library()
/*******************************************************/ /*******************************************************/
{ {
if ( g_LibName_List.GetCount() == 0 ) return; if( g_LibName_List.GetCount() == 0 )
return;
WinEDAListBox * LibListBox = new WinEDAListBox(this, _("Active Lib:"), WinEDAListBox* LibListBox = new WinEDAListBox( this, _( "Active Lib:" ),
NULL, m_CurrentLib, NULL, wxColour(200, 200, 255) ); NULL, m_CurrentLib, NULL, wxColour( 200, 200, 255 ) );
LibListBox->InsertItems(g_LibName_List); LibListBox->InsertItems( g_LibName_List );
int ii = LibListBox->ShowModal(); int ii = LibListBox->ShowModal();
if ( ii >= 0 ) m_CurrentLib = LibListBox->GetTextSelection(); if( ii >= 0 )
m_CurrentLib = LibListBox->GetTextSelection();
LibListBox->Destroy(); LibListBox->Destroy();
SetTitle( _("Module Editor (lib: ") + m_CurrentLib + wxT(")") ); SetTitle( _( "Module Editor (lib: " ) + m_CurrentLib + wxT( ")" ) );
return; return;
} }
/**********************************************************************/ /**********************************************************************/
int WinEDA_ModuleEditFrame::Create_Librairie(const wxString & LibName) int WinEDA_ModuleEditFrame::Create_Librairie( const wxString& LibName )
/**********************************************************************/ /**********************************************************************/
{ {
FILE * lib_module; FILE* lib_module;
wxString msg; wxString msg;
if ( wxFileExists(LibName) ) if( wxFileExists( LibName ) )
{ {
msg = _("Library exists ") + LibName; msg = _( "Library exists " ) + LibName;
DisplayError(this, msg); DisplayError( this, msg );
return(0); return 0;
} }
if ((lib_module = wxFopen(LibName, wxT("wt") )) == NULL ) if( ( lib_module = wxFopen( LibName, wxT( "wt" ) ) ) == NULL )
{ {
msg = _("Unable to create ") + LibName; msg = _( "Unable to create " ) + LibName;
DisplayError(this, msg); DisplayError( this, msg );
return(-1); return -1;
} }
/* Ecriture de l'entete de la nouvelle librairie */ /* Ecriture de l'entete de la nouvelle librairie */
if( fprintf(lib_module,ENTETE_LIBRAIRIE) == 0) if( fprintf( lib_module, ENTETE_LIBRAIRIE ) == 0 )
{ {
msg = _("Create error ") + LibName; msg = _( "Create error " ) + LibName;
DisplayError(this, msg); DisplayError( this, msg );
fclose(lib_module) ; return(-1); fclose( lib_module ); return -1;
} }
fprintf(lib_module," %s\n", DateAndTime(cbuf)); fprintf( lib_module, " %s\n", DateAndTime( cbuf ) );
fputs("$INDEX\n",lib_module); fputs( "$INDEX\n", lib_module );
fputs("$EndINDEX\n",lib_module); fputs( "$EndINDEX\n", lib_module );
fclose(lib_module) ; fclose( lib_module );
return(1); return 1;
} }
/******************************************************/ /******************************************************/
static bool CreateDocLibrary(const wxString & LibName) static bool CreateDocLibrary( const wxString& LibName )
/*****************************************************/ /*****************************************************/
/* Creation du fichier .dcm associe a la librairie LibName /* Creation du fichier .dcm associe a la librairie LibName
(full file name) * (full file name)
*/ */
{ {
char Line[1024]; char Line[1024];
wxString Name, Doc, KeyWord; wxString Name, Doc, KeyWord;
wxString LibDocName; wxString LibDocName;
FILE * LibMod, *LibDoc; FILE* LibMod, * LibDoc;
LibDocName = LibName; LibDocName = LibName;
ChangeFileNameExt(LibDocName, EXT_DOC); ChangeFileNameExt( LibDocName, EXT_DOC );
LibMod = wxFopen( LibName, wxT("rt") ); LibMod = wxFopen( LibName, wxT( "rt" ) );
if ( LibMod == NULL ) return FALSE; if( LibMod == NULL )
return FALSE;
/* lecture entete librairie*/ /* lecture entete librairie*/
GetLine(LibMod, Line, NULL, sizeof(Line) -1); GetLine( LibMod, Line, NULL, sizeof(Line) - 1 );
if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0) if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
{ {
fclose(LibMod); fclose( LibMod );
return FALSE; return FALSE;
} }
LibDoc = wxFopen( LibDocName, wxT("wt") ); LibDoc = wxFopen( LibDocName, wxT( "wt" ) );
if ( LibDoc == NULL ) if( LibDoc == NULL )
{ {
fclose( LibMod ); fclose( LibMod );
return FALSE; return FALSE;
} }
fprintf(LibDoc,ENTETE_LIBDOC); fprintf( LibDoc, ENTETE_LIBDOC );
fprintf(LibDoc," %s\n", DateAndTime(cbuf)); fprintf( LibDoc, " %s\n", DateAndTime( cbuf ) );
/* Lecture de la librairie */ /* Lecture de la librairie */
Name = Doc = KeyWord = wxEmptyString; Name = Doc = KeyWord = wxEmptyString;
while( GetLine(LibMod,Line, NULL, sizeof(Line) -1) ) while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) )
{ {
if( Line[0] != '$' ) continue; if( Line[0] != '$' )
if( strnicmp( Line, "$MODULE",6) == 0 ) continue;
if( strnicmp( Line, "$MODULE", 6 ) == 0 )
{ {
while( GetLine(LibMod,Line, NULL, sizeof(Line) -1) ) while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) )
{ {
if( Line[0] == '$' ) if( Line[0] == '$' )
{ {
if( Line[1] == 'E' ) break; if( Line[1] == 'E' )
break;
if( Line[1] == 'P' ) /* Pad Descr */ if( Line[1] == 'P' ) /* Pad Descr */
{ {
while( GetLine(LibMod,Line, NULL, sizeof(Line) -1) ) while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) )
{ {
if( (Line[0] == '$') && (Line[1] == 'E') ) if( (Line[0] == '$') && (Line[1] == 'E') )
break; break;
...@@ -789,43 +834,46 @@ FILE * LibMod, *LibDoc; ...@@ -789,43 +834,46 @@ FILE * LibMod, *LibDoc;
} }
} }
if( Line[0] == 'L' ) /* LibName */ if( Line[0] == 'L' ) /* LibName */
Name = CONV_FROM_UTF8(StrPurge(Line+3)); Name = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
if( Line[0] == 'K' ) /* KeyWords */ if( Line[0] == 'K' ) /* KeyWords */
KeyWord = CONV_FROM_UTF8(StrPurge(Line+3)); KeyWord = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
if( Line[0] == 'C' ) /* Doc */ if( Line[0] == 'C' ) /* Doc */
Doc = CONV_FROM_UTF8(StrPurge(Line+3)); Doc = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
} }
if( (Name != wxEmptyString) && ((Doc != wxEmptyString) || (KeyWord != wxEmptyString)) )/* Generation de la doc du composant */ if( (Name != wxEmptyString) && ( (Doc != wxEmptyString) || (KeyWord != wxEmptyString) ) )/* Generation de la doc du composant */
{ {
fprintf(LibDoc,"#\n$MODULE %s\n",CONV_TO_UTF8(Name)); fprintf( LibDoc, "#\n$MODULE %s\n", CONV_TO_UTF8( Name ) );
fprintf(LibDoc,"Li %s\n",CONV_TO_UTF8(Name)); fprintf( LibDoc, "Li %s\n", CONV_TO_UTF8( Name ) );
if( Doc != wxEmptyString) if( Doc != wxEmptyString )
fprintf( LibDoc,"Cd %s\n", CONV_TO_UTF8(Doc)); fprintf( LibDoc, "Cd %s\n", CONV_TO_UTF8( Doc ) );
if( KeyWord != wxEmptyString) if( KeyWord != wxEmptyString )
fprintf( LibDoc,"Kw %s\n", CONV_TO_UTF8(KeyWord)); fprintf( LibDoc, "Kw %s\n", CONV_TO_UTF8( KeyWord ) );
fprintf( LibDoc,"$EndMODULE\n"); fprintf( LibDoc, "$EndMODULE\n" );
} }
Name = Doc = KeyWord = wxEmptyString; Name = Doc = KeyWord = wxEmptyString;
} /* Fin lecture desc 1 module */ } /* Fin lecture desc 1 module */
if( strnicmp( Line,"$INDEX",6) == 0 ) if( strnicmp( Line, "$INDEX", 6 ) == 0 )
{ {
while( GetLine(LibMod,Line, NULL, sizeof(Line)-1) ) while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) )
{ {
if( strnicmp( Line,"$EndINDEX",9) == 0 ) break; if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
} /* Fin Lecture INDEX */ break;
}
/* Fin Lecture INDEX */
} }
} /* Fin lecture 1 Librairie */ }
/* Fin lecture 1 Librairie */
fclose( LibMod ); fclose( LibMod );
fprintf( LibDoc,"#\n$EndLIBDOC\n"); fprintf( LibDoc, "#\n$EndLIBDOC\n" );
fclose( LibDoc ); fclose( LibDoc );
return TRUE; return TRUE;
} }
...@@ -17,17 +17,17 @@ ...@@ -17,17 +17,17 @@
void Trace_Pistes( WinEDA_DrawPanel* panel, BOARD* Pcb, wxDC* DC, int drawmode ) void Trace_Pistes( WinEDA_DrawPanel* panel, BOARD* Pcb, wxDC* DC, int drawmode )
/********************************************************************************/ /********************************************************************************/
/* Draw all tracks and zones. /* Draw all tracks and zones. As long as dark colors are used for the tracks,
* Then the OR draw mode should show tracks underneath other tracks. But a white
* track will cover any other color since it has more bits to OR in.
*/ */
{ {
TRACK * track = Pcb->m_Track; for( TRACK* track = Pcb->m_Track; track; track = track->Next() )
for( ; track != NULL; track = track->Next() )
{ {
track->Draw( panel, DC, drawmode ); track->Draw( panel, DC, drawmode );
} }
SEGZONE * zone = Pcb->m_Zone; for( SEGZONE* zone = Pcb->m_Zone; zone; zone = zone->Next() )
for( ; zone != NULL; zone = zone->Next() )
{ {
zone->Draw( panel, DC, drawmode ); zone->Draw( panel, DC, drawmode );
} }
...@@ -51,12 +51,8 @@ void Trace_Une_Piste( WinEDA_DrawPanel* panel, wxDC* DC, TRACK* Track, ...@@ -51,12 +51,8 @@ void Trace_Une_Piste( WinEDA_DrawPanel* panel, wxDC* DC, TRACK* Track,
* donc mis a 0 avant appel a la routine si la piste a tracer est la derniere * donc mis a 0 avant appel a la routine si la piste a tracer est la derniere
*/ */
{ {
if( Track == NULL ) for( ; nbsegment > 0 && Track; nbsegment--, Track = Track->Next() )
return;
for( ; nbsegment > 0; nbsegment--, Track = (TRACK*) Track->Pnext )
{ {
if( Track == NULL )
break;
Track->Draw( panel, DC, draw_mode ); Track->Draw( panel, DC, draw_mode );
} }
} }
......
...@@ -384,25 +384,23 @@ void WinEDA_ZoneFrame::ExecFillZone( wxCommandEvent& event ) ...@@ -384,25 +384,23 @@ void WinEDA_ZoneFrame::ExecFillZone( wxCommandEvent& event )
/**************************************************************/ /**************************************************************/
void WinEDA_PcbFrame::Edit_Zone_Width( wxDC* DC, SEGZONE* Zone ) void WinEDA_PcbFrame::Edit_Zone_Width( wxDC* DC, SEGZONE* aZone )
/**************************************************************/ /**************************************************************/
/* Edite (change la largeur des segments) la zone Zone. /* Edite (change la largeur des segments) la zone Zone.
* La zone est constituee des segments zones de meme TimeStamp * La zone est constituee des segments zones de meme TimeStamp
*/ */
{ {
SEGZONE* pt_segm, * NextS;
unsigned long TimeStamp;
bool modify = FALSE; bool modify = FALSE;
double f_new_width; double f_new_width;
int w_tmp; int w_tmp;
wxString Line; wxString Line;
wxString Msg( _( "New zone segment width: " ) ); wxString Msg( _( "New zone segment width: " ) );
if( Zone == NULL ) if( aZone == NULL )
return; return;
f_new_width = To_User_Unit( g_UnitMetric, Zone->m_Width, GetScreen()->GetInternalUnits() ); f_new_width = To_User_Unit( g_UnitMetric, aZone->m_Width, GetScreen()->GetInternalUnits() );
Line.Printf( wxT( "%.4f" ), f_new_width ); Line.Printf( wxT( "%.4f" ), f_new_width );
...@@ -417,15 +415,12 @@ void WinEDA_PcbFrame::Edit_Zone_Width( wxDC* DC, SEGZONE* Zone ) ...@@ -417,15 +415,12 @@ void WinEDA_PcbFrame::Edit_Zone_Width( wxDC* DC, SEGZONE* Zone )
f_new_width, GetScreen( f_new_width, GetScreen(
)->GetInternalUnits() ); )->GetInternalUnits() );
TimeStamp = Zone->m_TimeStamp; for( SEGZONE* zone = m_Pcb->m_Zone; zone; zone = zone->Next() )
for( pt_segm = (SEGZONE*) m_Pcb->m_Zone; pt_segm != NULL; pt_segm = NextS )
{ {
NextS = (SEGZONE*) pt_segm->Pnext; if( zone->m_TimeStamp == aZone->m_TimeStamp )
if( pt_segm->m_TimeStamp == TimeStamp )
{ {
modify = TRUE; modify = TRUE;
Edit_TrackSegm_Width( DC, pt_segm ); Edit_TrackSegm_Width( DC, zone );
} }
} }
...@@ -446,22 +441,23 @@ void WinEDA_PcbFrame::Delete_Zone( wxDC* DC, SEGZONE* Zone ) ...@@ -446,22 +441,23 @@ void WinEDA_PcbFrame::Delete_Zone( wxDC* DC, SEGZONE* Zone )
* La zone est constituee des segments zones de meme TimeStamp * La zone est constituee des segments zones de meme TimeStamp
*/ */
{ {
SEGZONE* pt_segm, * NextS;
unsigned long TimeStamp; unsigned long TimeStamp;
int nb_segm = 0; int nb_segm = 0;
bool modify = FALSE; bool modify = FALSE;
TimeStamp = Zone->m_TimeStamp; TimeStamp = Zone->m_TimeStamp;
for( pt_segm = (SEGZONE*) m_Pcb->m_Zone; pt_segm != NULL; pt_segm = NextS ) SEGZONE* next;
for( SEGZONE* zone = m_Pcb->m_Zone; zone; zone = next )
{ {
NextS = (SEGZONE*) pt_segm->Pnext; next = zone->Next();
if( pt_segm->m_TimeStamp == TimeStamp ) if( zone->m_TimeStamp == TimeStamp )
{ {
modify = TRUE; modify = TRUE;
/* effacement des segments a l'ecran */ /* effacement des segments a l'ecran */
Trace_Une_Piste( DrawPanel, DC, pt_segm, nb_segm, GR_XOR ); Trace_Une_Piste( DrawPanel, DC, zone, nb_segm, GR_XOR );
pt_segm ->DeleteStructure(); zone->DeleteStructure();
} }
} }
...@@ -694,8 +690,7 @@ EDGE_ZONE* WinEDA_PcbFrame::Begin_Zone() ...@@ -694,8 +690,7 @@ EDGE_ZONE* WinEDA_PcbFrame::Begin_Zone()
else /* piste en cours : les coord du point d'arrivee ont ete mises else /* piste en cours : les coord du point d'arrivee ont ete mises
* a jour par la routine Show_Zone_Edge_While_MoveMouse*/ * a jour par la routine Show_Zone_Edge_While_MoveMouse*/
{ {
if( (oldedge->m_Start.x != oldedge->m_End.x) if( oldedge->m_Start != oldedge->m_End )
|| (oldedge->m_Start.y != oldedge->m_End.y) )
{ {
newedge = new EDGE_ZONE( oldedge ); newedge = new EDGE_ZONE( oldedge );
newedge->Pback = oldedge; newedge->Pback = oldedge;
...@@ -834,11 +829,15 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC ) ...@@ -834,11 +829,15 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC )
DisplayError( this, wxT( "Board is empty!" ), 10 ); DisplayError( this, wxT( "Board is empty!" ), 10 );
return; return;
} }
DrawPanel->m_IgnoreMouseEvents = TRUE; DrawPanel->m_IgnoreMouseEvents = TRUE;
WinEDA_ZoneFrame* frame = new WinEDA_ZoneFrame( this ); WinEDA_ZoneFrame* frame = new WinEDA_ZoneFrame( this );
ii = frame->ShowModal(); frame->Destroy();
ii = frame->ShowModal();
frame->Destroy();
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = FALSE;
if( ii ) if( ii )
return; return;
...@@ -856,7 +855,9 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC ) ...@@ -856,7 +855,9 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC )
s_TimeStamp = time( NULL ); s_TimeStamp = time( NULL );
/* Calcul du pas de routage fixe a 5 mils et plus */ /* Calcul du pas de routage fixe a 5 mils et plus */
E_scale = g_GridRoutingSize / 50; if( g_GridRoutingSize < 1 ) E_scale = g_GridRoutingSize / 50;
if( g_GridRoutingSize < 1 )
g_GridRoutingSize = 1; g_GridRoutingSize = 1;
/* calcule de Ncols et Nrow, taille de la matrice de routage */ /* calcule de Ncols et Nrow, taille de la matrice de routage */
...@@ -865,8 +866,10 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC ) ...@@ -865,8 +866,10 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC )
/* Determination de la cellule pointee par la souris */ /* Determination de la cellule pointee par la souris */
ZoneStartFill.x = ( GetScreen()->m_Curseur.x - m_Pcb->m_BoundaryBox.m_Pos.x + ZoneStartFill.x = ( GetScreen()->m_Curseur.x - m_Pcb->m_BoundaryBox.m_Pos.x +
(g_GridRoutingSize / 2) ) / g_GridRoutingSize; (g_GridRoutingSize / 2) ) / g_GridRoutingSize;
ZoneStartFill.y = ( GetScreen()->m_Curseur.y - m_Pcb->m_BoundaryBox.m_Pos.y + ZoneStartFill.y = ( GetScreen()->m_Curseur.y - m_Pcb->m_BoundaryBox.m_Pos.y +
(g_GridRoutingSize / 2) ) / g_GridRoutingSize; (g_GridRoutingSize / 2) ) / g_GridRoutingSize;
if( ZoneStartFill.x < 0 ) if( ZoneStartFill.x < 0 )
ZoneStartFill.x = 0; ZoneStartFill.x = 0;
if( ZoneStartFill.x >= Ncols ) if( ZoneStartFill.x >= Ncols )
...@@ -886,8 +889,10 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC ) ...@@ -886,8 +889,10 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC )
msg.Printf( wxT( "%d" ), Ncols ); msg.Printf( wxT( "%d" ), Ncols );
Affiche_1_Parametre( this, 1, wxT( "Cols" ), msg, GREEN ); Affiche_1_Parametre( this, 1, wxT( "Cols" ), msg, GREEN );
msg.Printf( wxT( "%d" ), Nrows ); msg.Printf( wxT( "%d" ), Nrows );
Affiche_1_Parametre( this, 7, wxT( "Lines" ), msg, GREEN ); Affiche_1_Parametre( this, 7, wxT( "Lines" ), msg, GREEN );
msg.Printf( wxT( "%d" ), Board.m_MemSize / 1024 ); msg.Printf( wxT( "%d" ), Board.m_MemSize / 1024 );
Affiche_1_Parametre( this, 14, wxT( "Mem(Ko)" ), msg, CYAN ); Affiche_1_Parametre( this, 14, wxT( "Mem(Ko)" ), msg, CYAN );
...@@ -922,10 +927,13 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC ) ...@@ -922,10 +927,13 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC )
{ {
if( g_HightLigth_NetCode != pt_segm->GetNet() ) if( g_HightLigth_NetCode != pt_segm->GetNet() )
continue; continue;
if( pt_segm->GetLayer() != GetScreen()->m_Active_Layer ) if( pt_segm->GetLayer() != GetScreen()->m_Active_Layer )
continue; continue;
if( pt_segm->Type() != TYPETRACK ) if( pt_segm->Type() != TYPETRACK )
continue; continue;
TraceSegmentPcb( m_Pcb, pt_segm, CELL_is_FRIEND, 0, WRITE_CELL ); TraceSegmentPcb( m_Pcb, pt_segm, CELL_is_FRIEND, 0, WRITE_CELL );
} }
......
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