2007-08-20 01:20:48 +00:00
|
|
|
/****************************************/
|
|
|
|
/* Module to load/save EESchema files. */
|
|
|
|
/****************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2008-04-12 18:39:20 +00:00
|
|
|
//#include "gr_basic.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
#include "id.h"
|
|
|
|
|
|
|
|
/* Format des fichiers:
|
2007-08-20 01:20:48 +00:00
|
|
|
* - entete:
|
|
|
|
* EESchema Schematic File Version n
|
|
|
|
* - liste des librairies utilisees
|
|
|
|
* LIBS:lib1,lib2,...
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2007-08-20 01:20:48 +00:00
|
|
|
* - description des elements:
|
|
|
|
* - ici Dimensions du schema, cartouche..:
|
|
|
|
* $Descr A3 xx yy (format A3 (A..A0 / A..E / "user") xx yy = dims internes )
|
|
|
|
* $EndDescr
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2007-08-20 01:20:48 +00:00
|
|
|
* - ici: polyline
|
|
|
|
* P L 0 3
|
|
|
|
* 2208 1008
|
|
|
|
* 2208 1136
|
|
|
|
* 2128 1136
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2007-08-20 01:20:48 +00:00
|
|
|
* - ici: Segment (wire, bus) ( 1; W = segment type Wire, 2: W = Wire B = Bus
|
|
|
|
* 3: L ou B = epaisseur ( L = ligne, B = bus)
|
|
|
|
* W W L (W B B si bus)
|
|
|
|
* 1856 1008 1856 1136 (debut X,Y fin X,Y)
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2007-08-20 01:20:48 +00:00
|
|
|
* - ici: Raccord (wire, bus)
|
|
|
|
* R W L
|
|
|
|
* 1856 1008 1856 1136 (debut X,Y fin X,Y)
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2007-08-20 01:20:48 +00:00
|
|
|
* - ici: Sheet ( Sous-feuille de hierarchie)
|
|
|
|
* $Sheet
|
|
|
|
* S 1856 1008 1856 1136 (debut X,Y fin X,Y)
|
|
|
|
* F0 "texte" X X posx posy ; sheetname
|
|
|
|
* F1 "texte" X X posx posy ; filename
|
|
|
|
* Fn "label" type side posx posy size ; n lignes de label
|
|
|
|
* $EndSheet
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2007-08-20 01:20:48 +00:00
|
|
|
* - ici: composant
|
|
|
|
* $Comp
|
|
|
|
* L CAPACITOR C1 H H -30863 -14794 1968 1184 nom, ref, dir et pos
|
|
|
|
* 1 2016 1136 1904 1024 2128 1248 multi, posx,y, rect encadrement
|
|
|
|
* 1 0 0 -1 matrice de rotation/miroir
|
|
|
|
* $EndComp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* Fonctions locales */
|
2007-08-20 01:20:48 +00:00
|
|
|
static int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, BASE_SCREEN* Window );
|
2008-02-12 21:12:46 +00:00
|
|
|
static int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, BASE_SCREEN* Window);
|
2007-08-20 01:20:48 +00:00
|
|
|
static int ReadSchemaDescr( wxWindow* frame, char* Line, FILE* f, BASE_SCREEN* Window );
|
|
|
|
static void LoadLayers( FILE* f, int* linecnt );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* Variables locales */
|
2007-08-20 01:20:48 +00:00
|
|
|
static int LineCount; /* Decompte de num de ligne lue dans eeload() */
|
|
|
|
static wxString MsgDiag; /* Error and log messages */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/************************************************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& FullFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
/************************************************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Routine to load an EESchema file.
|
2008-02-12 21:12:46 +00:00
|
|
|
* Returns TRUE if file has been loaded (at least partially.)
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
char Line[1024], * SLine;
|
|
|
|
char Name1[256],
|
|
|
|
Name2[256];
|
|
|
|
int ii, layer, orient, size;
|
|
|
|
wxPoint pos;
|
|
|
|
bool Failed = FALSE;
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* Phead, * Pnext;
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawJunctionStruct* ConnectionStruct;
|
|
|
|
DrawPolylineStruct* PolylineStruct;
|
|
|
|
EDA_DrawLineStruct* SegmentStruct;
|
|
|
|
DrawBusEntryStruct* RaccordStruct;
|
|
|
|
DrawMarkerStruct* MarkerStruct;
|
|
|
|
DrawNoConnectStruct* NoConnectStruct;
|
|
|
|
|
|
|
|
FILE* f;
|
|
|
|
|
|
|
|
if( screen == NULL )
|
|
|
|
return FALSE;
|
|
|
|
if( FullFileName.IsEmpty() )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
screen->SetCurItem( NULL );
|
2008-03-20 01:50:21 +00:00
|
|
|
screen->m_FileName = FullFileName;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
LineCount = 1;
|
|
|
|
if( ( f = wxFopen( FullFileName, wxT( "rt" ) ) ) == NULL )
|
|
|
|
{
|
|
|
|
MsgDiag = _( "Failed to open " ) + FullFileName;
|
|
|
|
DisplayError( this, MsgDiag );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
MsgDiag = _( "Loading " ) + screen->m_FileName;
|
2007-08-20 01:20:48 +00:00
|
|
|
PrintMsg( MsgDiag );
|
|
|
|
|
|
|
|
if( fgets( Line, 1024 - 1, f ) == NULL
|
|
|
|
|| strncmp( Line + 9, SCHEMATIC_HEAD_STRING, sizeof(SCHEMATIC_HEAD_STRING) - 1 )
|
|
|
|
!= 0 )
|
|
|
|
{
|
2008-04-06 16:05:23 +00:00
|
|
|
MsgDiag = FullFileName + _( " is NOT an EESchema file!" );
|
2007-08-20 01:20:48 +00:00
|
|
|
DisplayError( this, MsgDiag );
|
|
|
|
fclose( f );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-04-06 15:12:24 +00:00
|
|
|
//get the file version here. TODO: Support version numbers > 9
|
2008-03-20 01:50:21 +00:00
|
|
|
char version = Line[9 + sizeof(SCHEMATIC_HEAD_STRING)];
|
2008-04-06 15:12:24 +00:00
|
|
|
int ver = version - '0';
|
|
|
|
if ( ver > EESCHEMA_VERSION )
|
|
|
|
{
|
|
|
|
MsgDiag = FullFileName + _( " was created by a more recent version of EESchema and may not load correctly. Please consider updating!");
|
|
|
|
DisplayInfo( this, MsgDiag);
|
|
|
|
}
|
2008-04-15 19:38:19 +00:00
|
|
|
#if 0
|
|
|
|
// Compile it if the new versiopn is unreadable by previous eeschema versions
|
2008-04-06 15:12:24 +00:00
|
|
|
else if ( ver < EESCHEMA_VERSION )
|
|
|
|
{
|
|
|
|
MsgDiag = FullFileName + _( " was created by an older version of EESchema. It will be stored in the new file format when you save this file again.");
|
|
|
|
DisplayInfo( this, MsgDiag);
|
|
|
|
}
|
2008-04-15 19:38:19 +00:00
|
|
|
#endif
|
2008-04-06 15:12:24 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
LineCount++;
|
|
|
|
if( fgets( Line, 1024 - 1, f ) == NULL || strncmp( Line, "LIBS:", 5 ) != 0 )
|
|
|
|
{
|
2008-04-06 16:05:23 +00:00
|
|
|
MsgDiag = FullFileName + _( " is NOT an EESchema file!" );
|
2007-08-20 01:20:48 +00:00
|
|
|
DisplayError( this, MsgDiag );
|
|
|
|
fclose( f );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadLayers( f, &LineCount );
|
|
|
|
|
|
|
|
while( !feof( f ) && GetLine( f, Line, &LineCount, sizeof(Line) ) != NULL )
|
|
|
|
{
|
|
|
|
SLine = Line;
|
|
|
|
while( (*SLine != ' ' ) && *SLine )
|
|
|
|
SLine++;
|
|
|
|
|
|
|
|
switch( Line[0] )
|
|
|
|
{
|
|
|
|
case '$': /* identification de bloc */
|
|
|
|
if( Line[1] == 'C' )
|
|
|
|
{
|
|
|
|
Failed = ReadPartDescr( this, Line, f, screen );
|
|
|
|
}
|
|
|
|
else if( Line[1] == 'S' )
|
|
|
|
{
|
|
|
|
Failed = ReadSheetDescr( this, Line, f, screen );
|
|
|
|
}
|
|
|
|
else if( Line[1] == 'D' )
|
|
|
|
{
|
|
|
|
Failed = ReadSchemaDescr( this, Line, f, screen );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'L': /* Its a library item. */
|
|
|
|
Failed = ReadPartDescr( this, Line, f, screen );
|
|
|
|
break; /* Fin lecture 1 composant */
|
|
|
|
|
|
|
|
|
|
|
|
case 'W': /* Its a Segment (WIRE or BUS) item. */
|
|
|
|
if( sscanf( SLine, "%s %s", Name1, Name2 ) != 2 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file Segment struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
layer = LAYER_NOTES;
|
|
|
|
if( Name1[0] == 'W' )
|
|
|
|
layer = LAYER_WIRE;
|
|
|
|
if( Name1[0] == 'B' )
|
|
|
|
layer = LAYER_BUS;
|
|
|
|
|
|
|
|
SegmentStruct = new EDA_DrawLineStruct( wxPoint( 0, 0 ), layer );
|
|
|
|
|
|
|
|
LineCount++;
|
|
|
|
if( fgets( Line, 256 - 1, f ) == NULL
|
|
|
|
|| sscanf( Line, "%d %d %d %d ",
|
|
|
|
&SegmentStruct->m_Start.x, &SegmentStruct->m_Start.y,
|
|
|
|
&SegmentStruct->m_End.x, &SegmentStruct->m_End.y ) != 4 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file Segment struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
2008-03-20 01:50:21 +00:00
|
|
|
SAFE_DELETE( SegmentStruct ) ;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !Failed )
|
|
|
|
{
|
|
|
|
SegmentStruct->Pnext = screen->EEDrawList;
|
2008-04-14 19:22:48 +00:00
|
|
|
screen->EEDrawList = SegmentStruct;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 'E': /* Its a Raccord (WIRE or BUS) item. */
|
|
|
|
if( sscanf( SLine, "%s %s", Name1, Name2 ) != 2 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
2008-02-12 21:12:46 +00:00
|
|
|
wxT( "EESchema file record struct error at line %d, aborted" ),
|
2007-08-20 01:20:48 +00:00
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ii = WIRE_TO_BUS;
|
|
|
|
if( Name1[0] == 'B' )
|
|
|
|
ii = BUS_TO_BUS;
|
|
|
|
RaccordStruct = new DrawBusEntryStruct( wxPoint( 0, 0 ), '\\', ii );
|
|
|
|
LineCount++;
|
|
|
|
if( fgets( Line, 256 - 1, f ) == NULL
|
|
|
|
|| sscanf( Line, "%d %d %d %d ",
|
|
|
|
&RaccordStruct->m_Pos.x, &RaccordStruct->m_Pos.y,
|
|
|
|
&RaccordStruct->m_Size.x, &RaccordStruct->m_Size.y ) != 4 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file Raccord struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
2008-03-20 01:50:21 +00:00
|
|
|
SAFE_DELETE( RaccordStruct ) ;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !Failed )
|
|
|
|
{
|
|
|
|
RaccordStruct->m_Size.x -= RaccordStruct->m_Pos.x;
|
|
|
|
RaccordStruct->m_Size.y -= RaccordStruct->m_Pos.y;
|
|
|
|
RaccordStruct->Pnext = screen->EEDrawList;
|
|
|
|
screen->EEDrawList = RaccordStruct;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P': /* Its a polyline item. */
|
|
|
|
if( sscanf( SLine, "%s %s %d", Name1, Name2, &ii ) != 3 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file polyline struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
layer = LAYER_NOTES;
|
|
|
|
if( Name2[0] == 'W' )
|
|
|
|
layer = LAYER_WIRE;
|
|
|
|
if( Name2[0] == 'B' )
|
|
|
|
layer = LAYER_BUS;
|
|
|
|
|
|
|
|
PolylineStruct = new DrawPolylineStruct( layer );
|
|
|
|
|
|
|
|
PolylineStruct->m_NumOfPoints = ii;
|
|
|
|
PolylineStruct->m_Points = (int*) MyZMalloc( sizeof(int) * 2 *
|
|
|
|
PolylineStruct->m_NumOfPoints );
|
|
|
|
for( ii = 0; ii < PolylineStruct->m_NumOfPoints; ii++ )
|
|
|
|
{
|
|
|
|
LineCount++;
|
|
|
|
if( fgets( Line, 256 - 1, f ) == NULL
|
|
|
|
|| sscanf( Line, "%d %d", &PolylineStruct->m_Points[ii * 2],
|
|
|
|
&PolylineStruct->m_Points[ii * 2 + 1] ) != 2 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file polyline struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
2008-03-20 01:50:21 +00:00
|
|
|
SAFE_DELETE( PolylineStruct ) ;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !Failed )
|
|
|
|
{
|
|
|
|
PolylineStruct->Pnext = screen->EEDrawList;
|
2008-04-14 19:22:48 +00:00
|
|
|
screen->EEDrawList = PolylineStruct;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C': /* Its a connection item. */
|
|
|
|
ConnectionStruct = new DrawJunctionStruct( wxPoint( 0, 0 ) );
|
|
|
|
if( sscanf( SLine, "%s %d %d", Name1,
|
|
|
|
&ConnectionStruct->m_Pos.x,
|
|
|
|
&ConnectionStruct->m_Pos.y ) != 3 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file connection struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
2008-03-20 01:50:21 +00:00
|
|
|
SAFE_DELETE( ConnectionStruct ) ;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConnectionStruct->Pnext = screen->EEDrawList;
|
|
|
|
screen->EEDrawList = ConnectionStruct;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'N': /* Its a NoConnect item. */
|
|
|
|
if( sscanf( SLine, "%s %d %d", Name1, &pos.x, &pos.y ) != 3 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file NoConnect struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NoConnectStruct = new DrawNoConnectStruct( pos );
|
|
|
|
NoConnectStruct->Pnext = screen->EEDrawList;
|
|
|
|
screen->EEDrawList = NoConnectStruct;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'K': /* Its a MarKer item. */
|
|
|
|
if( sscanf( SLine, "%s %d %d", Name1, &pos.x, &pos.y ) != 3 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file marker struct error line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char* text;
|
|
|
|
char BufLine[1024];
|
|
|
|
MarkerStruct = new DrawMarkerStruct( pos, wxEmptyString );
|
|
|
|
ii = ReadDelimitedText( BufLine, Line, 256 );
|
|
|
|
MarkerStruct->m_Type = (TypeMarker) ( (Name1[0] & 255) - 'A' );
|
|
|
|
if( MarkerStruct->m_Type < 0 )
|
|
|
|
MarkerStruct->m_Type = MARQ_UNSPEC;
|
|
|
|
if( ii )
|
|
|
|
MarkerStruct->m_Comment = CONV_FROM_UTF8( BufLine );
|
|
|
|
text = strstr( Line, " F=" );
|
|
|
|
if( text )
|
|
|
|
{
|
|
|
|
sscanf( text + 3, "%X", &ii );
|
|
|
|
MarkerStruct->m_MarkFlags = ii;
|
|
|
|
}
|
|
|
|
MarkerStruct->Pnext = screen->EEDrawList;
|
|
|
|
screen->EEDrawList = MarkerStruct;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'T': /* Its a text item. */
|
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* Struct = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
*Name1 = *Name2 = 0;
|
|
|
|
ii = sscanf( SLine, "%s %d %d %d %d %s",
|
|
|
|
Name1, &pos.x, &pos.y, &orient, &size, Name2 );
|
|
|
|
|
|
|
|
if( ii < 4 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file text struct error line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
}
|
|
|
|
else if( fgets( Line, 256 - 1, f ) == NULL )
|
|
|
|
{
|
|
|
|
LineCount++;
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file text struct error line %d (No text), aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LineCount++;
|
|
|
|
if( size == 0 )
|
|
|
|
size = DEFAULT_SIZE_TEXT;
|
|
|
|
char* text = strtok( Line, "\n\r" );
|
|
|
|
if( text == NULL )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( Name1[0] == 'L' )
|
|
|
|
{
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_LABEL* TextStruct =
|
|
|
|
new SCH_LABEL( pos, CONV_FROM_UTF8( text ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
TextStruct->m_Size.x = TextStruct->m_Size.y = size;
|
|
|
|
TextStruct->m_Orient = orient;
|
2008-04-14 19:22:48 +00:00
|
|
|
Struct = TextStruct;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
else if( Name1[0] == 'G' && version > '1')
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_GLOBALLABEL* TextStruct = new SCH_GLOBALLABEL(pos, CONV_FROM_UTF8( text ) );
|
|
|
|
Struct = TextStruct;
|
2008-02-12 21:12:46 +00:00
|
|
|
TextStruct->m_Size.x = TextStruct->m_Size.y = size;
|
|
|
|
TextStruct->m_Orient = orient;
|
2008-03-20 01:50:21 +00:00
|
|
|
TextStruct->m_Shape = NET_INPUT;
|
2008-02-12 21:12:46 +00:00
|
|
|
if( stricmp( Name2, SheetLabelType[NET_OUTPUT] ) == 0 )
|
|
|
|
TextStruct->m_Shape = NET_OUTPUT;
|
|
|
|
if( stricmp( Name2, SheetLabelType[NET_BIDI] ) == 0 )
|
|
|
|
TextStruct->m_Shape = NET_BIDI;
|
|
|
|
if( stricmp( Name2, SheetLabelType[NET_TRISTATE] ) == 0 )
|
|
|
|
TextStruct->m_Shape = NET_TRISTATE;
|
|
|
|
if( stricmp( Name2, SheetLabelType[NET_UNSPECIFIED] ) == 0 )
|
|
|
|
TextStruct->m_Shape = NET_UNSPECIFIED;
|
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
else if( (Name1[0] == 'H') || (Name1[0] == 'G' && version == '1'))
|
|
|
|
{ //in schematic file version 1, glabels were actually hierarchal labels.
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_HIERLABEL* TextStruct = new SCH_HIERLABEL(pos, CONV_FROM_UTF8( text ) );
|
|
|
|
Struct = TextStruct;
|
2007-08-20 01:20:48 +00:00
|
|
|
TextStruct->m_Size.x = TextStruct->m_Size.y = size;
|
|
|
|
TextStruct->m_Orient = orient;
|
2008-03-20 01:50:21 +00:00
|
|
|
TextStruct->m_Shape = NET_INPUT;
|
2007-08-20 01:20:48 +00:00
|
|
|
if( stricmp( Name2, SheetLabelType[NET_OUTPUT] ) == 0 )
|
|
|
|
TextStruct->m_Shape = NET_OUTPUT;
|
|
|
|
if( stricmp( Name2, SheetLabelType[NET_BIDI] ) == 0 )
|
|
|
|
TextStruct->m_Shape = NET_BIDI;
|
|
|
|
if( stricmp( Name2, SheetLabelType[NET_TRISTATE] ) == 0 )
|
|
|
|
TextStruct->m_Shape = NET_TRISTATE;
|
|
|
|
if( stricmp( Name2, SheetLabelType[NET_UNSPECIFIED] ) == 0 )
|
|
|
|
TextStruct->m_Shape = NET_UNSPECIFIED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_TEXT* TextStruct =
|
|
|
|
new SCH_TEXT( pos, CONV_FROM_UTF8( text ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
TextStruct->m_Size.x = TextStruct->m_Size.y = size;
|
|
|
|
TextStruct->m_Orient = orient;
|
2008-04-14 19:22:48 +00:00
|
|
|
Struct = TextStruct;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
if( Struct )
|
|
|
|
{
|
|
|
|
Struct->Pnext = screen->EEDrawList;
|
|
|
|
screen->EEDrawList = Struct;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
Failed = FALSE;
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file undef structdef at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Failed )
|
|
|
|
{
|
|
|
|
DisplayError( this, MsgDiag );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EEDrawList was constructed in reverse order - reverse it back: */
|
|
|
|
Phead = NULL;
|
|
|
|
while( screen->EEDrawList )
|
|
|
|
{
|
|
|
|
Pnext = screen->EEDrawList;
|
2008-04-14 19:22:48 +00:00
|
|
|
screen->EEDrawList = screen->EEDrawList->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
Pnext->Pnext = Phead;
|
|
|
|
Phead = Pnext;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen->EEDrawList = Phead;
|
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#if 1 && defined(DEBUG)
|
2007-09-20 21:06:49 +00:00
|
|
|
screen->Show( 0, std::cout );
|
|
|
|
#endif
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
fclose( f );
|
|
|
|
|
|
|
|
TestDanglingEnds( screen->EEDrawList, NULL );
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
MsgDiag = _( "Done Loading " ) + screen->m_FileName;
|
|
|
|
PrintMsg( MsgDiag );
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
return TRUE; /* Although it may be that file is only partially loaded. */
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
static int ReadPartDescr( wxWindow* frame, char* Line, FILE* f,
|
|
|
|
BASE_SCREEN* Window )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*************************************************************/
|
|
|
|
|
|
|
|
/* Fonction utilisee par LoadEEFile().
|
2007-08-20 01:20:48 +00:00
|
|
|
* Lit les lignes relatives a la description d'un composant en schema
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int ii, fieldref;
|
|
|
|
char Name1[256], Name2[256],
|
|
|
|
Char1[256], Char2[256], Char3[256];
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* LibItemStruct;
|
2007-08-20 01:20:48 +00:00
|
|
|
int Failed = 0, newfmt = 0;
|
|
|
|
char* ptcar;
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
LibItemStruct = new SCH_COMPONENT();
|
2007-08-20 01:20:48 +00:00
|
|
|
LibItemStruct->m_Convert = 1;
|
|
|
|
|
|
|
|
if( Line[0] == '$' )
|
|
|
|
{
|
|
|
|
newfmt = 1;
|
|
|
|
LineCount++;
|
|
|
|
if( fgets( Line, 256 - 1, f ) == 0 )
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Traitement de la 1ere ligne de description */
|
|
|
|
if( sscanf( &Line[1], "%s %s", Name1, Name2 ) != 2 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema Component descr error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
return Failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strcmp( Name1, NULL_STRING ) != 0 )
|
|
|
|
{
|
|
|
|
for( ii = 0; ii < (int) strlen( Name1 ); ii++ )
|
|
|
|
if( Name1[ii] == '~' )
|
|
|
|
Name1[ii] = ' ';
|
|
|
|
|
|
|
|
LibItemStruct->m_ChipName = CONV_FROM_UTF8( Name1 );
|
|
|
|
if( !newfmt )
|
|
|
|
LibItemStruct->m_Field[VALUE].m_Text = CONV_FROM_UTF8( Name1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LibItemStruct->m_ChipName.Empty();
|
|
|
|
LibItemStruct->m_Field[VALUE].m_Text.Empty();
|
|
|
|
LibItemStruct->m_Field[VALUE].m_Orient = TEXT_ORIENT_HORIZ;
|
|
|
|
LibItemStruct->m_Field[VALUE].m_Attributs = TEXT_NO_VISIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strcmp( Name2, NULL_STRING ) != 0 )
|
|
|
|
{
|
2008-03-20 01:50:21 +00:00
|
|
|
bool isDigit = false;
|
2008-02-12 21:12:46 +00:00
|
|
|
for( ii = 0; ii < (int) strlen( Name2 ); ii++ ){
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Name2[ii] == '~' )
|
|
|
|
Name2[ii] = ' ';
|
2008-03-20 01:50:21 +00:00
|
|
|
//get RefBase from this, too. store in Name1.
|
|
|
|
if(Name2[ii] >= '0' && Name2[ii] <= '9'){
|
|
|
|
isDigit = true;
|
|
|
|
Name1[ii] = 0; //null-terminate.
|
|
|
|
}
|
|
|
|
if(!isDigit){
|
|
|
|
Name1[ii] = Name2[ii];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Name1[ii] = 0; //just in case
|
|
|
|
int jj;
|
|
|
|
for(jj=0; jj<ii && Name1[jj] == ' '; jj++);
|
|
|
|
if(jj == ii){
|
|
|
|
//blank string.
|
|
|
|
LibItemStruct->m_PrefixString = wxT("U");
|
|
|
|
}else{
|
|
|
|
LibItemStruct->m_PrefixString = CONV_FROM_UTF8(&Name1[jj]);
|
|
|
|
//printf("prefix: %s\n", CONV_TO_UTF8(LibItemStruct->m_PrefixString));
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
if( !newfmt )
|
|
|
|
LibItemStruct->m_Field[REFERENCE].m_Text = CONV_FROM_UTF8( Name2 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LibItemStruct->m_Field[REFERENCE].m_Attributs = TEXT_NO_VISIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Traitement des autres lignes de description */
|
|
|
|
|
|
|
|
/* Ces lignes commencent par:
|
|
|
|
* "P " = position
|
|
|
|
* "U " = Num Unit, et Conversion
|
|
|
|
* "Fn" = Champs ( n = 0.. = numero de champ )
|
2008-03-20 01:50:21 +00:00
|
|
|
* "Ar" = AlternateReference, in the case of multiple sheets
|
|
|
|
* referring to one schematic file.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Lecture des champs */
|
|
|
|
for( ; ; )
|
|
|
|
{
|
|
|
|
LineCount++;
|
|
|
|
if( fgets( Line, 256 - 1, f ) == NULL )
|
|
|
|
return TRUE;
|
|
|
|
if( (Line[0] != 'F' )
|
|
|
|
&& (Line[0] != 'P' )
|
2008-03-20 01:50:21 +00:00
|
|
|
&& (Line[0] != 'A' )
|
2007-08-20 01:20:48 +00:00
|
|
|
&& (Line[0] != 'U' ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( Line[0] == 'U' ) /* Lecture num multi, conversion et time stamp */
|
|
|
|
{
|
|
|
|
sscanf( Line + 1, "%d %d %lX",
|
|
|
|
&LibItemStruct->m_Multi, &LibItemStruct->m_Convert,
|
|
|
|
&LibItemStruct->m_TimeStamp );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Line[0] == 'P' )
|
|
|
|
{
|
|
|
|
sscanf( Line + 1, "%d %d",
|
|
|
|
&LibItemStruct->m_Pos.x, &LibItemStruct->m_Pos.y );
|
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
if( Line[0] == 'A' && Line[1] == 'R' )
|
|
|
|
{
|
|
|
|
/*format:
|
2008-04-16 08:40:31 +00:00
|
|
|
AR Path="/9086AF6E/67452AA0" Ref="C99" Part="1"
|
2008-03-20 01:50:21 +00:00
|
|
|
where 9086AF6E is the unique timestamp of the containing sheet
|
|
|
|
and 67452AA0 is the timestamp of this component.
|
|
|
|
C99 is the reference given this path.
|
|
|
|
*/
|
2008-04-16 08:40:31 +00:00
|
|
|
int ii;
|
|
|
|
ptcar = Line + 2;
|
2008-03-20 01:50:21 +00:00
|
|
|
//copy the path.
|
2008-04-16 08:40:31 +00:00
|
|
|
ii = ReadDelimitedText(Name1, ptcar, 255 );
|
|
|
|
ptcar += ii+1;
|
2008-03-20 01:50:21 +00:00
|
|
|
wxString path = CONV_FROM_UTF8(Name1);
|
2008-04-16 08:40:31 +00:00
|
|
|
// copy the reference
|
|
|
|
ii = ReadDelimitedText(Name1, ptcar, 255 );
|
|
|
|
ptcar += ii+1;
|
2008-03-20 01:50:21 +00:00
|
|
|
wxString ref = CONV_FROM_UTF8(Name1);
|
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
// copy the multi, if exists
|
|
|
|
ii = ReadDelimitedText(Name1, ptcar, 255 );
|
|
|
|
if ( Name1[0] == 0 ) // Nothing read, put a default value
|
|
|
|
sprintf( Name1, "%d", LibItemStruct->m_Multi );
|
|
|
|
int multi = atoi(Name1);
|
|
|
|
if ( multi < 0 || multi > 25 ) multi = 1;
|
|
|
|
LibItemStruct->AddHierarchicalReference(path, ref, multi);
|
2008-03-20 01:50:21 +00:00
|
|
|
LibItemStruct->m_Field[REFERENCE].m_Text = ref;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Line[0] == 'F' )
|
|
|
|
{
|
|
|
|
char FieldUserName[1024];
|
|
|
|
int hjustify = GR_TEXT_HJUSTIFY_CENTER;
|
|
|
|
int vjustify = GR_TEXT_VJUSTIFY_CENTER;
|
|
|
|
|
|
|
|
FieldUserName[0] = 0;
|
|
|
|
|
|
|
|
sscanf( Line + 1, "%d", &fieldref );
|
|
|
|
if( fieldref >= NUMBER_OF_FIELDS )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "Component Field number error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* Lecture du champ */
|
|
|
|
ptcar = Line; while( *ptcar && (*ptcar != '"') )
|
|
|
|
ptcar++;
|
|
|
|
|
|
|
|
if( *ptcar != '"' )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file lib field F at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ptcar++, ii = 0; ; ii++, ptcar++ )
|
|
|
|
{
|
|
|
|
Name1[ii] = *ptcar;
|
|
|
|
if( *ptcar == 0 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "Component field F at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if( *ptcar == '"' )
|
|
|
|
{
|
|
|
|
Name1[ii] = 0; ptcar++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( LibItemStruct->m_Field[fieldref].m_Text.IsEmpty() )
|
|
|
|
LibItemStruct->m_Field[fieldref].m_Text = CONV_FROM_UTF8( Name1 );
|
|
|
|
|
|
|
|
/* Lecture des coordonnees */
|
|
|
|
if( ( ii = sscanf( ptcar, "%s %d %d %d %X %s %s", Char1,
|
|
|
|
&LibItemStruct->m_Field[fieldref].m_Pos.x,
|
|
|
|
&LibItemStruct->m_Field[fieldref].m_Pos.y,
|
|
|
|
&LibItemStruct->m_Field[fieldref].m_Size.x,
|
|
|
|
&LibItemStruct->m_Field[fieldref].m_Attributs,
|
|
|
|
Char2, Char3 ) ) < 4 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "Component Field error line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
DisplayError( frame, MsgDiag );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadDelimitedText( FieldUserName, ptcar, sizeof(FieldUserName) );
|
|
|
|
if( (LibItemStruct->m_Field[fieldref].m_Size.x == 0 ) || (ii == 4) )
|
|
|
|
LibItemStruct->m_Field[fieldref].m_Size.x = DEFAULT_SIZE_TEXT;
|
|
|
|
LibItemStruct->m_Field[fieldref].m_Orient = TEXT_ORIENT_HORIZ;
|
|
|
|
LibItemStruct->m_Field[fieldref].m_Size.y = LibItemStruct->m_Field[fieldref].m_Size.x;
|
|
|
|
if( Char1[0] == 'V' )
|
|
|
|
LibItemStruct->m_Field[fieldref].m_Orient = TEXT_ORIENT_VERT;
|
|
|
|
if( ii >= 7 )
|
|
|
|
{
|
|
|
|
if( *Char2 == 'L' )
|
|
|
|
hjustify = GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
else if( *Char2 == 'R' )
|
|
|
|
hjustify = GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
if( *Char3 == 'B' )
|
|
|
|
vjustify = GR_TEXT_VJUSTIFY_BOTTOM;
|
|
|
|
else if( *Char3 == 'T' )
|
|
|
|
vjustify = GR_TEXT_VJUSTIFY_TOP;
|
|
|
|
LibItemStruct->m_Field[fieldref].m_HJustify = hjustify;
|
|
|
|
LibItemStruct->m_Field[fieldref].m_VJustify = vjustify;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fieldref >= FIELD1 )
|
|
|
|
{
|
|
|
|
LibItemStruct->m_Field[fieldref].m_Name = CONV_FROM_UTF8( FieldUserName );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( fieldref == REFERENCE )
|
|
|
|
if( LibItemStruct->m_Field[fieldref].m_Text[0] == '#' )
|
|
|
|
LibItemStruct->m_Field[fieldref].m_Attributs |= TEXT_NO_VISIBLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lecture multi et position du composant */
|
|
|
|
if( sscanf( Line, "%d %d %d",
|
|
|
|
&LibItemStruct->m_Multi,
|
|
|
|
&LibItemStruct->m_Pos.x, &LibItemStruct->m_Pos.y ) != 3 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "Component unit & pos error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
return Failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lecture de la matrice de miroir / rotation */
|
|
|
|
LineCount++;
|
|
|
|
if( (fgets( Line, 256 - 1, f ) == NULL)
|
|
|
|
|| (sscanf( Line, "%d %d %d %d",
|
|
|
|
&LibItemStruct->m_Transform[0][0],
|
|
|
|
&LibItemStruct->m_Transform[0][1],
|
|
|
|
&LibItemStruct->m_Transform[1][0],
|
|
|
|
&LibItemStruct->m_Transform[1][1] ) != 4) )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "Component orient error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
return Failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( newfmt )
|
|
|
|
{
|
|
|
|
LineCount++;
|
|
|
|
if( fgets( Line, 256 - 1, f ) == NULL )
|
|
|
|
return TRUE;
|
|
|
|
if( strnicmp( "$End", Line, 4 ) != 0 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "Component End expected at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !Failed )
|
|
|
|
{
|
|
|
|
LibItemStruct->Pnext = Window->EEDrawList;
|
2008-04-14 19:22:48 +00:00
|
|
|
Window->EEDrawList = LibItemStruct;
|
2008-03-20 01:50:21 +00:00
|
|
|
LibItemStruct->m_Parent = Window;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Failed; /* Fin lecture 1 composant */
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
static int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f, BASE_SCREEN* Window )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*************************************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Fonction utilisee par LoadEEFile().
|
2007-08-20 01:20:48 +00:00
|
|
|
* Lit les lignes relatives a la description d'une feuille de hierarchie
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int ii, fieldref, size;
|
|
|
|
char Name1[256], Char1[256], Char2[256];
|
|
|
|
DrawSheetStruct* SheetStruct;
|
2008-04-15 19:38:19 +00:00
|
|
|
Hierarchical_PIN_Sheet_Struct* SheetLabelStruct, * OldSheetLabel = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
int Failed = FALSE;
|
|
|
|
char* ptcar;
|
|
|
|
|
|
|
|
SheetStruct = new DrawSheetStruct();
|
2008-03-20 01:50:21 +00:00
|
|
|
SheetStruct->m_TimeStamp = GetTimeStamp();
|
|
|
|
//sheets are added to the EEDrawList like other schematic components.
|
|
|
|
//however, in order to preserve the heirarchy (through m_Parent pointers),
|
|
|
|
//a duplicate of the sheet is added to m_SubSheet array.
|
|
|
|
//must be a duplicate, references just work for a two-layer structure.
|
|
|
|
//this is accomplished through the Sync() function.
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( Line[0] == '$' ) /* Ligne doit etre "$Sheet" */
|
|
|
|
{
|
|
|
|
LineCount++;
|
|
|
|
if( fgets( Line, 256 - 1, f ) == 0 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf( wxT( "Read File Errror" ) ); return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next line: must be "S xx yy nn mm" with xx, yy = sheet position
|
|
|
|
* ( upper left corner ) et nn,mm = sheet size */
|
|
|
|
if( (sscanf( &Line[1], "%d %d %d %d",
|
|
|
|
&SheetStruct->m_Pos.x, &SheetStruct->m_Pos.y,
|
|
|
|
&SheetStruct->m_Size.x, &SheetStruct->m_Size.y ) != 4)
|
|
|
|
|| (Line[0] != 'S' ) )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( " ** EESchema file sheet struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
return Failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lecture des champs */
|
|
|
|
for( ; ; ) /* Analyse des lignes "Fn "texte" .." */
|
|
|
|
{
|
|
|
|
LineCount++;
|
|
|
|
if( fgets( Line, 256 - 1, f ) == NULL )
|
|
|
|
return TRUE;
|
2008-03-20 01:50:21 +00:00
|
|
|
if( Line[0] == 'U' ){
|
|
|
|
sscanf( Line + 1, "%lX", &(SheetStruct->m_TimeStamp) );
|
|
|
|
if(SheetStruct->m_TimeStamp == 0) //zero is not unique!
|
|
|
|
SheetStruct->m_TimeStamp = GetTimeStamp();
|
|
|
|
continue;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Line[0] != 'F' )
|
|
|
|
break;
|
|
|
|
sscanf( Line + 1, "%d", &fieldref );
|
|
|
|
|
|
|
|
/* Lecture du champ :
|
|
|
|
* si fieldref >= 2 : Fn "texte" t s posx posy
|
|
|
|
* sinon F0 "texte" pour sheetname
|
|
|
|
* et F1 "texte" pour filename */
|
|
|
|
|
|
|
|
ptcar = Line; while( *ptcar && (*ptcar != '"') )
|
|
|
|
ptcar++;
|
|
|
|
|
|
|
|
if( *ptcar != '"' )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( " ** EESchema file sheet label F%d at line %d, aborted" ),
|
|
|
|
fieldref, LineCount );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ptcar++, ii = 0; ; ii++, ptcar++ )
|
|
|
|
{
|
|
|
|
Name1[ii] = *ptcar;
|
|
|
|
if( *ptcar == 0 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( " ** EESchema file sheet field F at line %d, aborted" ), LineCount );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if( *ptcar == '"' )
|
|
|
|
{
|
|
|
|
Name1[ii] = 0; ptcar++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( fieldref == 0 ) || ( fieldref == 1 ) )
|
|
|
|
{
|
|
|
|
if( sscanf( ptcar, "%d", &size ) != 1 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT(
|
|
|
|
" ** EESchema file sheet Label Caract error line %d, aborted" ), LineCount );
|
|
|
|
DisplayError( frame, MsgDiag );
|
|
|
|
}
|
|
|
|
if( size == 0 )
|
|
|
|
size = DEFAULT_SIZE_TEXT;
|
|
|
|
if( fieldref == 0 )
|
|
|
|
{
|
|
|
|
SheetStruct->m_SheetName = CONV_FROM_UTF8( Name1 );
|
|
|
|
SheetStruct->m_SheetNameSize = size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-02-28 19:27:25 +00:00
|
|
|
SheetStruct->SetFileName(CONV_FROM_UTF8( Name1 ));
|
2008-03-20 01:50:21 +00:00
|
|
|
//printf("in ReadSheetDescr : SheetStruct->m_FileName = %s \n", Name1);
|
2007-08-20 01:20:48 +00:00
|
|
|
SheetStruct->m_FileNameSize = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fieldref > 1 )
|
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
SheetLabelStruct = new Hierarchical_PIN_Sheet_Struct( SheetStruct,
|
2007-08-20 01:20:48 +00:00
|
|
|
wxPoint( 0, 0 ), CONV_FROM_UTF8( Name1 ) );
|
|
|
|
if( SheetStruct->m_Label == NULL )
|
|
|
|
OldSheetLabel = SheetStruct->m_Label = SheetLabelStruct;
|
|
|
|
else
|
|
|
|
OldSheetLabel->Pnext = (EDA_BaseStruct*) SheetLabelStruct;
|
|
|
|
OldSheetLabel = SheetLabelStruct;
|
|
|
|
|
|
|
|
/* Lecture des coordonnees */
|
|
|
|
if( sscanf( ptcar, "%s %s %d %d %d", Char1, Char2,
|
|
|
|
&SheetLabelStruct->m_Pos.x, &SheetLabelStruct->m_Pos.y,
|
|
|
|
&size ) != 5 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT(
|
|
|
|
" ** EESchema file Sheet Label Caract error line %d, aborted" ), LineCount );
|
|
|
|
DisplayError( frame, MsgDiag );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( size == 0 )
|
|
|
|
size = DEFAULT_SIZE_TEXT;
|
|
|
|
SheetLabelStruct->m_Size.x = SheetLabelStruct->m_Size.y = size;
|
|
|
|
|
|
|
|
/* Mise a jour des cadrage et type */
|
|
|
|
switch( Char1[0] )
|
|
|
|
{
|
|
|
|
case 'I':
|
|
|
|
SheetLabelStruct->m_Shape = NET_INPUT; break;
|
|
|
|
|
|
|
|
case 'O':
|
|
|
|
SheetLabelStruct->m_Shape = NET_OUTPUT; break;
|
|
|
|
|
|
|
|
case 'B':
|
|
|
|
SheetLabelStruct->m_Shape = NET_BIDI; break;
|
|
|
|
|
|
|
|
case 'T':
|
|
|
|
SheetLabelStruct->m_Shape = NET_TRISTATE; break;
|
|
|
|
|
|
|
|
case 'U':
|
|
|
|
SheetLabelStruct->m_Shape = NET_UNSPECIFIED; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Char2[0] == 'R' )
|
|
|
|
SheetLabelStruct->m_Edge = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( "$End", Line, 4 ) != 0 )
|
|
|
|
{
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( " **EESchema file end_sheet struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
|
|
|
Failed = TRUE;
|
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
if( !Failed )
|
|
|
|
{
|
|
|
|
SheetStruct->Pnext = Window->EEDrawList;
|
2008-04-14 19:22:48 +00:00
|
|
|
Window->EEDrawList = SheetStruct;
|
2008-03-20 01:50:21 +00:00
|
|
|
SheetStruct->m_Parent = Window;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
return Failed; /* Fin lecture 1 composant */
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
static int ReadSchemaDescr( wxWindow* frame, char* Line, FILE* f, BASE_SCREEN* Window )
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Analyse de l'entete du schema ( dims feuille, cartouche..)
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
char Text[256], buf[1024];
|
|
|
|
int ii;
|
|
|
|
Ki_PageDescr* wsheet = &g_Sheet_A4;
|
|
|
|
static Ki_PageDescr* SheetFormatList[] = {
|
|
|
|
&g_Sheet_A4, &g_Sheet_A3, &g_Sheet_A2, &g_Sheet_A1, &g_Sheet_A0,
|
|
|
|
&g_Sheet_A, &g_Sheet_B, &g_Sheet_C, &g_Sheet_D, &g_Sheet_E,
|
|
|
|
&g_Sheet_user, NULL
|
|
|
|
};
|
|
|
|
wxSize PageSize;
|
|
|
|
|
|
|
|
sscanf( Line, "%s %s %d %d", Text, Text, &PageSize.x, &PageSize.y );
|
|
|
|
/* Recherche de la descr correspondante: */
|
|
|
|
wxString pagename = CONV_FROM_UTF8( Text );
|
|
|
|
for( ii = 0; SheetFormatList[ii] != NULL; ii++ )
|
|
|
|
{
|
|
|
|
wsheet = SheetFormatList[ii];
|
|
|
|
if( wsheet->m_Name.CmpNoCase( pagename ) == 0 )
|
|
|
|
{ /* Descr found ! */
|
|
|
|
if( wsheet == &g_Sheet_user ) // Get the user page size and make it the default
|
|
|
|
{
|
|
|
|
g_Sheet_user.m_Size = PageSize;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( SheetFormatList[ii] == NULL )
|
|
|
|
{
|
|
|
|
/* Erreur ici: descr non trouvee */
|
|
|
|
MsgDiag.Printf(
|
|
|
|
wxT( "EESchema file Dims Caract error line %d, aborted" ), LineCount );
|
|
|
|
DisplayError( frame, MsgDiag );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ajuste ecran */
|
2008-02-12 21:12:46 +00:00
|
|
|
Window->m_CurrentSheetDesc = wsheet;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
/* Recheche suite et fin de descr */
|
|
|
|
for( ; ; )
|
|
|
|
{
|
|
|
|
if( GetLine( f, Line, &LineCount, 1024 ) == NULL )
|
|
|
|
return TRUE;
|
|
|
|
if( strnicmp( Line, "$End", 4 ) == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( strnicmp( Line, "Sheet", 2 ) == 0 )
|
|
|
|
sscanf( Line + 5, " %d %d",
|
2008-02-12 21:12:46 +00:00
|
|
|
&Window->m_ScreenNumber, &Window->m_NumberOfScreen );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( strnicmp( Line, "Title", 2 ) == 0 )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, Line, 256 );
|
|
|
|
Window->m_Title = CONV_FROM_UTF8( buf );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( Line, "Date", 2 ) == 0 )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, Line, 256 );
|
|
|
|
Window->m_Date = CONV_FROM_UTF8( buf );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( Line, "Rev", 2 ) == 0 )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, Line, 256 );
|
|
|
|
Window->m_Revision = CONV_FROM_UTF8( buf );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( Line, "Comp", 4 ) == 0 )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, Line, 256 );
|
|
|
|
Window->m_Company = CONV_FROM_UTF8( buf );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( Line, "Comment1", 8 ) == 0 )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, Line, 256 );
|
|
|
|
Window->m_Commentaire1 = CONV_FROM_UTF8( buf );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( Line, "Comment2", 8 ) == 0 )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, Line, 256 );
|
|
|
|
Window->m_Commentaire2 = CONV_FROM_UTF8( buf );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( Line, "Comment3", 8 ) == 0 )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, Line, 256 );
|
|
|
|
Window->m_Commentaire3 = CONV_FROM_UTF8( buf );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( Line, "Comment4", 8 ) == 0 )
|
|
|
|
{
|
|
|
|
ReadDelimitedText( buf, Line, 256 );
|
|
|
|
Window->m_Commentaire4 = CONV_FROM_UTF8( buf );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/***********************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
static void LoadLayers( FILE* f, int* linecnt )
|
2007-06-05 12:10:51 +00:00
|
|
|
/***********************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Load the Layer Struct from a file
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int cnt = 0, Number;
|
|
|
|
char Line[1024];
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
//int Mode,Color,Layer;
|
2007-08-20 01:20:48 +00:00
|
|
|
char Name[256];
|
|
|
|
|
|
|
|
GetLine( f, Line, NULL, sizeof(Line) ); /* read line */
|
|
|
|
(*linecnt)++;
|
|
|
|
sscanf( Line, "%s %d %d", Name, &Number, &g_LayerDescr.CurrentLayer );
|
|
|
|
if( strcmp( Name, "EELAYER" ) !=0 )
|
|
|
|
{
|
|
|
|
/* error : init par defaut */
|
|
|
|
Number = MAX_LAYER;
|
|
|
|
}
|
|
|
|
if( Number <= 0 )
|
|
|
|
Number = MAX_LAYER;
|
|
|
|
if( Number > MAX_LAYER )
|
|
|
|
Number = MAX_LAYER;
|
|
|
|
|
|
|
|
g_LayerDescr.NumberOfLayers = Number;
|
|
|
|
|
|
|
|
while( GetLine( f, Line, NULL, sizeof(Line) ) )
|
|
|
|
{
|
|
|
|
(*linecnt)++;
|
|
|
|
if( strnicmp( Line, "EELAYER END", 11 ) == 0 )
|
|
|
|
break;
|
|
|
|
cnt++;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|