From 64e9e16886532004796a500856462259713db41e Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Tue, 30 Oct 2007 21:30:58 +0000 Subject: [PATCH] virtual BOARD_ITEM::Save() --- change_log.txt | 22 +- common/base_struct.cpp | 2 +- gerbview/export_to_pcbnew.cpp | 88 +-- include/base_struct.h | 13 +- include/pcbstruct.h | 19 +- pcbnew/class_board.cpp | 67 ++ pcbnew/class_cotation.cpp | 68 ++ pcbnew/class_cotation.h | 9 +- pcbnew/class_edge_mod.cpp | 54 ++ pcbnew/class_edge_mod.h | 10 +- pcbnew/class_equipot.cpp | 27 + pcbnew/class_equipot.h | 10 +- pcbnew/class_marker.h | 14 + pcbnew/class_mire.cpp | 29 + pcbnew/class_mire.h | 9 +- pcbnew/class_module.cpp | 103 ++- pcbnew/class_module.h | 12 +- pcbnew/class_pad.cpp | 88 +++ pcbnew/class_pad.h | 12 +- pcbnew/class_pcb_text.cpp | 31 + pcbnew/class_pcb_text.h | 10 +- pcbnew/class_text_mod.cpp | 22 + pcbnew/class_text_mod.h | 12 +- pcbnew/class_track.cpp | 24 + pcbnew/class_track.h | 13 +- pcbnew/classpcb.cpp | 32 +- pcbnew/files.cpp | 2 +- pcbnew/ioascii.cpp | 146 +--- pcbnew/librairi.cpp | 1354 +++++++++++++++++---------------- pcbnew/trpiste.cpp | 16 +- pcbnew/zones.cpp | 52 +- 31 files changed, 1469 insertions(+), 901 deletions(-) diff --git a/change_log.txt b/change_log.txt index 9406a9e159..7ab7f3283d 100644 --- a/change_log.txt +++ b/change_log.txt @@ -4,17 +4,33 @@ Started 2007-June-11 Please add newer entries at the top, list the date and your name with email address. +2007-Oct-30 UPDATE Dick Hollenbeck +================================================================================ ++ 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 ================================================================================ +cvpcb: listboxes.cpp problem solved: exists only under windows now apply to windows only, because this Workaround creates a problem undex linux - +others: some very minor problems solved - +eeschema: in B.O.M.: the footprint field can be added to the field list + 2007-Oct-29 UPDATE Jean-Pierre Charras ================================================================================ +cvpcb: listboxes.cpp problem solved: Workaround for a curious bug in wxWidgets: @@ -33,12 +49,10 @@ email address. + all: remove unused files. some translations - +cvpcb: set flag wxFRAME_FLOAT_ON_PARENT when create the footprint 3D frame and the display frame minor other changes - + pcbnew: Use collector class to locate items in modedit. This is a big enhancement, diff --git a/common/base_struct.cpp b/common/base_struct.cpp index f11abbfb0e..07d7c71b6c 100644 --- a/common/base_struct.cpp +++ b/common/base_struct.cpp @@ -58,7 +58,7 @@ void EDA_BaseStruct::InitVars() /* 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; } diff --git a/gerbview/export_to_pcbnew.cpp b/gerbview/export_to_pcbnew.cpp index ee06c34220..7f904e66e4 100644 --- a/gerbview/export_to_pcbnew.cpp +++ b/gerbview/export_to_pcbnew.cpp @@ -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 ) /*******************************************************************/ @@ -136,20 +136,17 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File, * @return 1 if OK, 0 if fail */ { - char Line[256]; + char line[256]; TRACK* track; - TRACK* next_track; - BOARD_ITEM* PtStruct; - BOARD_ITEM* NextStruct; - BOARD* GerberPcb = frame->m_Pcb; - BOARD* Pcb; + BOARD* gerberPcb = frame->m_Pcb; + BOARD* pcb; wxBeginBusyCursor(); - /* Create an image of gerber data */ - Pcb = new BOARD( NULL, frame ); + // create an image of gerber data + 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 pcb_layer_number = LayerLookUpTable[layer]; @@ -158,23 +155,23 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File, if( pcb_layer_number > CMP_N ) { - DRAWSEGMENT* drawitem = new DRAWSEGMENT( NULL, TYPEDRAWSEGMENT ); + DRAWSEGMENT* drawitem = new DRAWSEGMENT( pcb, TYPEDRAWSEGMENT ); drawitem->SetLayer( pcb_layer_number ); drawitem->m_Start = track->m_Start; drawitem->m_End = track->m_End; drawitem->m_Width = track->m_Width; - drawitem->Pnext = Pcb->m_Drawings; - Pcb->m_Drawings = drawitem; + drawitem->Pnext = pcb->m_Drawings; + pcb->m_Drawings = drawitem; } else { TRACK* newtrack; // replace spots with vias when possible - if( (track->m_Shape == S_SPOT_CIRCLE) - || (track->m_Shape == S_SPOT_RECT) - || (track->m_Shape == S_SPOT_OVALE) ) + if( track->m_Shape == S_SPOT_CIRCLE + || track->m_Shape == S_SPOT_RECT + || track->m_Shape == S_SPOT_OVALE ) { newtrack = new SEGVIA( (const SEGVIA&) *track ); @@ -198,19 +195,20 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File, newtrack->SetLayer( pcb_layer_number ); } - newtrack->Insert( Pcb, NULL ); + newtrack->Insert( pcb, NULL ); } } // 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 ) continue; // Search and delete others vias + TRACK* next_track; 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(); if( alt_track->m_Shape != VIA_THROUGH ) @@ -229,54 +227,16 @@ static int SavePcbFormatAscii( WinEDA_GerberFrame* frame, FILE* File, setlocale( LC_NUMERIC, "C" ); // write the PCB heading - fprintf( File, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB, - DateAndTime( Line ) ); - WriteGeneralDescrPcb( Pcb, File ); - WriteSetup( File, Pcb ); + fprintf( aFile, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB, + DateAndTime( line ) ); + WriteGeneralDescrPcb( pcb, aFile ); + WriteSetup( aFile, pcb ); // write the useful part of the pcb - PtStruct = Pcb->m_Drawings; - for( ; PtStruct != NULL; PtStruct = PtStruct->Next() ) - { - switch( PtStruct->Type() ) - { - case TYPETEXTE: - ( (TEXTE_PCB*) PtStruct )->WriteTextePcbDescr( File ); - break; + pcb->Save( aFile ); - 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 wxEndBusyCursor(); diff --git a/include/base_struct.h b/include/base_struct.h index 353d758af3..332ac8dde4 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -191,7 +191,7 @@ public: /* 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 ); int ReturnStatus() const { return m_Status; } @@ -490,6 +490,17 @@ public: * @todo: make this virtual and split into each derived class */ 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; + + }; diff --git a/include/pcbstruct.h b/include/pcbstruct.h index 79b1eeafa6..33ec8ab585 100644 --- a/include/pcbstruct.h +++ b/include/pcbstruct.h @@ -287,6 +287,15 @@ public: * @return EQUIPOT* - the net or NULL if not found. */ 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; /** @@ -370,7 +379,15 @@ public: ~DRAWSEGMENT(); // 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 ); /* remove this from the linked list */ diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index dcc34934af..7a72e2fcc2 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -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) /** diff --git a/pcbnew/class_cotation.cpp b/pcbnew/class_cotation.cpp index 5134da292a..255c2c64f8 100644 --- a/pcbnew/class_cotation.cpp +++ b/pcbnew/class_cotation.cpp @@ -227,6 +227,7 @@ bool COTATION::ReadCotationDescr( FILE* File, int* LineNum ) } +#if 0 /**************************************************/ bool COTATION::WriteCotationDescr( FILE* File ) /**************************************************/ @@ -285,6 +286,73 @@ bool COTATION::WriteCotationDescr( FILE* File ) 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; +} + + /************************************************************************/ diff --git a/pcbnew/class_cotation.h b/pcbnew/class_cotation.h index 75d5c9264b..6b22c32b45 100644 --- a/pcbnew/class_cotation.h +++ b/pcbnew/class_cotation.h @@ -29,8 +29,15 @@ public: ~COTATION(); 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 */ void UnLink(); diff --git a/pcbnew/class_edge_mod.cpp b/pcbnew/class_edge_mod.cpp index 465638b840..a709e506ee 100644 --- a/pcbnew/class_edge_mod.cpp +++ b/pcbnew/class_edge_mod.cpp @@ -298,6 +298,7 @@ void EDGE_MODULE::Display_Infos( WinEDA_DrawFrame* frame ) } +#if 0 // replaced by Save() /*****************************************/ int EDGE_MODULE::WriteDescr( FILE* File ) /*****************************************/ @@ -358,6 +359,59 @@ int EDGE_MODULE::WriteDescr( FILE* File ) 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 5); +} + + /****************************************************************/ diff --git a/pcbnew/class_edge_mod.h b/pcbnew/class_edge_mod.h index 28655724c8..e71db6a8d9 100644 --- a/pcbnew/class_edge_mod.h +++ b/pcbnew/class_edge_mod.h @@ -34,8 +34,14 @@ public: 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 ); // Mise a jour des coordon�s pour l'affichage diff --git a/pcbnew/class_equipot.cpp b/pcbnew/class_equipot.cpp index 5eaa24f584..59f432c679 100644 --- a/pcbnew/class_equipot.cpp +++ b/pcbnew/class_equipot.cpp @@ -106,6 +106,7 @@ int EQUIPOT:: ReadEquipotDescr( FILE* File, int* LineNum ) } +#if 0 // replaced by Save() /********************************************/ int EQUIPOT:: WriteEquipotDescr( FILE* File ) /********************************************/ @@ -121,6 +122,32 @@ int EQUIPOT:: WriteEquipotDescr( FILE* File ) fprintf( File, "$EndEQUIPOT\n" ); 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) /** diff --git a/pcbnew/class_equipot.h b/pcbnew/class_equipot.h index 2a92025e90..c78cc4e74f 100644 --- a/pcbnew/class_equipot.h +++ b/pcbnew/class_equipot.h @@ -33,8 +33,16 @@ public: /* Readind and writing data on files */ 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 * @return int - the netcode diff --git a/pcbnew/class_marker.h b/pcbnew/class_marker.h index 81e5162b17..20e6d4a358 100644 --- a/pcbnew/class_marker.h +++ b/pcbnew/class_marker.h @@ -33,6 +33,20 @@ public: 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 * tests if the given wxPoint is within the bounds of this object. diff --git a/pcbnew/class_mire.cpp b/pcbnew/class_mire.cpp index 390b2304e8..41a6accb7a 100644 --- a/pcbnew/class_mire.cpp +++ b/pcbnew/class_mire.cpp @@ -94,6 +94,7 @@ bool MIREPCB::ReadMirePcbDescr( FILE* File, int* LineNum ) } +#if 0 // replaced by Save() /************************************************/ bool MIREPCB::WriteMirePcbDescr( FILE* File ) /************************************************/ @@ -109,6 +110,34 @@ bool MIREPCB::WriteMirePcbDescr( FILE* File ) fprintf( File, "$EndMIREPCB\n" ); 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; +} + + /**********************************************************/ diff --git a/pcbnew/class_mire.h b/pcbnew/class_mire.h index cfc7daf600..3c820422fd 100644 --- a/pcbnew/class_mire.h +++ b/pcbnew/class_mire.h @@ -19,7 +19,14 @@ public: MIREPCB( BOARD_ITEM* StructFather ); ~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 ); /* supprime du chainage la structure Struct */ diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 32c0f22072..b4b2053be3 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -345,6 +345,7 @@ void MODULE::DrawEdgesOnly( WinEDA_DrawPanel* panel, wxDC* DC, } +#if 0 /*************************************/ int MODULE::WriteDescr( FILE* File ) /*************************************/ @@ -489,10 +490,110 @@ int MODULE::WriteDescr( FILE* File ) 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 diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index efc33339ef..08031a5ae0 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -116,8 +116,16 @@ public: /* 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 Read_3D_Descr( FILE* File, int* LineNum = NULL ); diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index 24b70b8fbc..2e81a49104 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -763,6 +763,8 @@ int D_PAD::ReadDescr( FILE* File, int* LineNum ) } + +#if 0 /***********************************/ int D_PAD::WriteDescr( FILE* File ) /***********************************/ @@ -849,6 +851,92 @@ int D_PAD::WriteDescr( FILE* File ) 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; +} + /******************************************************/ diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index 1976ef2647..03ac276325 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -77,8 +77,16 @@ public: /* Reading and writing data on files */ 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 */ void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode ); void Draw3D( Pcb3D_GLCanvas* glcanvas ); diff --git a/pcbnew/class_pcb_text.cpp b/pcbnew/class_pcb_text.cpp index 7165a554c1..a05bcfa0ac 100644 --- a/pcbnew/class_pcb_text.cpp +++ b/pcbnew/class_pcb_text.cpp @@ -112,6 +112,7 @@ int TEXTE_PCB::ReadTextePcbDescr( FILE* File, int* LineNum ) } +#if 0 // replaced by Save() /**************************************************/ int TEXTE_PCB::WriteTextePcbDescr( FILE* File ) /**************************************************/ @@ -129,6 +130,36 @@ int TEXTE_PCB::WriteTextePcbDescr( FILE* File ) fprintf( File, "$EndTEXTPCB\n" ); 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; +} + + /**********************************************************************/ diff --git a/pcbnew/class_pcb_text.h b/pcbnew/class_pcb_text.h index 7ed6c34834..0ba993913b 100644 --- a/pcbnew/class_pcb_text.h +++ b/pcbnew/class_pcb_text.h @@ -24,8 +24,14 @@ public: // File Operations: 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 diff --git a/pcbnew/class_text_mod.cpp b/pcbnew/class_text_mod.cpp index 097bea5cf8..c84115c561 100644 --- a/pcbnew/class_text_mod.cpp +++ b/pcbnew/class_text_mod.cpp @@ -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 { if( source == NULL ) diff --git a/pcbnew/class_text_mod.h b/pcbnew/class_text_mod.h index bacb8293dd..767583842b 100644 --- a/pcbnew/class_text_mod.h +++ b/pcbnew/class_text_mod.h @@ -47,9 +47,15 @@ public: void SetLocalCoord(); // mise a jour des coordonn�s relatives - // a partir des coord absolues de trac� - /* 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( FILE* File, int* LineNum = NULL ); /* drawing functions */ diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index a017078a83..8246a0a39c 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -535,6 +535,7 @@ TRACK* TRACK::GetEndNetCode( int NetCode ) } +#if 0 // replaced by Save() /********************************************/ bool TRACK::WriteTrackDescr( FILE* File ) /********************************************/ @@ -558,6 +559,29 @@ bool TRACK::WriteTrackDescr( FILE* File ) 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; +} + /*********************************************************************/ diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h index 668f6ab4c6..7c40a5c7f8 100644 --- a/pcbnew/class_track.h +++ b/pcbnew/class_track.h @@ -59,9 +59,16 @@ public: /* supprime du chainage la structure Struct */ 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 * inserts a TRACK, SEGVIA or SEGZONE into its proper list, either at the diff --git a/pcbnew/classpcb.cpp b/pcbnew/classpcb.cpp index 1c0f17bba3..0e20df9909 100644 --- a/pcbnew/classpcb.cpp +++ b/pcbnew/classpcb.cpp @@ -102,7 +102,7 @@ void DRAWSEGMENT::Copy( DRAWSEGMENT* source ) m_TimeStamp = source->m_TimeStamp; } - +#if 0 // replaced by Save() /********************************************************/ bool DRAWSEGMENT::WriteDrawSegmentDescr( FILE* File ) /********************************************************/ @@ -121,6 +121,36 @@ bool DRAWSEGMENT::WriteDrawSegmentDescr( FILE* File ) fprintf( File, "$EndDRAWSEGMENT\n" ); 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; +} /******************************************************************/ diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index f1b20e0732..8359f3a0a4 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -234,7 +234,7 @@ int WinEDA_PcbFrame::LoadOnePcbFile( const wxString& FullFileName, wxDC * DC, bo 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 // manager. runs fine from command prompt. // output the board object tree to stdout: diff --git a/pcbnew/ioascii.cpp b/pcbnew/ioascii.cpp index c2bfc1b220..8d3a26dd39 100644 --- a/pcbnew/ioascii.cpp +++ b/pcbnew/ioascii.cpp @@ -1070,7 +1070,7 @@ int WinEDA_PcbFrame::ReadPcbFile( wxDC* DC, FILE* File, bool Append ) #ifdef PCBNEW /***************************************************/ -int WinEDA_PcbFrame::SavePcbFormatAscii( FILE* File ) +int WinEDA_PcbFrame::SavePcbFormatAscii( FILE* aFile ) /****************************************************/ /* Routine de sauvegarde du PCB courant sous format ASCII @@ -1079,139 +1079,35 @@ int WinEDA_PcbFrame::SavePcbFormatAscii( FILE* File ) * 0 si sauvegarde non faite */ { - int ii, NbModules, nseg; - float Pas; - char Line[256]; - EQUIPOT* Equipot; - TRACK* PtSegm; - EDA_BaseStruct* PtStruct; - MODULE* Module; - - wxBeginBusyCursor(); - + bool rc; + char line[256]; + m_Pcb->m_Status_Pcb &= ~CONNEXION_OK; - /* Calcul du nombre des modules */ - PtStruct = (EDA_BaseStruct*) m_Pcb->m_Modules; - NbModules = 0; - for( ; PtStruct != NULL; PtStruct = PtStruct->Pnext ) - NbModules++; - + wxBeginBusyCursor(); + // Switch the locale to standard C (needed to print floating point numbers like 1.3) setlocale( LC_NUMERIC, "C" ); + /* Ecriture de l'entete PCB : */ - fprintf( File, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB, - DateAndTime( Line ) ); + fprintf( aFile, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB, + DateAndTime( line ) ); - WriteGeneralDescrPcb( File ); - WriteSheetDescr( m_CurrentScreen, File ); - WriteSetup( File, this ); + WriteGeneralDescrPcb( aFile ); + WriteSheetDescr( m_CurrentScreen, aFile ); + WriteSetup( aFile, this ); - /* Ecriture des donnes utiles du pcb */ - - Equipot = m_Pcb->m_Equipots; + rc = m_Pcb->Save( aFile ); - 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: - ( (COTATION*) PtStruct )->WriteCotationDescr( File ); - break; - - 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; - if( ii ) - Pas /= ii; - - PtSegm = m_Pcb->m_Zone; - - 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(); - - Affiche_Message( wxEmptyString ); - return 1; + + if( !rc ) + DisplayError( this, wxT( "Unable to save PCB file" ) ); + else + Affiche_Message( wxEmptyString ); + + return rc; } #endif diff --git a/pcbnew/librairi.cpp b/pcbnew/librairi.cpp index 240f9265f8..ef9c380c75 100644 --- a/pcbnew/librairi.cpp +++ b/pcbnew/librairi.cpp @@ -1,8 +1,8 @@ - /***************************************/ - /* Gestion de la LIBRAIRIE des MODULES */ - /***************************************/ +/***************************************/ +/* Gestion de la LIBRAIRIE des MODULES */ +/***************************************/ - /* Fichier LIBRAIRI.CPP */ +/* Fichier LIBRAIRI.CPP */ #include "fctsys.h" #include "gr_basic.h" @@ -13,660 +13,702 @@ #include "protos.h" /* -Format de l'entete de la Librairie: -chaine ENTETE-LIBRAIRIE date-heure -$INDEX -liste des noms modules ( 1 nom par ligne) -$EndINDEX -liste des descriptions des Modules -$EndLIBRARY -*/ + * Format de l'entete de la Librairie: + * chaine ENTETE-LIBRAIRIE date-heure + * $INDEX + * liste des noms modules ( 1 nom par ligne) + * $EndINDEX + * liste des descriptions des Modules + * $EndLIBRARY + */ -#define OLD_EXT wxT(".bak") -#define FILETMP_EXT wxT(".$$$") +#define OLD_EXT wxT( ".bak" ) +#define FILETMP_EXT wxT( ".$$$" ) /* 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 - Lit 1 fichier type Empreinte et place le module sur PCB -*/ + * Importation de modules Hors librairie + * Lit 1 fichier type Empreinte et place le module sur PCB + */ { -int NbLine = 0; -char Line[1024]; -wxString CmpFullFileName; -FILE * dest; -MODULE * module = NULL; + int NbLine = 0; + char Line[1024]; + wxString CmpFullFileName; + FILE* dest; + MODULE* module = NULL; - /* Lecture Fichier module */ - CmpFullFileName = EDA_FileSelector( _("Import Module:"), - wxEmptyString, /* Chemin par defaut */ - wxEmptyString, /* nom fichier par defaut */ - EXT_CMP, /* extension par defaut */ - EXT_CMP_MASK, /* Masque d'affichage */ - this, - wxFD_OPEN, - TRUE - ); + /* Lecture Fichier module */ + CmpFullFileName = EDA_FileSelector( _( "Import Module:" ), + wxEmptyString, /* Chemin par defaut */ + wxEmptyString, /* nom fichier par defaut */ + EXT_CMP, /* extension par defaut */ + EXT_CMP_MASK, /* Masque d'affichage */ + this, + wxFD_OPEN, + TRUE + ); - if ( CmpFullFileName == wxEmptyString ) return NULL; + if( CmpFullFileName == wxEmptyString ) + return NULL; - if ( (dest = wxFopen(CmpFullFileName, wxT("rt")) ) == NULL ) - { - wxString msg; - msg.Printf( _("File <%s> not found"), CmpFullFileName.GetData()); - DisplayError(this, msg) ; - return NULL; - } + if( ( dest = wxFopen( CmpFullFileName, wxT( "rt" ) ) ) == NULL ) + { + wxString msg; + msg.Printf( _( "File <%s> not found" ), CmpFullFileName.GetData() ); + DisplayError( this, msg ); + return NULL; + } - /* Lecture Entete */ - GetLine(dest, Line, &NbLine); - if(strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0) - { - DisplayError(this, _("Not a module file")); - return NULL; - } + /* Lecture Entete */ + GetLine( dest, Line, &NbLine ); + if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 ) + { + DisplayError( this, _( "Not a module file" ) ); + return NULL; + } - /* Lecture du fichier: recherche du debut de la descr module */ - while( GetLine(dest, Line, &NbLine) != NULL) - { - if(strnicmp( Line,"$MODULE",7) == 0) break; - } + /* Lecture du fichier: recherche du debut de la descr module */ + while( GetLine( dest, Line, &NbLine ) != NULL ) + { + if( strnicmp( Line, "$MODULE", 7 ) == 0 ) + break; + } - module = new MODULE(m_Pcb); - module->ReadDescr(dest, &NbLine); - fclose(dest); + module = new MODULE( m_Pcb ); - /* Mise a jour du chainage */ - if( m_Pcb->m_Modules ) - { - m_Pcb->m_Modules->Pback = module; - } - module->Pnext = m_Pcb->m_Modules; - module->Pback = m_Pcb; - m_Pcb->m_Modules = module; + module->ReadDescr( dest, &NbLine ); + fclose( dest ); - /* Affichage des caracteristiques : */ - module->Display_Infos(this); - Place_Module(module, DC) ; - m_Pcb->m_Status_Pcb = 0 ; - build_liste_pads(); + /* Mise a jour du chainage */ + if( m_Pcb->m_Modules ) + { + m_Pcb->m_Modules->Pback = module; + } + module->Pnext = m_Pcb->m_Modules; + module->Pback = m_Pcb; + m_Pcb->m_Modules = module; - return module; + /* Affichage des caracteristiques : */ + module->Display_Infos( this ); + Place_Module( module, DC ); + m_Pcb->m_Status_Pcb = 0; + build_liste_pads(); + + 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("*") ); -char Line[1025]; -FILE * dest; -wxString msg, path; + wxString FullFileName, Mask( wxT( "*" ) ); + char Line[1025]; + FILE* dest; + wxString msg, path; - if ( ptmod == NULL ) return; + if( ptmod == NULL ) + return; - ptmod->m_LibRef = ptmod->m_Reference->m_Text; - FullFileName = ptmod->m_LibRef; - FullFileName += createlib ? LibExtBuffer : EXT_CMP; + ptmod->m_LibRef = ptmod->m_Reference->m_Text; + FullFileName = ptmod->m_LibRef; + FullFileName += createlib ? LibExtBuffer : EXT_CMP; - Mask += createlib ? LibExtBuffer : EXT_CMP; + Mask += createlib ? LibExtBuffer : EXT_CMP; - if ( createlib ) path = g_RealLibDirBuffer; - FullFileName = EDA_FileSelector( createlib ? _("Create lib") : _("Export Module:"), - path, /* Chemin par defaut */ - FullFileName, /* nom fichier par defaut */ - createlib ? LibExtBuffer : EXT_CMP, /* extension par defaut */ - Mask, /* Masque d'affichage */ - this, - wxFD_SAVE, - TRUE - ); + if( createlib ) + path = g_RealLibDirBuffer; + FullFileName = EDA_FileSelector( createlib ? _( "Create lib" ) : _( "Export Module:" ), + path, /* Chemin par defaut */ + FullFileName, /* nom fichier par defaut */ + createlib ? LibExtBuffer : EXT_CMP, /* extension par defaut */ + Mask, /* Masque d'affichage */ + this, + wxFD_SAVE, + TRUE + ); - if ( FullFileName.IsEmpty() ) return; + if( FullFileName.IsEmpty() ) + return; - if ( createlib && wxFileExists(FullFileName) ) - { - msg.Printf( _("File %s exists, OK to replace ?"), - FullFileName.GetData()); - if( ! IsOK(this, msg) ) return; - } + if( createlib && wxFileExists( FullFileName ) ) + { + msg.Printf( _( "File %s exists, OK to replace ?" ), + FullFileName.GetData() ); + if( !IsOK( this, msg ) ) + return; + } - /* Generation du fichier Empreinte */ - if ( (dest = wxFopen(FullFileName, wxT("wt")) ) == NULL ) - { - msg.Printf( _("Unable to create <%s>"),FullFileName.GetData()) ; - DisplayError(this, msg) ; - return ; - } + /* Generation du fichier Empreinte */ + if( ( dest = wxFopen( FullFileName, wxT( "wt" ) ) ) == NULL ) + { + msg.Printf( _( "Unable to create <%s>" ), FullFileName.GetData() ); + DisplayError( this, msg ); + return; + } - fprintf(dest,"%s %s\n", ENTETE_LIBRAIRIE, DateAndTime(Line)); - fputs("$INDEX\n",dest); + fprintf( dest, "%s %s\n", ENTETE_LIBRAIRIE, DateAndTime( Line ) ); + fputs( "$INDEX\n", dest ); - fprintf(dest,"%s\n", CONV_TO_UTF8(ptmod->m_LibRef) ); - fputs("$EndINDEX\n",dest); + fprintf( dest, "%s\n", CONV_TO_UTF8( ptmod->m_LibRef ) ); + fputs( "$EndINDEX\n", dest ); - m_Pcb->m_Modules->WriteDescr(dest); + m_Pcb->m_Modules->Save( dest ); - fputs("$EndLIBRARY\n",dest); - fclose(dest) ; - msg.Printf( _("Module exported in file <%s>"),FullFileName.GetData()) ; - DisplayInfo(this, msg) ; + fputs( "$EndLIBRARY\n", dest ); + fclose( dest ); + msg.Printf( _( "Module exported in file <%s>" ), FullFileName.GetData() ); + DisplayInfo( this, msg ); } + /**********************************************************/ -void WinEDA_ModuleEditFrame::Delete_Module_In_Library(const - wxString & libname) +void WinEDA_ModuleEditFrame::Delete_Module_In_Library( const + wxString& libname ) /**********************************************************/ { -int ii, NoFound = 1, LineNum = 0; -char Line[1024], Name[256]; -wxString NewLib, OldLib; -FILE * dest, * lib_module; -wxString CmpName, msg; + int ii, NoFound = 1, LineNum = 0; + char Line[1024], Name[256]; + wxString NewLib, OldLib; + FILE* dest, * lib_module; + wxString CmpName, msg; - /* Demande du nom du composant a supprimer */ - CmpName = Select_1_Module_From_List( this, libname, wxEmptyString, wxEmptyString ); - if( CmpName == wxEmptyString ) return; + /* Demande du nom du composant a supprimer */ + CmpName = Select_1_Module_From_List( this, libname, wxEmptyString, wxEmptyString ); + if( CmpName == wxEmptyString ) + return; - /* Confirmation */ - msg.Printf( _("Ok to delete module %s in library %s"), - CmpName.GetData(), libname.GetData() ); - if( !IsOK(this, msg) ) return; + /* Confirmation */ + msg.Printf( _( "Ok to delete module %s in library %s" ), + CmpName.GetData(), libname.GetData() ); + if( !IsOK( this, msg ) ) + return; - OldLib = libname; + OldLib = libname; - if ((lib_module = wxFopen( OldLib, wxT("rt"))) == NULL ) - { - wxString msg; - msg = _("Library ") + OldLib + _(" not found"); - DisplayError(this, msg); - return; - } + if( ( lib_module = wxFopen( OldLib, wxT( "rt" ) ) ) == NULL ) + { + wxString msg; + msg = _( "Library " ) + OldLib + _( " not found" ); + DisplayError( this, msg ); + return; + } - /* lecture entete */ - GetLine(lib_module,Line, &LineNum) ; + /* lecture entete */ + GetLine( lib_module, Line, &LineNum ); - if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0) - { - DisplayError(this, _("Not a Library file")); - fclose(lib_module); - return; - } + if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 ) + { + DisplayError( this, _( "Not a Library file" ) ); + fclose( lib_module ); + return; + } - /* lecture des nom des composants */ - while( GetLine(lib_module, Line, &LineNum) ) - { - if( strnicmp( Line, "$INDEX",6) == 0 ) - { - while( GetLine(lib_module, Line, &LineNum) ) - { - StrPurge(Line); - msg = CONV_FROM_UTF8(Line); - if( CmpName.CmpNoCase(msg) == 0) /* composant trouve */ - { - NoFound = 0; break; - } - if( strnicmp( Line, "$EndINDEX",9) == 0 ) break; - } - } - if( strnicmp( Line, "$EndINDEX",9) == 0 ) break; - } + /* lecture des nom des composants */ + while( GetLine( lib_module, Line, &LineNum ) ) + { + if( strnicmp( Line, "$INDEX", 6 ) == 0 ) + { + while( GetLine( lib_module, Line, &LineNum ) ) + { + StrPurge( Line ); + msg = CONV_FROM_UTF8( Line ); + if( CmpName.CmpNoCase( msg ) == 0 ) /* composant trouve */ + { + NoFound = 0; break; + } + if( strnicmp( Line, "$EndINDEX", 9 ) == 0 ) + break; + } + } + if( strnicmp( Line, "$EndINDEX", 9 ) == 0 ) + break; + } - if( NoFound ) - { - fclose(lib_module); - msg.Printf( _("Module [%s] not found"), CmpName.GetData() ); - DisplayError(this, msg); - return ; - } + if( NoFound ) + { + fclose( lib_module ); + msg.Printf( _( "Module [%s] not found" ), CmpName.GetData() ); + DisplayError( this, msg ); + return; + } - /* Creation de la nouvelle librairie */ - NewLib = OldLib; - ChangeFileNameExt(NewLib,FILETMP_EXT); - if ((dest = wxFopen(NewLib, wxT("wt") )) == NULL ) - { - fclose(lib_module) ; - wxString msg; - msg = _("Unable to create ") + NewLib; - DisplayError(this, msg); - return; - } + /* Creation de la nouvelle librairie */ + NewLib = OldLib; + ChangeFileNameExt( NewLib, FILETMP_EXT ); + if( ( dest = wxFopen( NewLib, wxT( "wt" ) ) ) == NULL ) + { + fclose( lib_module ); + wxString msg; + msg = _( "Unable to create " ) + NewLib; + DisplayError( this, msg ); + return; + } -wxBeginBusyCursor(); + wxBeginBusyCursor(); - /* Creation de l'entete avec nouvelle date */ - fprintf(dest,ENTETE_LIBRAIRIE); - fprintf(dest," %s\n$INDEX\n", DateAndTime(Line) ); + /* Creation de l'entete avec nouvelle date */ + fprintf( dest, ENTETE_LIBRAIRIE ); + fprintf( dest, " %s\n$INDEX\n", DateAndTime( Line ) ); - fseek(lib_module,0,0); GetLine(lib_module, Line, &ii); - while(GetLine(lib_module,Line, &ii)) - { - if ( strnicmp(Line,"$M",2 ) == 0 ) break; - if ( strnicmp(Line,"$INDEX",6 ) == 0 ) - { - while(GetLine(lib_module,Line, &ii)) - { - if ( strnicmp(Line,"$EndINDEX",9 ) == 0 ) break; - StrPurge(Line); - msg = CONV_FROM_UTF8(Line); - if( CmpName.CmpNoCase(msg) != 0 ) - fprintf(dest,"%s\n",Line); - } - } - if ( strnicmp(Line,"$EndINDEX",9 ) == 0 ) break; - } + fseek( lib_module, 0, 0 ); GetLine( lib_module, Line, &ii ); + while( GetLine( lib_module, Line, &ii ) ) + { + if( strnicmp( Line, "$M", 2 ) == 0 ) + break; + if( strnicmp( Line, "$INDEX", 6 ) == 0 ) + { + while( GetLine( lib_module, Line, &ii ) ) + { + if( strnicmp( Line, "$EndINDEX", 9 ) == 0 ) + break; + StrPurge( Line ); + msg = CONV_FROM_UTF8( Line ); + if( CmpName.CmpNoCase( msg ) != 0 ) + fprintf( dest, "%s\n", Line ); + } + } + if( strnicmp( Line, "$EndINDEX", 9 ) == 0 ) + break; + } - fprintf(dest,"$EndINDEX\n"); + fprintf( dest, "$EndINDEX\n" ); - /* Copie des modules */ - while( GetLine(lib_module, Line, &LineNum) ) - { - StrPurge(Line); - if( strnicmp( Line, "$MODULE", 7) == 0 ) - { - sscanf(Line+7," %s", Name); - msg = CONV_FROM_UTF8(Name); - if( msg.CmpNoCase(CmpName) == 0 ) - { - /* suppression ancien module */ - while( GetLine(lib_module, Line, &LineNum) ) - { - if( strnicmp( Line, "$EndMODULE", 9) == 0 ) break; - } - continue; - } - } - fprintf(dest, "%s\n", Line); - } + /* Copie des modules */ + while( GetLine( lib_module, Line, &LineNum ) ) + { + StrPurge( Line ); + if( strnicmp( Line, "$MODULE", 7 ) == 0 ) + { + sscanf( Line + 7, " %s", Name ); + msg = CONV_FROM_UTF8( Name ); + if( msg.CmpNoCase( CmpName ) == 0 ) + { + /* suppression ancien module */ + while( GetLine( lib_module, Line, &LineNum ) ) + { + if( strnicmp( Line, "$EndMODULE", 9 ) == 0 ) + break; + } - fclose(lib_module); - fclose(dest) ; + continue; + } + } + fprintf( dest, "%s\n", Line ); + } -wxEndBusyCursor(); + fclose( lib_module ); + fclose( dest ); - /* Le fichier ancienne librairie est renommee en .bak */ -wxString BakFilename = OldLib; - ChangeFileNameExt( BakFilename, OLD_EXT); + wxEndBusyCursor(); - if( wxFileExists(BakFilename) ) wxRemoveFile(BakFilename); + /* Le fichier ancienne librairie est renommee en .bak */ + wxString BakFilename = OldLib; + ChangeFileNameExt( BakFilename, OLD_EXT ); - if( ! wxRenameFile(OldLib, BakFilename) ) - { - DisplayError(this, wxT("Librairi.cpp: rename .bak err")); - return; - } + if( wxFileExists( BakFilename ) ) + wxRemoveFile( BakFilename ); - /* Le fichier temporaire est renommee comme l'ancienne Lib */ - if( ! wxRenameFile(NewLib,OldLib) ) - { - DisplayError(this, wxT("Librairi.cpp: rename err 2") ); - return; - } + if( !wxRenameFile( OldLib, BakFilename ) ) + { + DisplayError( this, wxT( "Librairi.cpp: rename .bak err" ) ); + return; + } - msg.Printf( _("Component %s deleted in library %s"), CmpName.GetData(), OldLib.GetData() ) ; - Affiche_Message(msg) ; + /* Le fichier temporaire est renommee comme l'ancienne Lib */ + if( !wxRenameFile( NewLib, OldLib ) ) + { + DisplayError( this, wxT( "Librairi.cpp: rename err 2" ) ); + return; + } - CreateDocLibrary(OldLib); + msg.Printf( _( "Component %s deleted in library %s" ), CmpName.GetData(), OldLib.GetData() ); + Affiche_Message( msg ); + + CreateDocLibrary( OldLib ); } /***********************************************************************/ -void WinEDA_BasePcbFrame::Archive_Modules(const wxString & LibName, - bool NewModulesOnly) +void WinEDA_BasePcbFrame::Archive_Modules( const wxString& LibName, + bool NewModulesOnly ) /***********************************************************************/ + /* - Sauve en Librairie: - tous les nouveaux modules ( c.a.d. les modules - n'existant pas deja (si NewModulesOnly == TRUE) - tous les modules (si NewModulesOnly == FALSE) -*/ + * Sauve en Librairie: + * tous les nouveaux modules ( c.a.d. les modules + * n'existant pas deja (si NewModulesOnly == TRUE) + * tous les modules (si NewModulesOnly == FALSE) + */ { -int ii, NbModules = 0; -float Pas; -MODULE * Module; -wxString FullFileName = LibName; - - if ( m_Pcb->m_Modules == NULL ) - { - DisplayInfo(this, _(" No modules to archive!") ); - return; - } - - if ( FullFileName.IsEmpty() ) - { - wxString Mask = wxT("*") + LibExtBuffer; - FullFileName = EDA_FileSelector( _("Library"), - g_RealLibDirBuffer, /* Chemin par defaut */ - FullFileName, /* nom fichier par defaut */ - LibExtBuffer, /* extension par defaut */ - Mask, /* Masque d'affichage */ - this, - wxFD_SAVE, - TRUE - ); + int ii, NbModules = 0; + float Pas; + MODULE* Module; + wxString FullFileName = LibName; - if ( FullFileName.IsEmpty() ) return; - } - - bool file_exists = wxFileExists(FullFileName); - if ( ! NewModulesOnly && file_exists ) - { - wxString msg; - msg.Printf( _("File %s exists, OK to replace ?"), FullFileName.GetData()); - if( ! IsOK(this, msg) ) return; - } - - DrawPanel->m_AbortRequest = FALSE; - - // Create a new, empty library if no old lib, or if archive all modules - if ( ! NewModulesOnly || ! file_exists ) - { - FILE * lib_module; - if ((lib_module = wxFopen(FullFileName, wxT("w+t"))) == NULL ) - { - wxString msg = _("Unable to create ") + FullFileName; - DisplayError(this, msg); - return; - } - char Line[256]; - fprintf(lib_module,"%s %s\n", ENTETE_LIBRAIRIE, DateAndTime(Line)); - fputs("$INDEX\n",lib_module); - fputs("$EndINDEX\n",lib_module); - fputs("$EndLIBRARY\n",lib_module); - fclose(lib_module) ; - } + if( m_Pcb->m_Modules == NULL ) + { + DisplayInfo( this, _( " No modules to archive!" ) ); + return; + } - /* Calcul du nombre de modules */ - Module = (MODULE *) m_Pcb->m_Modules; - for( ;Module != NULL; Module = (MODULE *)Module->Pnext) NbModules++; - Pas = (float) 100 / NbModules; - DisplayActivity(0, wxEmptyString); + if( FullFileName.IsEmpty() ) + { + wxString Mask = wxT( "*" ) + LibExtBuffer; + FullFileName = EDA_FileSelector( _( "Library" ), + g_RealLibDirBuffer, /* Chemin par defaut */ + FullFileName, /* nom fichier par defaut */ + LibExtBuffer, /* extension par defaut */ + Mask, /* Masque d'affichage */ + this, + wxFD_SAVE, + TRUE + ); - Module = (MODULE *) m_Pcb->m_Modules; - for( ii = 1 ;Module != NULL; ii++, Module = (MODULE *)Module->Pnext) - { - if( Save_1_Module(FullFileName, Module, - NewModulesOnly ? FALSE : TRUE, FALSE) == 0 ) break; - DisplayActivity((int)( ii * Pas) , wxEmptyString); - /* Tst demande d'arret de sauvegarde ( key ESCAPE actionnee ) */ - if( DrawPanel->m_AbortRequest ) break; - } + if( FullFileName.IsEmpty() ) + return; + } - CreateDocLibrary(LibName); + bool file_exists = wxFileExists( FullFileName ); + if( !NewModulesOnly && file_exists ) + { + wxString msg; + msg.Printf( _( "File %s exists, OK to replace ?" ), FullFileName.GetData() ); + if( !IsOK( this, msg ) ) + return; + } + + DrawPanel->m_AbortRequest = FALSE; + + // Create a new, empty library if no old lib, or if archive all modules + if( !NewModulesOnly || !file_exists ) + { + FILE* lib_module; + if( ( lib_module = wxFopen( FullFileName, wxT( "w+t" ) ) ) == NULL ) + { + wxString msg = _( "Unable to create " ) + FullFileName; + DisplayError( this, msg ); + return; + } + char Line[256]; + fprintf( lib_module, "%s %s\n", ENTETE_LIBRAIRIE, DateAndTime( Line ) ); + fputs( "$INDEX\n", lib_module ); + fputs( "$EndINDEX\n", lib_module ); + fputs( "$EndLIBRARY\n", lib_module ); + fclose( lib_module ); + } + + /* Calcul du nombre de modules */ + Module = (MODULE*) m_Pcb->m_Modules; + for( ; Module != NULL; Module = (MODULE*) Module->Pnext ) + NbModules++; + + Pas = (float) 100 / NbModules; + DisplayActivity( 0, wxEmptyString ); + + Module = (MODULE*) m_Pcb->m_Modules; + for( ii = 1; Module != NULL; ii++, Module = (MODULE*) Module->Pnext ) + { + if( Save_1_Module( FullFileName, Module, + NewModulesOnly ? FALSE : TRUE, FALSE ) == 0 ) + break; + DisplayActivity( (int) ( ii * Pas), wxEmptyString ); + /* Tst demande d'arret de sauvegarde ( key ESCAPE actionnee ) */ + if( DrawPanel->m_AbortRequest ) + break; + } + + CreateDocLibrary( LibName ); } /*****************************************************************/ -int WinEDA_BasePcbFrame::Save_1_Module(const wxString & LibName, - MODULE* Module, bool Overwrite, bool DisplayDialog) +int WinEDA_BasePcbFrame::Save_1_Module( const wxString& LibName, + MODULE* Module, bool Overwrite, bool DisplayDialog ) /*****************************************************************/ + /* - sauve en Librairie le module Module: - si no_replace == TRUE, s'il est nouveau. - - retourne - 1 si OK - 0 si abort ou probleme -*/ + * sauve en Librairie le module Module: + * si no_replace == TRUE, s'il est nouveau. + * + * retourne + * 1 si OK + * 0 si abort ou probleme + */ { -int newmodule, end; -int LineNum = 0, tmp; -char Name[256], Line[1024]; -wxString Name_Cmp; -wxString NewLib, OldLib, msg; -FILE * lib_module, *dest; -bool added = TRUE; - - Module->Display_Infos(this); + int newmodule, end; + int LineNum = 0, tmp; + char Name[256], Line[1024]; + wxString Name_Cmp; + wxString NewLib, OldLib, msg; + FILE* lib_module, * dest; + bool added = TRUE; - if ( ! wxFileExists(LibName) ) - { - msg.Printf( _("Library %s not found"), LibName.GetData()); - DisplayError(this, msg); - return 0; - } + Module->Display_Infos( this ); + + if( !wxFileExists( LibName ) ) + { + msg.Printf( _( "Library %s not found" ), LibName.GetData() ); + DisplayError( this, msg ); + return 0; + } - /* Demande du nom du composant en librairie */ - Name_Cmp = Module->m_LibRef; + /* Demande du nom du composant en librairie */ + Name_Cmp = Module->m_LibRef; - if( DisplayDialog ) - { - Get_Message(_("Name:"), Name_Cmp, this ) ; - if( Name_Cmp.IsEmpty() ) return(0); - Name_Cmp.Trim(TRUE); - Name_Cmp.Trim(FALSE); - Module->m_LibRef = Name_Cmp; - } + if( DisplayDialog ) + { + Get_Message( _( "Name:" ), Name_Cmp, this ); + if( Name_Cmp.IsEmpty() ) + return 0; + Name_Cmp.Trim( TRUE ); + Name_Cmp.Trim( FALSE ); + Module->m_LibRef = Name_Cmp; + } - if ((lib_module = wxFopen(LibName, wxT("rt"))) == NULL ) - { - msg.Printf( _("Unable to open %s"), LibName.GetData()); - DisplayError(this, msg); - return 0; - } + if( ( lib_module = wxFopen( LibName, wxT( "rt" ) ) ) == NULL ) + { + msg.Printf( _( "Unable to open %s" ), LibName.GetData() ); + DisplayError( this, msg ); + return 0; + } - /* lecture entete : ENTETE_LIBRAIRIE */ - GetLine(lib_module, Line, &LineNum) ; - if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0) - { - fclose(lib_module) ; - msg.Printf( _("File %s is not a eeschema library"), LibName.GetData()); - DisplayError(this, msg); - return(0); - } + /* lecture entete : ENTETE_LIBRAIRIE */ + GetLine( lib_module, Line, &LineNum ); + if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 ) + { + fclose( lib_module ); + msg.Printf( _( "File %s is not a eeschema library" ), LibName.GetData() ); + DisplayError( this, msg ); + return 0; + } - /* lecture des noms des composants - verif si le module est deja existant */ - newmodule = 1; end = 0; - while( !end && GetLine(lib_module, Line, &LineNum) ) - { - if( Line[0] != '$' ) continue; - if( strncmp( Line+1, "INDEX",5) != 0 ) continue; + /* lecture des noms des composants - verif si le module est deja existant */ + newmodule = 1; end = 0; + while( !end && GetLine( lib_module, Line, &LineNum ) ) + { + if( Line[0] != '$' ) + continue; + if( strncmp( Line + 1, "INDEX", 5 ) != 0 ) + continue; - while( GetLine(lib_module, Line, &LineNum) ) - { - if( strncmp( Line, "$EndINDEX",9) == 0 ) - { - end = 1; break; - } + while( GetLine( lib_module, Line, &LineNum ) ) + { + if( strncmp( Line, "$EndINDEX", 9 ) == 0 ) + { + end = 1; break; + } - StrPurge(Line); - msg = CONV_FROM_UTF8(Line); - if( Name_Cmp.CmpNoCase(msg) == 0) /* composant trouve */ - { - added = FALSE; - newmodule = 0; - if( DisplayDialog ) - { - msg = _("Module exists Line "); - msg << LineNum; - Affiche_Message(msg) ; - } - if( ! Overwrite) /* le module n'est pas a sauver car deja existant */ - { - fclose(lib_module); return(1); - } - end = 1; break; - } - } - } - fclose(lib_module); + StrPurge( Line ); + msg = CONV_FROM_UTF8( Line ); + if( Name_Cmp.CmpNoCase( msg ) == 0 ) /* composant trouve */ + { + added = FALSE; + newmodule = 0; + if( DisplayDialog ) + { + msg = _( "Module exists Line " ); + msg << LineNum; + Affiche_Message( msg ); + } + if( !Overwrite ) /* le module n'est pas a sauver car deja existant */ + { + fclose( lib_module ); return 1; + } + end = 1; break; + } + } + } - /* Creation de la nouvelle librairie */ + fclose( lib_module ); - if ((lib_module = wxFopen(LibName, wxT("rt"))) == NULL ) - { - DisplayError(this, wxT("Librairi.cpp: Error oldlib not found")); - return(0); - } + /* Creation de la nouvelle librairie */ - NewLib = LibName; - ChangeFileNameExt(NewLib, FILETMP_EXT); - if ((dest = wxFopen(NewLib, wxT("w+t"))) == NULL ) - { - fclose(lib_module) ; - msg = _("Unable to create ") + NewLib; - DisplayError(this, msg); - return(0); - } - -wxBeginBusyCursor() ; + if( ( lib_module = wxFopen( LibName, wxT( "rt" ) ) ) == NULL ) + { + DisplayError( this, wxT( "Librairi.cpp: Error oldlib not found" ) ); + return 0; + } - /* Creation de l'entete avec nouvelle date */ - fprintf(dest,ENTETE_LIBRAIRIE); - fprintf(dest," %s\n$INDEX\n", DateAndTime(Line) ); + NewLib = LibName; + ChangeFileNameExt( NewLib, FILETMP_EXT ); + if( ( dest = wxFopen( NewLib, wxT( "w+t" ) ) ) == NULL ) + { + fclose( lib_module ); + msg = _( "Unable to create " ) + NewLib; + DisplayError( this, msg ); + return 0; + } - LineNum = 0; - GetLine(lib_module, Line, &LineNum); - while(GetLine(lib_module,Line, &LineNum)) - { - StrPurge(Line); - if ( strnicmp(Line,"$M",2 ) == 0 ) break; - if ( strnicmp(Line,"$INDEX",6 ) == 0 ) - { - while(GetLine(lib_module,Line, &LineNum)) - { - if ( strnicmp(Line,"$EndINDEX",9 ) == 0 ) break; - fprintf(dest,"%s\n",Line); - } - } - if(newmodule) fprintf(dest,"%s\n",CONV_TO_UTF8(Name_Cmp) ); - if ( strnicmp(Line,"$EndINDEX",0 ) == 0 ) break; - } + wxBeginBusyCursor(); - fprintf(dest,"$EndINDEX\n"); + /* Creation de l'entete avec nouvelle date */ + fprintf( dest, ENTETE_LIBRAIRIE ); + fprintf( dest, " %s\n$INDEX\n", DateAndTime( Line ) ); - /* Copie des modules, jusqu'au module a supprimer */ - while( GetLine(lib_module, Line, &LineNum) ) - { - StrPurge(Line); - if( strnicmp( Line, "$EndLIBRARY", 8) == 0 ) continue; - if( strnicmp( Line, "$MODULE", 7) == 0 ) - { - sscanf(Line+7," %s", Name); - msg = CONV_FROM_UTF8(Name); - if( msg.CmpNoCase(Name_Cmp) == 0 ) - { - /* suppression ancien module */ - while( GetLine(lib_module, Line, &LineNum) ) - { - if( strnicmp( Line, "$EndMODULE", 9) == 0 ) break; - } - continue; - } - } - fprintf(dest,"%s\n",Line); - } + LineNum = 0; + GetLine( lib_module, Line, &LineNum ); + while( GetLine( lib_module, Line, &LineNum ) ) + { + StrPurge( Line ); + if( strnicmp( Line, "$M", 2 ) == 0 ) + break; + if( strnicmp( Line, "$INDEX", 6 ) == 0 ) + { + while( GetLine( lib_module, Line, &LineNum ) ) + { + if( strnicmp( Line, "$EndINDEX", 9 ) == 0 ) + break; + fprintf( dest, "%s\n", Line ); + } + } + if( newmodule ) + fprintf( dest, "%s\n", CONV_TO_UTF8( Name_Cmp ) ); + if( strnicmp( Line, "$EndINDEX", 0 ) == 0 ) + break; + } - /* Ecriture du module ( en fin de librairie ) */ - tmp = Module->m_TimeStamp; Module->m_TimeStamp = 0; - Module->WriteDescr(dest); - fprintf(dest,"$EndLIBRARY\n"); - Module->m_TimeStamp = tmp; + fprintf( dest, "$EndINDEX\n" ); - fclose(dest) ; fclose(lib_module) ; + /* Copie des modules, jusqu'au module a supprimer */ + while( GetLine( lib_module, Line, &LineNum ) ) + { + StrPurge( Line ); + if( strnicmp( Line, "$EndLIBRARY", 8 ) == 0 ) + continue; + if( strnicmp( Line, "$MODULE", 7 ) == 0 ) + { + sscanf( Line + 7, " %s", Name ); + msg = CONV_FROM_UTF8( Name ); + if( msg.CmpNoCase( Name_Cmp ) == 0 ) + { + /* suppression ancien module */ + while( GetLine( lib_module, Line, &LineNum ) ) + { + if( strnicmp( Line, "$EndMODULE", 9 ) == 0 ) + break; + } -wxEndBusyCursor() ; + continue; + } + } + fprintf( dest, "%s\n", Line ); + } - /* L'ancien fichier librairie est renomme en .bak */ - OldLib = LibName; - ChangeFileNameExt ( OldLib, OLD_EXT); + /* Ecriture du module ( en fin de librairie ) */ + tmp = Module->m_TimeStamp; Module->m_TimeStamp = 0; + Module->Save( dest ); + fprintf( dest, "$EndLIBRARY\n" ); + Module->m_TimeStamp = tmp; - if( wxFileExists(OldLib) ) wxRemoveFile(OldLib); + fclose( dest ); fclose( lib_module ); - if ( ! wxRenameFile(LibName, OldLib ) ) - DisplayError(this, wxT("Librairi.cpp: rename .bak err") ); + wxEndBusyCursor(); - /* Le nouveau fichier librairie est renomme */ - if ( ! wxRenameFile(NewLib,LibName) ) - { - DisplayError(this, wxT("Librairi.cpp: rename NewLib err") ); - return(0); - } + /* L'ancien fichier librairie est renomme en .bak */ + OldLib = LibName; + ChangeFileNameExt( OldLib, OLD_EXT ); - CreateDocLibrary(OldLib); + if( wxFileExists( OldLib ) ) + wxRemoveFile( OldLib ); - if ( DisplayDialog ) - { - msg = _("Component ") ; msg += Name_Cmp; - msg += added ? _(" added in ") : _(" replaced in "); - msg += LibName; - Affiche_Message(msg); - } + if( !wxRenameFile( LibName, OldLib ) ) + DisplayError( this, wxT( "Librairi.cpp: rename .bak err" ) ); - return(1); + /* Le nouveau fichier librairie est renomme */ + if( !wxRenameFile( NewLib, LibName ) ) + { + DisplayError( this, wxT( "Librairi.cpp: rename NewLib err" ) ); + return 0; + } + + CreateDocLibrary( OldLib ); + + if( DisplayDialog ) + { + msg = _( "Component " ); msg += Name_Cmp; + msg += added ? _( " added in " ) : _( " replaced in " ); + msg += LibName; + Affiche_Message( msg ); + } + + 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 : - 1er = type REF: nom du module - 2eme = type VALEUR: "VAL**" - Le module est insere en debut de liste des modules -*/ + * 1er = type REF: nom du module + * 2eme = type VALEUR: "VAL**" + * Le module est insere en debut de liste des modules + */ { -MODULE* Module ; -wxString Line; -wxPoint newpos; + MODULE* Module; + wxString Line; + wxPoint newpos; - /* Demande du nom du nouveau module */ - if ( module_name.IsEmpty() ) - { - if ( Get_Message( _("Module Reference:"), Line, this ) != 0 ) return NULL; - } - - else Line = module_name; - Line.Trim(TRUE); - Line.Trim(FALSE); + /* Demande du nom du nouveau module */ + if( module_name.IsEmpty() ) + { + if( Get_Message( _( "Module Reference:" ), Line, this ) != 0 ) + return NULL; + } + else + Line = module_name; + Line.Trim( TRUE ); + Line.Trim( FALSE ); - Module = new MODULE(m_Pcb); + Module = new MODULE( m_Pcb ); - Module->Pnext = m_Pcb->m_Modules; - Module->Pback = m_Pcb; - if( m_Pcb->m_Modules ) - { - m_Pcb->m_Modules->Pback = Module; - } - m_Pcb->m_Modules = Module; + Module->Pnext = m_Pcb->m_Modules; + Module->Pback = m_Pcb; + if( m_Pcb->m_Modules ) + { + m_Pcb->m_Modules->Pback = Module; + } + m_Pcb->m_Modules = Module; - /* Creation du module : On place d'office les 2 textes ref et val : - 1er = type REF: nom du module - 2eme = type VALEUR: "VAL**" */ + /* Creation du module : On place d'office les 2 textes ref et val : + * 1er = type REF: nom du module + * 2eme = type VALEUR: "VAL**" */ - /* Mise a jour des caract du nouveau module */ - newpos = m_CurrentScreen->m_Curseur; - Module->SetPosition(newpos); - Module->m_LastEdit_Time = time(NULL); + /* Mise a jour des caract du nouveau module */ + newpos = m_CurrentScreen->m_Curseur; + Module->SetPosition( newpos ); + Module->m_LastEdit_Time = time( NULL ); - /* Mise a jour du nom de Librairie (reference libr) */ - Module->m_LibRef = Line; + /* Mise a jour du nom de Librairie (reference libr) */ + Module->m_LibRef = Line; - /* Mise a jour de la reference: */ - Module->m_Reference->m_Text = Line; - Module->m_Reference->SetWidth(ModuleTextWidth); - Module->m_Reference->m_Size = ModuleTextSize; + /* Mise a jour de la reference: */ + Module->m_Reference->m_Text = Line; + Module->m_Reference->SetWidth( ModuleTextWidth ); + Module->m_Reference->m_Size = ModuleTextSize; - /* mise a jour de la valeurs */ - Module->m_Value->m_Text = wxT("VAL**"); - Module->m_Value->SetWidth(ModuleTextWidth); - Module->m_Value->m_Size = ModuleTextSize; + /* mise a jour de la valeurs */ + Module->m_Value->m_Text = wxT( "VAL**" ); + Module->m_Value->SetWidth( ModuleTextWidth ); + Module->m_Value->m_Size = ModuleTextSize; - Module->Display_Infos(this); - return Module; + Module->Display_Infos( this ); + return Module; } @@ -674,158 +716,164 @@ wxPoint newpos; 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:"), - NULL, m_CurrentLib, NULL, wxColour(200, 200, 255) ); + WinEDAListBox* LibListBox = new WinEDAListBox( this, _( "Active Lib:" ), + NULL, m_CurrentLib, NULL, wxColour( 200, 200, 255 ) ); - LibListBox->InsertItems(g_LibName_List); + LibListBox->InsertItems( g_LibName_List ); - int ii = LibListBox->ShowModal(); - if ( ii >= 0 ) m_CurrentLib = LibListBox->GetTextSelection(); + int ii = LibListBox->ShowModal(); + if( ii >= 0 ) + m_CurrentLib = LibListBox->GetTextSelection(); - LibListBox->Destroy(); + LibListBox->Destroy(); - SetTitle( _("Module Editor (lib: ") + m_CurrentLib + wxT(")") ); - return; + SetTitle( _( "Module Editor (lib: " ) + m_CurrentLib + wxT( ")" ) ); + return; } - - /**********************************************************************/ -int WinEDA_ModuleEditFrame::Create_Librairie(const wxString & LibName) +int WinEDA_ModuleEditFrame::Create_Librairie( const wxString& LibName ) /**********************************************************************/ { -FILE * lib_module; -wxString msg; - - if ( wxFileExists(LibName) ) - { - msg = _("Library exists ") + LibName; - DisplayError(this, msg); - return(0); - } + FILE* lib_module; + wxString msg; - if ((lib_module = wxFopen(LibName, wxT("wt") )) == NULL ) - { - msg = _("Unable to create ") + LibName; - DisplayError(this, msg); - return(-1); - } + if( wxFileExists( LibName ) ) + { + msg = _( "Library exists " ) + LibName; + DisplayError( this, msg ); + return 0; + } - /* Ecriture de l'entete de la nouvelle librairie */ - if( fprintf(lib_module,ENTETE_LIBRAIRIE) == 0) - { - msg = _("Create error ") + LibName; - DisplayError(this, msg); - fclose(lib_module) ; return(-1); - } + if( ( lib_module = wxFopen( LibName, wxT( "wt" ) ) ) == NULL ) + { + msg = _( "Unable to create " ) + LibName; + DisplayError( this, msg ); + return -1; + } - fprintf(lib_module," %s\n", DateAndTime(cbuf)); - fputs("$INDEX\n",lib_module); - fputs("$EndINDEX\n",lib_module); - fclose(lib_module) ; + /* Ecriture de l'entete de la nouvelle librairie */ + if( fprintf( lib_module, ENTETE_LIBRAIRIE ) == 0 ) + { + msg = _( "Create error " ) + LibName; + DisplayError( this, msg ); + fclose( lib_module ); return -1; + } - return(1); + fprintf( lib_module, " %s\n", DateAndTime( cbuf ) ); + fputs( "$INDEX\n", lib_module ); + fputs( "$EndINDEX\n", lib_module ); + fclose( lib_module ); + + return 1; } - /******************************************************/ -static bool CreateDocLibrary(const wxString & LibName) +static bool CreateDocLibrary( const wxString& LibName ) /*****************************************************/ + /* Creation du fichier .dcm associe a la librairie LibName - (full file name) -*/ + * (full file name) + */ { -char Line[1024]; -wxString Name, Doc, KeyWord; -wxString LibDocName; -FILE * LibMod, *LibDoc; + char Line[1024]; + wxString Name, Doc, KeyWord; + wxString LibDocName; + FILE* LibMod, * LibDoc; - LibDocName = LibName; - ChangeFileNameExt(LibDocName, EXT_DOC); + LibDocName = LibName; + ChangeFileNameExt( LibDocName, EXT_DOC ); - LibMod = wxFopen( LibName, wxT("rt") ); - if ( LibMod == NULL ) return FALSE; + LibMod = wxFopen( LibName, wxT( "rt" ) ); + if( LibMod == NULL ) + return FALSE; - /* lecture entete librairie*/ - GetLine(LibMod, Line, NULL, sizeof(Line) -1); - if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0) - { - fclose(LibMod); - return FALSE; - } + /* lecture entete librairie*/ + GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ); + if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 ) + { + fclose( LibMod ); + return FALSE; + } - LibDoc = wxFopen( LibDocName, wxT("wt") ); - if ( LibDoc == NULL ) - { - fclose( LibMod ); - return FALSE; - } - fprintf(LibDoc,ENTETE_LIBDOC); - fprintf(LibDoc," %s\n", DateAndTime(cbuf)); + LibDoc = wxFopen( LibDocName, wxT( "wt" ) ); + if( LibDoc == NULL ) + { + fclose( LibMod ); + return FALSE; + } + fprintf( LibDoc, ENTETE_LIBDOC ); + fprintf( LibDoc, " %s\n", DateAndTime( cbuf ) ); - /* Lecture de la librairie */ - Name = Doc = KeyWord = wxEmptyString; - while( GetLine(LibMod,Line, NULL, sizeof(Line) -1) ) - { - if( Line[0] != '$' ) continue; - if( strnicmp( Line, "$MODULE",6) == 0 ) - { - while( GetLine(LibMod,Line, NULL, sizeof(Line) -1) ) - { - if( Line[0] == '$' ) - { - if( Line[1] == 'E' ) break; - if( Line[1] == 'P' ) /* Pad Descr */ - { - while( GetLine(LibMod,Line, NULL, sizeof(Line) -1) ) - { - if( (Line[0] == '$') && (Line[1] == 'E') ) - break; - } - } - } - if( Line[0] == 'L' ) /* LibName */ - Name = CONV_FROM_UTF8(StrPurge(Line+3)); + /* Lecture de la librairie */ + Name = Doc = KeyWord = wxEmptyString; + while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) ) + { + if( Line[0] != '$' ) + continue; + if( strnicmp( Line, "$MODULE", 6 ) == 0 ) + { + while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) ) + { + if( Line[0] == '$' ) + { + if( Line[1] == 'E' ) + break; + if( Line[1] == 'P' ) /* Pad Descr */ + { + while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) ) + { + if( (Line[0] == '$') && (Line[1] == 'E') ) + break; + } + } + } + if( Line[0] == 'L' ) /* LibName */ + Name = CONV_FROM_UTF8( StrPurge( Line + 3 ) ); - if( Line[0] == 'K' ) /* KeyWords */ - KeyWord = CONV_FROM_UTF8(StrPurge(Line+3)); + if( Line[0] == 'K' ) /* KeyWords */ + KeyWord = CONV_FROM_UTF8( StrPurge( Line + 3 ) ); - if( Line[0] == 'C' ) /* Doc */ - Doc = CONV_FROM_UTF8(StrPurge(Line+3)); - } + if( Line[0] == 'C' ) /* Doc */ + Doc = CONV_FROM_UTF8( StrPurge( Line + 3 ) ); + } - 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,"Li %s\n",CONV_TO_UTF8(Name)); - if( Doc != wxEmptyString) - fprintf( LibDoc,"Cd %s\n", CONV_TO_UTF8(Doc)); + 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, "Li %s\n", CONV_TO_UTF8( Name ) ); + if( Doc != wxEmptyString ) + fprintf( LibDoc, "Cd %s\n", CONV_TO_UTF8( Doc ) ); - if( KeyWord != wxEmptyString) - fprintf( LibDoc,"Kw %s\n", CONV_TO_UTF8(KeyWord)); + if( KeyWord != wxEmptyString ) + fprintf( LibDoc, "Kw %s\n", CONV_TO_UTF8( KeyWord ) ); - fprintf( LibDoc,"$EndMODULE\n"); - } - Name = Doc = KeyWord = wxEmptyString; - } /* Fin lecture desc 1 module */ + fprintf( LibDoc, "$EndMODULE\n" ); + } + Name = Doc = KeyWord = wxEmptyString; + } /* Fin lecture desc 1 module */ - if( strnicmp( Line,"$INDEX",6) == 0 ) - { - while( GetLine(LibMod,Line, NULL, sizeof(Line)-1) ) - { - if( strnicmp( Line,"$EndINDEX",9) == 0 ) break; - } /* Fin Lecture INDEX */ - } - } /* Fin lecture 1 Librairie */ + if( strnicmp( Line, "$INDEX", 6 ) == 0 ) + { + while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) ) + { + if( strnicmp( Line, "$EndINDEX", 9 ) == 0 ) + break; + } - fclose( LibMod ); - fprintf( LibDoc,"#\n$EndLIBDOC\n"); - fclose( LibDoc ); - return TRUE; + /* Fin Lecture INDEX */ + } + } + + /* Fin lecture 1 Librairie */ + + fclose( LibMod ); + fprintf( LibDoc, "#\n$EndLIBDOC\n" ); + fclose( LibDoc ); + return TRUE; } - - diff --git a/pcbnew/trpiste.cpp b/pcbnew/trpiste.cpp index 7187a2fb25..b266d8bab0 100644 --- a/pcbnew/trpiste.cpp +++ b/pcbnew/trpiste.cpp @@ -17,17 +17,17 @@ 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 != NULL; track = track->Next() ) + for( TRACK* track = Pcb->m_Track; track; track = track->Next() ) { track->Draw( panel, DC, drawmode ); } - SEGZONE * zone = Pcb->m_Zone; - for( ; zone != NULL; zone = zone->Next() ) + for( SEGZONE* zone = Pcb->m_Zone; zone; zone = zone->Next() ) { zone->Draw( panel, DC, drawmode ); } @@ -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 */ { - if( Track == NULL ) - return; - for( ; nbsegment > 0; nbsegment--, Track = (TRACK*) Track->Pnext ) + for( ; nbsegment > 0 && Track; nbsegment--, Track = Track->Next() ) { - if( Track == NULL ) - break; Track->Draw( panel, DC, draw_mode ); } } diff --git a/pcbnew/zones.cpp b/pcbnew/zones.cpp index d7857294ef..6f9ef0bbf7 100644 --- a/pcbnew/zones.cpp +++ b/pcbnew/zones.cpp @@ -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. * La zone est constituee des segments zones de meme TimeStamp */ { - SEGZONE* pt_segm, * NextS; - unsigned long TimeStamp; bool modify = FALSE; double f_new_width; int w_tmp; wxString Line; wxString Msg( _( "New zone segment width: " ) ); - if( Zone == NULL ) + if( aZone == NULL ) 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 ); @@ -417,15 +415,12 @@ void WinEDA_PcbFrame::Edit_Zone_Width( wxDC* DC, SEGZONE* Zone ) f_new_width, GetScreen( )->GetInternalUnits() ); - TimeStamp = Zone->m_TimeStamp; - - for( pt_segm = (SEGZONE*) m_Pcb->m_Zone; pt_segm != NULL; pt_segm = NextS ) + for( SEGZONE* zone = m_Pcb->m_Zone; zone; zone = zone->Next() ) { - NextS = (SEGZONE*) pt_segm->Pnext; - if( pt_segm->m_TimeStamp == TimeStamp ) + if( zone->m_TimeStamp == aZone->m_TimeStamp ) { 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 ) * La zone est constituee des segments zones de meme TimeStamp */ { - SEGZONE* pt_segm, * NextS; unsigned long TimeStamp; int nb_segm = 0; bool modify = FALSE; 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; - if( pt_segm->m_TimeStamp == TimeStamp ) + next = zone->Next(); + if( zone->m_TimeStamp == TimeStamp ) { modify = TRUE; + /* effacement des segments a l'ecran */ - Trace_Une_Piste( DrawPanel, DC, pt_segm, nb_segm, GR_XOR ); - pt_segm ->DeleteStructure(); + Trace_Une_Piste( DrawPanel, DC, zone, nb_segm, GR_XOR ); + zone->DeleteStructure(); } } @@ -675,7 +671,7 @@ EDGE_ZONE* WinEDA_PcbFrame::Begin_Zone() oldedge = m_Pcb->m_CurrentLimitZone; if( (m_Pcb->m_CurrentLimitZone == NULL ) /* debut reel du trace */ - || (DrawPanel->ManageCurseur == NULL) ) /* reprise d'un trace complementaire */ + || (DrawPanel->ManageCurseur == NULL) ) /* reprise d'un trace complementaire */ { m_Pcb->m_CurrentLimitZone = newedge = new EDGE_ZONE( m_Pcb ); @@ -694,8 +690,7 @@ EDGE_ZONE* WinEDA_PcbFrame::Begin_Zone() else /* piste en cours : les coord du point d'arrivee ont ete mises * a jour par la routine Show_Zone_Edge_While_MoveMouse*/ { - if( (oldedge->m_Start.x != oldedge->m_End.x) - || (oldedge->m_Start.y != oldedge->m_End.y) ) + if( oldedge->m_Start != oldedge->m_End ) { newedge = new EDGE_ZONE( oldedge ); newedge->Pback = oldedge; @@ -834,11 +829,15 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC ) DisplayError( this, wxT( "Board is empty!" ), 10 ); return; } + DrawPanel->m_IgnoreMouseEvents = TRUE; WinEDA_ZoneFrame* frame = new WinEDA_ZoneFrame( this ); - ii = frame->ShowModal(); frame->Destroy(); + + ii = frame->ShowModal(); + frame->Destroy(); DrawPanel->MouseToCursorSchema(); DrawPanel->m_IgnoreMouseEvents = FALSE; + if( ii ) return; @@ -856,7 +855,9 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC ) s_TimeStamp = time( NULL ); /* 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; /* calcule de Ncols et Nrow, taille de la matrice de routage */ @@ -865,8 +866,10 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC ) /* Determination de la cellule pointee par la souris */ ZoneStartFill.x = ( GetScreen()->m_Curseur.x - m_Pcb->m_BoundaryBox.m_Pos.x + (g_GridRoutingSize / 2) ) / g_GridRoutingSize; + ZoneStartFill.y = ( GetScreen()->m_Curseur.y - m_Pcb->m_BoundaryBox.m_Pos.y + (g_GridRoutingSize / 2) ) / g_GridRoutingSize; + if( ZoneStartFill.x < 0 ) ZoneStartFill.x = 0; if( ZoneStartFill.x >= Ncols ) @@ -886,8 +889,10 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC ) msg.Printf( wxT( "%d" ), Ncols ); Affiche_1_Parametre( this, 1, wxT( "Cols" ), msg, GREEN ); + msg.Printf( wxT( "%d" ), Nrows ); Affiche_1_Parametre( this, 7, wxT( "Lines" ), msg, GREEN ); + msg.Printf( wxT( "%d" ), Board.m_MemSize / 1024 ); Affiche_1_Parametre( this, 14, wxT( "Mem(Ko)" ), msg, CYAN ); @@ -922,10 +927,13 @@ void WinEDA_PcbFrame::Fill_Zone( wxDC* DC ) { if( g_HightLigth_NetCode != pt_segm->GetNet() ) continue; + if( pt_segm->GetLayer() != GetScreen()->m_Active_Layer ) continue; + if( pt_segm->Type() != TYPETRACK ) continue; + TraceSegmentPcb( m_Pcb, pt_segm, CELL_is_FRIEND, 0, WRITE_CELL ); }