KiCad PCB EDA Suite
load_one_schematic_file.cpp File Reference

Code to load and save Eeschema files. More...

#include <fctsys.h>
#include <confirm.h>
#include <kicad_string.h>
#include <schframe.h>
#include <richio.h>
#include <project.h>
#include <general.h>
#include <sch_bus_entry.h>
#include <sch_marker.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <sch_no_connect.h>
#include <sch_component.h>
#include <sch_text.h>
#include <sch_sheet.h>
#include <sch_bitmap.h>
#include <wildcards_and_files_ext.h>

Go to the source code of this file.

Macros

#define SZ(x)   (sizeof(x)-1)
 Get the length of a string constant, at compile time. More...
 

Functions

bool ReadSchemaDescr (LINE_READER *aLine, wxString &aMsgDiag, SCH_SCREEN *Window)
 

Variables

static const char delims [] = " \t\r\n"
 

Detailed Description

Code to load and save Eeschema files.

Definition in file load_one_schematic_file.cpp.

Macro Definition Documentation

#define SZ (   x)    (sizeof(x)-1)

Get the length of a string constant, at compile time.

Definition at line 289 of file load_one_schematic_file.cpp.

Referenced by ReadSchemaDescr().

Function Documentation

bool ReadSchemaDescr ( LINE_READER aLine,
wxString &  aMsgDiag,
SCH_SCREEN Window 
)

Definition at line 294 of file load_one_schematic_file.cpp.

References PAGE_INFO::Custom, delims, FROM_UTF8(), LINE_READER::Line(), LINE_READER::LineNumber(), BASE_SCREEN::m_NumberOfScreens, BASE_SCREEN::m_ScreenNumber, ReadDelimitedText(), LINE_READER::ReadLine(), TITLE_BLOCK::SetComment1(), TITLE_BLOCK::SetComment2(), TITLE_BLOCK::SetComment3(), TITLE_BLOCK::SetComment4(), TITLE_BLOCK::SetCompany(), TITLE_BLOCK::SetDate(), PAGE_INFO::SetHeightMils(), SCH_SCREEN::SetPageSettings(), PAGE_INFO::SetPortrait(), TITLE_BLOCK::SetRevision(), TITLE_BLOCK::SetTitle(), SCH_SCREEN::SetTitleBlock(), PAGE_INFO::SetType(), PAGE_INFO::SetWidthMils(), and SZ.

Referenced by SCH_EDIT_FRAME::LoadOneEEFile().

295 {
296  char* line = aLine->Line();
297 
298  char* pageType = strtok( line + SZ( "$Descr" ), delims );
299  char* width = strtok( NULL, delims );
300  char* height = strtok( NULL, delims );
301  char* orient = strtok( NULL, delims );
302 
303  wxString pagename = FROM_UTF8( pageType );
304 
305  PAGE_INFO pageInfo;
306  TITLE_BLOCK tb;
307 
308  if( !pageInfo.SetType( pagename ) )
309  {
310  aMsgDiag.Printf( _( "Eeschema file dimension definition error line %d,"
311  "\nAbort reading file.\n" ),
312  aLine->LineNumber() );
313  aMsgDiag << FROM_UTF8( line );
314  }
315 
316  if( pagename == PAGE_INFO::Custom )
317  {
318  if( width && height )
319  {
320  int w = atoi( width );
321  int h = atoi( height );
322 
323  pageInfo.SetWidthMils( w );
324  pageInfo.SetHeightMils( h );
325  }
326  }
327 
328  // non custom size, set portrait if its present
329  else if( orient && !strcmp( orient, "portrait" ) )
330  {
331  pageInfo.SetPortrait( true );
332  }
333 
334  aScreen->SetPageSettings( pageInfo );
335 
336  for(;;)
337  {
338  char buf[1024];
339 
340  if( !aLine->ReadLine() )
341  return true;
342 
343  line = aLine->Line();
344 
345  if( strncasecmp( line, "$End", 4 ) == 0 )
346  {
347  aScreen->SetTitleBlock( tb );
348  break;
349  }
350 
351  if( strncasecmp( line, "Sheet", 2 ) == 0 )
352  sscanf( line + 5, " %d %d",
353  &aScreen->m_ScreenNumber, &aScreen->m_NumberOfScreens );
354 
355  if( strncasecmp( line, "Title", 2 ) == 0 )
356  {
357  ReadDelimitedText( buf, line, 256 );
358  tb.SetTitle( FROM_UTF8( buf ) );
359  continue;
360  }
361 
362  if( strncasecmp( line, "Date", 2 ) == 0 )
363  {
364  ReadDelimitedText( buf, line, 256 );
365  tb.SetDate( FROM_UTF8( buf ) );
366  continue;
367  }
368 
369  if( strncasecmp( line, "Rev", 2 ) == 0 )
370  {
371  ReadDelimitedText( buf, line, 256 );
372  tb.SetRevision( FROM_UTF8( buf ) );
373  continue;
374  }
375 
376  if( strncasecmp( line, "Comp", 4 ) == 0 )
377  {
378  ReadDelimitedText( buf, line, 256 );
379  tb.SetCompany( FROM_UTF8( buf ) );
380  continue;
381  }
382 
383  if( strncasecmp( line, "Comment1", 8 ) == 0 )
384  {
385  ReadDelimitedText( buf, line, 256 );
386  tb.SetComment1( FROM_UTF8( buf ) );
387  continue;
388  }
389 
390  if( strncasecmp( line, "Comment2", 8 ) == 0 )
391  {
392  ReadDelimitedText( buf, line, 256 );
393  tb.SetComment2( FROM_UTF8( buf ) );
394  continue;
395  }
396 
397  if( strncasecmp( line, "Comment3", 8 ) == 0 )
398  {
399  ReadDelimitedText( buf, line, 256 );
400  tb.SetComment3( FROM_UTF8( buf ) );
401  continue;
402  }
403 
404  if( strncasecmp( line, "Comment4", 8 ) == 0 )
405  {
406  ReadDelimitedText( buf, line, 256 );
407  tb.SetComment4( FROM_UTF8( buf ) );
408  continue;
409  }
410  }
411 
412  return true;
413 }
void SetComment1(const wxString &aComment)
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
void SetRevision(const wxString &aRevision)
void SetDate(const wxString &aDate)
Function SetDate sets the date field, and defaults to the current time and date.
static const wxChar Custom[]
"User" defined page type
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
void SetComment4(const wxString &aComment)
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define SZ(x)
Get the length of a string constant, at compile time.
void SetCompany(const wxString &aCompany)
bool SetType(const wxString &aStandardPageDescriptionName, bool IsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
void SetTitle(const wxString &aTitle)
void SetPortrait(bool isPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
void SetHeightMils(int aHeightInMils)
void SetComment2(const wxString &aComment)
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter...
void SetWidthMils(int aWidthInMils)
void SetComment3(const wxString &aComment)
int ReadDelimitedText(wxString *aDest, const char *aSource)
Function ReadDelimitedText copies bytes from aSource delimited string segment to aDest wxString...
Definition: string.cpp:43
static const char delims[]

Variable Documentation

const char delims[] = " \t\r\n"
static

Definition at line 291 of file load_one_schematic_file.cpp.

Referenced by ReadSchemaDescr().