int EQUIPOT:: ReadEquipotDescr(FILE * File, int * LineNum)
/*********************************************************/
/* Routine de lecture de 1 descr Equipotentielle.
	retourne 0 si OK
   			1 si lecture incomplete
*/
{
char Line[1024], Ltmp[1024];
int tmp;

	while( GetLine(File, Line, LineNum ) )
		{
		if( strnicmp(Line,"$End",4) == 0 )return 0;

		if( strncmp(Line,"Na", 2) == 0 )	/* Texte */
			{
			sscanf(Line+2," %d", &tmp);
			m_NetCode = tmp;

			ReadDelimitedText(Ltmp, Line + 2, sizeof(Ltmp) );
			m_Netname = CONV_FROM_UTF8(Ltmp);
			continue;
			}

		if( strncmp(Line,"Lw", 2) == 0 )	/* Texte */
			{
			sscanf(Line+2," %d", &tmp);
			m_ForceWidth = tmp;
			continue;
			}
		}
	return 1;
}
int TEXTE_PCB::ReadTextePcbDescr(FILE * File, int * LineNum)
/****************************************************************/
{
char text[1024], Line[1024];
int dummy;

	while(  GetLine(File, Line, LineNum ) != NULL )
	{
		if(strnicmp(Line,"$EndTEXTPCB",11) == 0) return 0;
		if( strncmp(Line,"Te", 2) == 0 )	/* Texte */
		{
			ReadDelimitedText(text, Line+2, sizeof(text) );
			m_Text = text;
			continue;
		}
		if( strncmp(Line,"Po", 2) == 0 )
		{
			sscanf( Line+2," %d %d %d %d %d %d",
				&m_Pos.x, &m_Pos.y, &m_Size.x, &m_Size.y,
				&m_Width, &m_Orient);
			continue;
		}
		if( strncmp(Line,"De", 2) == 0 )
		{
			sscanf( Line+2," %d %d %lX %d\n",&m_Layer, &m_Miroir,
							&m_TimeStamp, &dummy);
			if ( m_Layer < LAYER_CUIVRE_N )
				m_Layer = LAYER_CUIVRE_N;
			if ( m_Layer > LAST_NO_COPPER_LAYER )
				m_Layer = LAST_NO_COPPER_LAYER;

			continue;
		}
	}
	return(1);
}
Example #3
0
bool WinEDA_SchematicFrame::LoadOneEEFile(BASE_SCREEN *screen, const wxString & FullFileName)
/**************************************************************************************/
/* Routine to load an EESchema file.
Returns TRUE if file has been loaded (at list partially.)
*/
{
char Line[1024], * SLine;
char Name1[256],
	Name2[256];
int ii, layer, orient, size;
wxPoint pos;
bool	Failed = FALSE;
EDA_BaseStruct *Phead, *Pnext;
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->m_CurrentItem = NULL;

	LineCount = 1;
	if ((f = wxFopen(FullFileName, wxT("rt")) ) == NULL)
		{
		MsgDiag = _("Failed to open ") + FullFileName;
		DisplayError(this, MsgDiag);
		return FALSE;
		}

	MsgDiag = _("Loading ") + FullFileName;
	PrintMsg(MsgDiag);

	if (fgets(Line, 1024 - 1, f) == NULL ||
		strncmp(Line+9, SCHEMATIC_HEAD_STRING, sizeof(SCHEMATIC_HEAD_STRING) - 1)
		!= 0)
		{
		MsgDiag = FullFileName + _(" is NOT EESchema file");
		DisplayError(this, MsgDiag);
		fclose(f);
		return FALSE;
		}

	LineCount++;
	if(fgets(Line, 1024 - 1, f) == NULL || strncmp(Line, "LIBS:", 5) != 0)
		{
		MsgDiag =  FullFileName + _(" is NOT EESchema file");
		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;
					delete SegmentStruct;
					break;
					}

				if (!Failed)
					{
					SegmentStruct->Pnext = screen->EEDrawList;
					screen->EEDrawList = (EDA_BaseStruct *) SegmentStruct;
					}
				break;


			case 'E':	 /* Its a Raccord (WIRE or BUS) item. */
				if( sscanf(SLine, "%s %s", Name1, Name2) != 2  )
					{
					MsgDiag.Printf(
					wxT("EESchema file Raccord struct error at line %d, aborted"),
								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;
					delete RaccordStruct;
					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;
						delete  PolylineStruct;
						break;
					}
				}

				if (!Failed)
					{
					PolylineStruct->Pnext = screen->EEDrawList;
					screen->EEDrawList = (EDA_BaseStruct *)
										  PolylineStruct;
					}
				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;
					delete ConnectionStruct;
					}
				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. */
				{
				EDA_BaseStruct * Struct = NULL;
				*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' )
						{
						DrawLabelStruct * TextStruct =
							new DrawLabelStruct(pos, CONV_FROM_UTF8(text));
						TextStruct->m_Size.x = TextStruct->m_Size.y = size;
						TextStruct->m_Orient = orient;
						Struct = (EDA_BaseStruct*)TextStruct;
						}
					else if( Name1[0] == 'G' )
						{
						DrawGlobalLabelStruct * TextStruct =
								new DrawGlobalLabelStruct(pos, CONV_FROM_UTF8(text));
						Struct = (EDA_BaseStruct*)TextStruct;
						TextStruct->m_Size.x = TextStruct->m_Size.y = size;
						TextStruct->m_Orient = orient;
						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
						{
						DrawTextStruct * TextStruct =
							new DrawTextStruct(pos, CONV_FROM_UTF8(text));
						TextStruct->m_Size.x = TextStruct->m_Size.y = size;
						TextStruct->m_Orient = orient;
						Struct = (EDA_BaseStruct*)TextStruct;
						}
					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;
		screen->EEDrawList = screen->EEDrawList->Pnext;
		Pnext->Pnext = Phead;
		Phead = Pnext;
		}
	screen->EEDrawList = Phead;

	fclose(f);

	TestDanglingEnds(screen->EEDrawList, NULL);
		
	return TRUE;	/* Although it may be that file is only partially loaded. */
}
Example #4
0
static int ReadSchemaDescr(wxWindow * frame, char *Line, FILE *f, BASE_SCREEN * Window)
/******************************************************************/
/* Analyse de l'entete du schema ( dims feuille, cartouche..)
*/
{
char Text[256], buf[1024];
int ii;
W_PLOT * wsheet = &g_Sheet_A4;
static W_PLOT * 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 */
	Window->m_CurrentSheet = wsheet;

	/* 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",
				&Window->m_SheetNumber,&Window->m_NumberOfSheet);
 
		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);
}
Example #5
0
bool SCH_SHEET::Load( LINE_READER& aLine, wxString& aErrorMsg )
{
    int              fieldNdx, size;
    SCH_SHEET_PIN*   sheetPin;
    char*            ptcar;

    SetTimeStamp( GetNewTimeStamp() );

    // sheets are added to the GetDrawItems() like other schematic components.
    // however, in order to preserve the hierarchy (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.

    if( ((char*)aLine)[0] == '$' )   // line should be "$Sheet"
    {
        if( !aLine.ReadLine() )
        {
            aErrorMsg.Printf( wxT( "Read File Error" ) );
            return false;
        }
    }

    /* Next line: must be "S xx yy nn mm" with xx, yy = sheet position
     *  ( upper left corner  ) et nn,mm = sheet size */
    if( ( sscanf( &((char*)aLine)[1], "%d %d %d %d",
                  &m_pos.x, &m_pos.y, &m_size.x, &m_size.y ) != 4 )
        || ( ((char*)aLine)[0] != 'S' ) )
    {
        aErrorMsg.Printf( wxT( " ** Eeschema file sheet struct error at line %d, aborted\n" ),
                          aLine.LineNumber() );

        aErrorMsg << FROM_UTF8( ((char*)aLine) );
        return false;
    }

    /* Read fields */
    for( ; ; ) /* Analysis of lines "Fn" text. */
    {
        if( !aLine.ReadLine() )
            return false;

        if( ((char*)aLine)[0] == 'U' )
        {
            sscanf( ((char*)aLine) + 1, "%lX", &m_TimeStamp );
            if( m_TimeStamp == 0 )  // zero is not unique!
                SetTimeStamp( GetNewTimeStamp() );
            continue;
        }

        if( ((char*)aLine)[0] != 'F' )
            break;

        sscanf( ((char*)aLine) + 1, "%d", &fieldNdx );

        /* Read the field:
         * If fieldNdx> = 2: Fn "text" t s posx posy
         * If F0 "text" for SheetName
         * F1 and "text" for filename
         */
        ptcar = ((char*)aLine);

        while( *ptcar && ( *ptcar != '"' ) )
            ptcar++;

        if( *ptcar != '"' )
        {
            aErrorMsg.Printf( wxT( "Eeschema file sheet label F%d at line %d, aborted\n" ),
                              fieldNdx, aLine.LineNumber() );
            aErrorMsg << FROM_UTF8( (char*) aLine );
            return false;
        }

        wxString sheetName;
        ptcar += ReadDelimitedText( &sheetName, ptcar );

        if( *ptcar == 0 )
        {
            aErrorMsg.Printf( wxT( "Eeschema file sheet field F at line %d, aborted\n" ),
                              aLine.LineNumber() );
            aErrorMsg << FROM_UTF8( (char*) aLine );
            return false;
        }

        if( ( fieldNdx == 0 ) || ( fieldNdx == 1 ) )
        {
            if( sscanf( ptcar, "%d", &size ) != 1 )
            {
                aErrorMsg.Printf( wxT( "Eeschema file sheet Label error line %d, aborted\n" ),
                                  aLine.LineNumber() );

                aErrorMsg << FROM_UTF8( (char*) aLine );
            }

            if( size == 0 )
                size = DEFAULT_SIZE_TEXT;

            if( fieldNdx == 0 )
            {
                m_name     = sheetName;
                m_sheetNameSize = size;
            }
            else
            {
                SetFileName( sheetName );
                m_fileNameSize = size;
            }
        }

        if( fieldNdx > 1 )
        {
            sheetPin = new SCH_SHEET_PIN( this );

            if( !sheetPin->Load( aLine, aErrorMsg ) )
            {
                delete sheetPin;
                sheetPin = NULL;
                return false;
            }

            AddPin( sheetPin );
        }
    }

    if( strnicmp( "$End", ((char*)aLine), 4 ) != 0 )
    {
        aErrorMsg.Printf( wxT( "**Eeschema file end_sheet struct error at line %d, aborted\n" ),
                          aLine.LineNumber() );
        aErrorMsg << FROM_UTF8( ((char*)aLine) );
        return false;
    }

    return true;
}
bool LIB_FIELD::Load( LINE_READER& aLineReader, wxString& errorMsg )
{
    int     cnt;
    char    textOrient;
    char    textVisible;
    char    textHJustify;
    char    textVJustify[256];

    char*   line = (char*) aLineReader;
    char*   limit = line + aLineReader.Length();

    if( sscanf( line + 1, "%d", &m_id ) != 1 || m_id < 0 )
    {
        errorMsg = wxT( "invalid field header" );
        return false;
    }

    // Caller did a strtok(), which inserts a nul, so next few bytes are ugly:
    // digit(s), a nul, some whitespace, then a double quote.
    while( line < limit && *line != '"' )
        line++;

    if( line == limit )
        return false;

    line += ReadDelimitedText( &m_Text, line );

    // Doctor the *.lib file field which has a "~" in blank fields.  New saves will
    // not save like this, and eventually these two lines can be removed.
    if( m_Text.size()==1  &&  m_Text[0]==wxChar( '~' ) )
        m_Text.clear();

    memset( textVJustify, 0, sizeof( textVJustify ) );

    cnt = sscanf( line, " %d %d %d %c %c %c %s", &m_Pos.x, &m_Pos.y, &m_Size.y,
                  &textOrient, &textVisible, &textHJustify, textVJustify );

    if( cnt < 5 )
    {
        errorMsg.Printf( wxT( "field %d does not have the correct number of parameters" ),
                         m_id );
        return false;
    }

    m_Size.x = m_Size.y;

    if( textOrient == 'H' )
        m_Orient = TEXT_ORIENT_HORIZ;
    else if( textOrient == 'V' )
        m_Orient = TEXT_ORIENT_VERT;
    else
    {
        errorMsg.Printf( wxT( "field %d text orientation parameter <%c> is not valid" ),
                         textOrient );
        return false;
    }

    if( textVisible == 'V' )
        m_Attributs &= ~TEXT_NO_VISIBLE;
    else if ( textVisible == 'I' )
        m_Attributs |= TEXT_NO_VISIBLE;
    else
    {
        errorMsg.Printf( wxT( "field %d text visible parameter <%c> is not valid" ),
                         textVisible );
        return false;
    }

    m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
    m_VJustify = GR_TEXT_VJUSTIFY_CENTER;

    if( cnt >= 6 )
    {
        if( textHJustify == 'C' )
            m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
        else if( textHJustify == 'L' )
            m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
        else if( textHJustify == 'R' )
            m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
        else
        {
            errorMsg.Printf(
                wxT( "field %d text horizontal justification parameter <%c> is not valid" ),
                textHJustify );
            return false;
        }

        if( textVJustify[0] == 'C' )
            m_VJustify = GR_TEXT_VJUSTIFY_CENTER;
        else if( textVJustify[0] == 'B' )
            m_VJustify = GR_TEXT_VJUSTIFY_BOTTOM;
        else if( textVJustify[0] == 'T' )
            m_VJustify = GR_TEXT_VJUSTIFY_TOP;
        else
        {
            errorMsg.Printf(
                wxT( "field %d text vertical justification parameter <%c> is not valid" ),
                textVJustify[0] );
            return false;
        }

        if ( textVJustify[1] == 'I' )  // Italic
            m_Italic = true;
        if ( textVJustify[2] == 'B' )  // Bold
            m_Bold = true;
    }

    // fields in RAM must always have names.
    if( m_id < MANDATORY_FIELDS )
    {
        // Fields in RAM must always have names, because we are trying to get
        // less dependent on field ids and more dependent on names.
        // Plus assumptions are made in the field editors.
        m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
    }
    else
    {
        ReadDelimitedText( &m_name, line );
    }

    return true;
}
bool SCH_SHEET_PIN::Load( LINE_READER& aLine, wxString& aErrorMsg )
{
    int     size;
    char    number[256];
    char    name[256];
    char    connectType[256];
    char    sheetSide[256];
    char*   line = aLine.Line();
    char*   cp;

    static const char delims[] = " \t";

    // Read coordinates.
    // D( printf( "line: \"%s\"\n", line );)

    cp = strtok( line, delims );

    strncpy( number, cp, sizeof(number) );
    number[sizeof(number)-1] = 0;

    cp += strlen( number ) + 1;

    cp += ReadDelimitedText( name, cp, sizeof(name) );

    cp = strtok( cp, delims );
    strncpy( connectType, cp, sizeof(connectType) );
    connectType[sizeof(connectType)-1] = 0;

    cp = strtok( NULL, delims );
    strncpy( sheetSide, cp, sizeof(sheetSide) );
    sheetSide[sizeof(sheetSide)-1] = 0;

    cp += strlen( sheetSide ) + 1;

    int r = sscanf( cp, "%d %d %d", &m_Pos.x, &m_Pos.y, &size );
    if( r != 3 )
    {
        aErrorMsg.Printf( wxT( "Eeschema file sheet hierarchical label error at line %d.\n" ),
                          aLine.LineNumber() );

        aErrorMsg << FROM_UTF8( line );
        return false;
    }

    m_Text = FROM_UTF8( name );

    if( size == 0 )
        size = GetDefaultTextSize();

    m_Size.x = m_Size.y = size;

    switch( connectType[0] )
    {
    case 'I':
        m_shape = NET_INPUT;
        break;

    case 'O':
        m_shape = NET_OUTPUT;
        break;

    case 'B':
        m_shape = NET_BIDI;
        break;

    case 'T':
        m_shape = NET_TRISTATE;
        break;

    case 'U':
        m_shape = NET_UNSPECIFIED;
        break;
    }

    switch( sheetSide[0] )
    {
    case 'R' : /* pin on right side */
        SetEdge( 1 );
        break;

    case 'T' : /* pin on top side */
        SetEdge( 2 );
        break;

    case 'B' : /* pin on bottom side */
        SetEdge( 3 );
        break;

    case 'L' : /* pin on left side */
    default  :
        SetEdge( 0 );
        break;
    }

    return true;
}