2007-08-20 01:20:48 +00:00
|
|
|
/****************************************/
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Module to load/save EESchema files. */
|
2007-08-20 01:20:48 +00:00
|
|
|
/****************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-07-07 17:50:02 +00:00
|
|
|
#include "class_marker_sch.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2008-12-19 20:40:08 +00:00
|
|
|
/* in read_from_file_schematic_items_description.cpp */
|
|
|
|
SCH_ITEM* ReadTextDescr( FILE* aFile, wxString& aMsgDiag, char* aLine,
|
2009-04-05 20:49:15 +00:00
|
|
|
int aBufsize, int* aLineNum,
|
|
|
|
int aSchematicFileVersion );
|
|
|
|
|
|
|
|
extern int ReadSheetDescr( wxWindow* frame, char* Line, FILE* f,
|
|
|
|
wxString& aMsgDiag, int* aLineNum,
|
|
|
|
BASE_SCREEN* Window );
|
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
extern bool ReadSchemaDescr( wxWindow* frame, char* Line, FILE* f,
|
|
|
|
wxString& aMsgDiag, int* aLineNum,
|
|
|
|
BASE_SCREEN* Window );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
extern int ReadPartDescr( wxWindow* frame, char* Line, FILE* f,
|
|
|
|
wxString& aMsgDiag, int* aLineNum,
|
2008-12-19 20:40:08 +00:00
|
|
|
BASE_SCREEN* Window );
|
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
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/**
|
|
|
|
* Routine to load an EESchema file.
|
2008-12-19 20:40:08 +00:00
|
|
|
* Returns true if file has been loaded (at least partially.)
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen,
|
|
|
|
const wxString& FullFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
char Line[1024], * SLine;
|
|
|
|
char Name1[256],
|
|
|
|
Name2[256];
|
|
|
|
int ii, layer;
|
|
|
|
wxPoint pos;
|
|
|
|
bool Failed = FALSE;
|
|
|
|
SCH_ITEM* Phead, * Pnext;
|
|
|
|
SCH_JUNCTION* ConnectionStruct;
|
|
|
|
SCH_POLYLINE* PolylineStruct;
|
|
|
|
SCH_LINE* SegmentStruct;
|
2010-06-24 18:31:43 +00:00
|
|
|
SCH_BUS_ENTRY* busEntry;
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_NO_CONNECT* NoConnectStruct;
|
|
|
|
int LineCount;
|
2010-08-31 10:44:38 +00:00
|
|
|
wxString MsgDiag; // Error and log messages
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
FILE* f;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( screen == NULL )
|
|
|
|
return FALSE;
|
2010-08-31 10:44:38 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
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
|
|
|
|
2010-08-31 10:44:38 +00:00
|
|
|
// D(printf("LoadOneEEFile:%s\n", CONV_TO_UTF8( 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 );
|
|
|
|
|
2009-03-15 21:13:56 +00:00
|
|
|
if( fgets( Line, sizeof(Line), f ) == NULL
|
2009-04-05 20:49:15 +00:00
|
|
|
|| strncmp( Line + 9, SCHEMATIC_HEAD_STRING,
|
|
|
|
sizeof(SCHEMATIC_HEAD_STRING) - 1 ) != 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
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-10-06 05:44:29 +00:00
|
|
|
|
2010-08-31 10:44:38 +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-12-19 20:40:08 +00:00
|
|
|
int ver = version - '0';
|
2008-10-06 05:44:29 +00:00
|
|
|
if( ver > EESCHEMA_VERSION )
|
2008-04-06 15:12:24 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
MsgDiag = FullFileName + _( " was created by a more recent \
|
|
|
|
version of EESchema and may not load correctly. Please consider updating!" );
|
2009-04-17 08:51:02 +00:00
|
|
|
DisplayInfoMessage( this, MsgDiag );
|
2008-04-06 15:12:24 +00:00
|
|
|
}
|
2008-12-19 20:40:08 +00:00
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
#if 0
|
2008-12-19 20:40:08 +00:00
|
|
|
// Compile it if the new version is unreadable by previous eeschema versions
|
2008-10-06 05:44:29 +00:00
|
|
|
else if( ver < EESCHEMA_VERSION )
|
2008-04-06 15:12:24 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
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." );
|
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
DisplayInfoMessage( this, MsgDiag );
|
2008-04-06 15:12:24 +00:00
|
|
|
}
|
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++;
|
2009-03-15 21:13:56 +00:00
|
|
|
if( fgets( Line, sizeof(Line), f ) == NULL || strncmp( Line, "LIBS:", 5 ) != 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2009-03-15 21:13:56 +00:00
|
|
|
// Read the rest of a potentially very long line. fgets() puts a '\n' into
|
2009-11-04 20:46:53 +00:00
|
|
|
// the buffer if the end of line was reached. Read until end of line if
|
|
|
|
// necessary.
|
2009-03-15 21:13:56 +00:00
|
|
|
if( Line[ strlen( Line )-1 ] != '\n' )
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
while( !feof( f ) && (c = fgetc( f )) != '\n' )
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
LoadLayers( f, &LineCount );
|
|
|
|
|
|
|
|
while( !feof( f ) && GetLine( f, Line, &LineCount, sizeof(Line) ) != NULL )
|
|
|
|
{
|
|
|
|
SLine = Line;
|
|
|
|
while( (*SLine != ' ' ) && *SLine )
|
|
|
|
SLine++;
|
|
|
|
|
|
|
|
switch( Line[0] )
|
|
|
|
{
|
2010-08-31 10:44:38 +00:00
|
|
|
case '$': // identification block
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Line[1] == 'C' )
|
2010-06-24 18:31:43 +00:00
|
|
|
Failed = ReadPartDescr( this, Line, f, MsgDiag, &LineCount, screen );
|
2008-12-19 20:40:08 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
else if( Line[1] == 'S' )
|
2010-06-24 18:31:43 +00:00
|
|
|
Failed = ReadSheetDescr( this, Line, f, MsgDiag, &LineCount, screen );
|
2008-12-19 20:40:08 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
else if( Line[1] == 'D' )
|
2010-06-24 18:31:43 +00:00
|
|
|
Failed = ReadSchemaDescr( this, Line, f, MsgDiag, &LineCount, screen );
|
|
|
|
|
2010-08-31 10:44:38 +00:00
|
|
|
else if( Line[1] == 'T' ) // text part
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2010-08-31 10:44:38 +00:00
|
|
|
printf( "**** TEXT PART\n" );
|
|
|
|
SCH_ITEM* Struct;
|
|
|
|
Struct = ReadTextDescr( f, MsgDiag, Line, sizeof(Line), &LineCount, version );
|
2008-12-19 20:40:08 +00:00
|
|
|
|
2010-08-31 10:44:38 +00:00
|
|
|
if( Struct )
|
|
|
|
{
|
|
|
|
Struct->SetNext( screen->EEDrawList );
|
|
|
|
screen->EEDrawList = Struct;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Failed = true;
|
|
|
|
}
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2010-08-31 10:44:38 +00:00
|
|
|
case 'L': // Its a library item.
|
2008-12-19 20:40:08 +00:00
|
|
|
Failed = ReadPartDescr( this, Line, f, MsgDiag, &LineCount, screen );
|
2009-11-04 20:46:53 +00:00
|
|
|
break;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-08-31 10:44:38 +00:00
|
|
|
case 'W': // Its a Segment (WIRE or BUS) item.
|
2007-08-20 01:20:48 +00:00
|
|
|
if( sscanf( SLine, "%s %s", Name1, Name2 ) != 2 )
|
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
MsgDiag.Printf( wxT( "EESchema file segment error at line %d, aborted" ),
|
2009-05-21 17:42:42 +00:00
|
|
|
LineCount );
|
2008-12-19 20:40:08 +00:00
|
|
|
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
|
|
|
Failed = true;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-08-31 10:44:38 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
layer = LAYER_NOTES;
|
2010-08-31 10:44:38 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Name1[0] == 'W' )
|
|
|
|
layer = LAYER_WIRE;
|
|
|
|
if( Name1[0] == 'B' )
|
|
|
|
layer = LAYER_BUS;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SegmentStruct = new SCH_LINE( wxPoint( 0, 0 ), layer );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
LineCount++;
|
|
|
|
if( fgets( Line, 256 - 1, f ) == NULL
|
2009-04-05 20:49:15 +00:00
|
|
|
|| sscanf( Line, "%d %d %d %d ", &SegmentStruct->m_Start.x,
|
|
|
|
&SegmentStruct->m_Start.y, &SegmentStruct->m_End.x,
|
|
|
|
&SegmentStruct->m_End.y ) != 4 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
MsgDiag.Printf( wxT( "EESchema file Segment struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
2008-12-19 20:40:08 +00:00
|
|
|
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
|
|
|
Failed = true;
|
2008-10-06 05:44:29 +00:00
|
|
|
SAFE_DELETE( SegmentStruct );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !Failed )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
SegmentStruct->SetNext( screen->EEDrawList );
|
2008-12-19 20:40:08 +00:00
|
|
|
screen->EEDrawList = SegmentStruct;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-08-31 10:44:38 +00:00
|
|
|
case 'E': // Its a WIRE or BUS item.
|
2007-08-20 01:20:48 +00:00
|
|
|
if( sscanf( SLine, "%s %s", Name1, Name2 ) != 2 )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
MsgDiag.Printf( wxT( "EESchema file record struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
2008-12-19 20:40:08 +00:00
|
|
|
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
|
|
|
Failed = true;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ii = WIRE_TO_BUS;
|
|
|
|
if( Name1[0] == 'B' )
|
|
|
|
ii = BUS_TO_BUS;
|
2010-06-24 18:31:43 +00:00
|
|
|
busEntry = new SCH_BUS_ENTRY( wxPoint( 0, 0 ), '\\', ii );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
LineCount++;
|
2010-08-31 10:44:38 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( fgets( Line, 256 - 1, f ) == NULL
|
2010-06-24 18:31:43 +00:00
|
|
|
|| sscanf( Line, "%d %d %d %d ", &busEntry->m_Pos.x, &busEntry->m_Pos.y,
|
|
|
|
&busEntry->m_Size.x, &busEntry->m_Size.y ) != 4 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
MsgDiag.Printf( wxT( "EESchema file Bus Entry struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
2008-12-19 20:40:08 +00:00
|
|
|
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
|
|
|
Failed = true;
|
2010-06-24 18:31:43 +00:00
|
|
|
SAFE_DELETE( busEntry );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !Failed )
|
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
busEntry->m_Size.x -= busEntry->m_Pos.x;
|
|
|
|
busEntry->m_Size.y -= busEntry->m_Pos.y;
|
|
|
|
busEntry->SetNext( screen->EEDrawList );
|
|
|
|
screen->EEDrawList = busEntry;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-08-31 10:44:38 +00:00
|
|
|
case 'P': // Its a polyline item.
|
2007-08-20 01:20:48 +00:00
|
|
|
if( sscanf( SLine, "%s %s %d", Name1, Name2, &ii ) != 3 )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
MsgDiag.Printf( wxT( "EESchema file polyline struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
2008-12-19 20:40:08 +00:00
|
|
|
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
|
|
|
Failed = true;
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
layer = LAYER_NOTES;
|
|
|
|
if( Name2[0] == 'W' )
|
|
|
|
layer = LAYER_WIRE;
|
|
|
|
if( Name2[0] == 'B' )
|
|
|
|
layer = LAYER_BUS;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
PolylineStruct = new SCH_POLYLINE( layer );
|
2009-01-02 17:07:50 +00:00
|
|
|
for( unsigned jj = 0; jj < (unsigned)ii; jj++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
LineCount++;
|
2009-01-02 17:07:50 +00:00
|
|
|
wxPoint point;
|
2007-08-20 01:20:48 +00:00
|
|
|
if( fgets( Line, 256 - 1, f ) == NULL
|
2009-01-02 17:07:50 +00:00
|
|
|
|| sscanf( Line, "%d %d", &point.x, &point.y ) != 2 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
MsgDiag.Printf( wxT( "EESchema file polyline struct error \
|
|
|
|
at line %d, aborted" ),
|
2009-04-05 20:49:15 +00:00
|
|
|
LineCount );
|
2008-12-19 20:40:08 +00:00
|
|
|
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
|
|
|
Failed = true;
|
2008-10-06 05:44:29 +00:00
|
|
|
SAFE_DELETE( PolylineStruct );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-01-02 17:07:50 +00:00
|
|
|
|
|
|
|
PolylineStruct->AddPoint( point );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !Failed )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
PolylineStruct->SetNext( screen->EEDrawList );
|
2008-12-19 20:40:08 +00:00
|
|
|
screen->EEDrawList = PolylineStruct;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-08-31 10:44:38 +00:00
|
|
|
case 'C': // It is a connection item.
|
2009-12-02 21:44:03 +00:00
|
|
|
ConnectionStruct = new SCH_JUNCTION( wxPoint( 0, 0 ) );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( sscanf( SLine, "%s %d %d", Name1, &ConnectionStruct->m_Pos.x,
|
|
|
|
&ConnectionStruct->m_Pos.y ) != 3 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
MsgDiag.Printf( wxT( "EESchema file connection struct error \
|
2009-12-02 21:44:03 +00:00
|
|
|
at line %d, aborted" ),
|
|
|
|
LineCount );
|
2008-12-19 20:40:08 +00:00
|
|
|
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
|
|
|
Failed = true;
|
2008-10-06 05:44:29 +00:00
|
|
|
SAFE_DELETE( ConnectionStruct );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
ConnectionStruct->SetNext( screen->EEDrawList );
|
2007-08-20 01:20:48 +00:00
|
|
|
screen->EEDrawList = ConnectionStruct;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-08-31 10:44:38 +00:00
|
|
|
case 'N': // It is a NoConnect item.
|
2007-08-20 01:20:48 +00:00
|
|
|
if( sscanf( SLine, "%s %d %d", Name1, &pos.x, &pos.y ) != 3 )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
MsgDiag.Printf( wxT( "EESchema file NoConnect struct error at line %d, aborted" ),
|
|
|
|
LineCount );
|
2008-12-19 20:40:08 +00:00
|
|
|
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
|
|
|
Failed = true;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
NoConnectStruct = new SCH_NO_CONNECT( pos );
|
2008-11-24 06:53:43 +00:00
|
|
|
NoConnectStruct->SetNext( screen->EEDrawList );
|
2007-08-20 01:20:48 +00:00
|
|
|
screen->EEDrawList = NoConnectStruct;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-08-31 10:44:38 +00:00
|
|
|
case 'K': // It is a Marker item.
|
2009-11-04 20:46:53 +00:00
|
|
|
// Markers are no more read from file. they are only created on
|
|
|
|
// demand in schematic
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2010-08-31 10:44:38 +00:00
|
|
|
case 'T': // It is a text item.
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-08-31 10:44:38 +00:00
|
|
|
SCH_ITEM* Struct;
|
|
|
|
Struct = ReadTextDescr( f, MsgDiag, Line, sizeof(Line), &LineCount, version);
|
|
|
|
|
|
|
|
if( Struct )
|
|
|
|
{
|
|
|
|
Struct->SetNext( screen->EEDrawList );
|
|
|
|
screen->EEDrawList = Struct;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Failed = true;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-12-19 20:40:08 +00:00
|
|
|
Failed = true;
|
2009-05-21 17:42:42 +00:00
|
|
|
MsgDiag.Printf( wxT( "EESchema file undefined object at line %d, aborted" ),
|
|
|
|
LineCount );
|
2008-12-19 20:40:08 +00:00
|
|
|
MsgDiag << wxT( "\n" ) << CONV_FROM_UTF8( Line );
|
2007-08-20 01:20:48 +00:00
|
|
|
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();
|
2008-11-24 06:53:43 +00:00
|
|
|
Pnext->SetNext( Phead );
|
2007-08-20 01:20:48 +00:00
|
|
|
Phead = Pnext;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen->EEDrawList = Phead;
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
#if 0 && 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-10-06 05:44:29 +00:00
|
|
|
MsgDiag = _( "Done Loading " ) + screen->m_FileName;
|
2008-03-20 01:50:21 +00:00
|
|
|
PrintMsg( MsgDiag );
|
|
|
|
|
2010-08-31 10:44:38 +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 void LoadLayers( FILE* f, int* linecnt )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-03-15 21:13:56 +00:00
|
|
|
int Number;
|
2007-08-20 01:20:48 +00:00
|
|
|
char Line[1024];
|
|
|
|
|
2009-03-15 21:13:56 +00:00
|
|
|
//int Mode,Color,Layer;
|
2007-08-20 01:20:48 +00:00
|
|
|
char Name[256];
|
|
|
|
|
2009-03-15 21:13:56 +00:00
|
|
|
GetLine( f, Line, linecnt, sizeof(Line) ); /* read line */
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
sscanf( Line, "%s %d %d", Name, &Number, &g_LayerDescr.CurrentLayer );
|
|
|
|
if( strcmp( Name, "EELAYER" ) !=0 )
|
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
/* error : init par default */
|
2007-08-20 01:20:48 +00:00
|
|
|
Number = MAX_LAYER;
|
|
|
|
}
|
2009-03-15 21:13:56 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Number <= 0 )
|
|
|
|
Number = MAX_LAYER;
|
|
|
|
if( Number > MAX_LAYER )
|
|
|
|
Number = MAX_LAYER;
|
|
|
|
|
|
|
|
g_LayerDescr.NumberOfLayers = Number;
|
|
|
|
|
2009-03-15 21:13:56 +00:00
|
|
|
while( GetLine( f, Line, linecnt, sizeof(Line) ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
if( strnicmp( Line, "EELAYER END", 11 ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|