Esempio n. 1
0
static void ReadDocLib(const wxString & ModLibName )
/***************************************************/
/* Routine de lecture du fichier Doc associe a la librairie ModLibName.
	Cree en memoire la chaine liste des docs pointee par MList
	ModLibName = full file Name de la librairie Modules
*/
{
STOREMOD * NewMod;
char Line[1024], *Name;
wxString docfilename;
FILE * LibDoc;

	docfilename = ModLibName;
	ChangeFileNameExt(docfilename, EXT_DOC);

	if( (LibDoc = fopen(docfilename.GetData(),"rt")) == NULL ) return;

	GetLine(LibDoc, Line, NULL, sizeof(Line) -1);
	if(strnicmp( Line,ENTETE_LIBDOC, L_ENTETE_LIB) != 0) return;

	/* Lecture de la librairie */
	while( GetLine(LibDoc,Line, NULL, sizeof(Line) -1) )
		{
		NewMod = NULL;
		if( Line[0] != '$' ) continue;
		if( Line[1] == 'E' ) break;;
		if( Line[1] == 'M' )	/* Debut decription 1 module */
			{
			while( GetLine(LibDoc,Line, NULL, sizeof(Line) -1) )
				{
				if( Line[0] ==  '$' )	/* $EndMODULE */
						break;
				switch( Line[0] )
					{
					case 'L':	/* LibName */
						Name = StrPurge(Line+3);
						NewMod = BaseListePkg;
						while ( NewMod )
							{
							if( strcmp(Name, NewMod->Module ) == 0 ) break;
							NewMod = NewMod->Pnext;
							}
						break;

					case 'K':	/* KeyWords */
						if( NewMod && (! NewMod->KeyWord) )
							NewMod->KeyWord = strdup(StrPurge(Line+3) );
						break;

					case 'C':	/* Doc */
						if( NewMod && (! NewMod->Doc ) )
							NewMod->Doc = strdup(StrPurge(Line+3) );
						break;
					}
				}
			} /* lecture 1 descr module */
		}	/* Fin lecture librairie */
	fclose(LibDoc);
}
Esempio n. 2
0
static void ReadDocLib(const wxString & ModLibName )
/***************************************************/
/* Routine de lecture du fichier Doc associe a la librairie ModLibName.
  	Cree en memoire la chaine liste des docs pointee par MList
	ModLibName = full file Name de la librairie Modules
*/
{
ModList * NewMod;
char Line[1024];
FILE * LibDoc;
wxString FullModLibName = ModLibName;

	ChangeFileNameExt(FullModLibName, EXT_DOC);

	if( (LibDoc = wxFopen(FullModLibName, wxT("rt"))) == NULL ) return;

	GetLine(LibDoc, Line, NULL, sizeof(Line) -1);
	if(strnicmp( Line,ENTETE_LIBDOC, L_ENTETE_LIB) != 0) return;

	/* Lecture de la librairie */
	while( GetLine(LibDoc,Line, NULL, sizeof(Line) -1) )
		{
		if( Line[0] != '$' ) continue;
		if( Line[1] == 'E' ) break;;
		if( Line[1] == 'M' )	/* Debut decription 1 module */
			{
			NewMod = new ModList();
			NewMod->Next = MList;
			MList = NewMod;
			while( GetLine(LibDoc,Line, NULL, sizeof(Line) -1) )
			{
				if( Line[0] ==  '$' )	/* $EndMODULE */
						break;
				switch( Line[0] )
				{
					case 'L':	/* LibName */
						NewMod->m_Name = CONV_FROM_UTF8(StrPurge(Line+3) );
						break;

					case 'K':	/* KeyWords */
						NewMod->m_KeyWord = CONV_FROM_UTF8(StrPurge(Line+3) );
						break;

					case 'C':	/* Doc */
						NewMod->m_Doc = CONV_FROM_UTF8(StrPurge(Line+3) );
						break;
				}
			}
		} /* lecture 1 descr module */
	}	/* Fin lecture librairie */
	fclose(LibDoc);
}
void LEGACY_NETLIST_READER::LoadNetlist() throw ( IO_ERROR, PARSE_ERROR, boost::bad_pointer )
{
    int state            = 0;
    bool is_comment      = false;
    COMPONENT* component = NULL;

    while( m_lineReader->ReadLine() )
    {
        char* line = StrPurge( m_lineReader->Line() );

        if( is_comment ) // Comments in progress
        {
            // Test for end of the current comment
            if( ( line = strchr( line, '}' ) ) == NULL )
                continue;

            is_comment = false;
        }

        if( *line == '{' ) // Start Comment or Pcbnew info section
        {
            is_comment = true;

            if( m_loadFootprintFilters && state == 0
              && (strnicmp( line, "{ Allowed footprints", 20 ) == 0) )
            {
                loadFootprintFilters();
                continue;
            }

            if( ( line = strchr( line, '}' ) ) == NULL )
                continue;
        }

        if( *line == '(' )
            state++;

        if( *line == ')' )
            state--;

        if( state == 2 )
        {
            component = loadComponent( line );
            continue;
        }

        if( state >= 3 ) // Pad descriptions are read here.
        {
            wxASSERT( component != NULL );

            loadNet( line, component );
            state--;
        }
    }

    if( m_footprintReader )
    {
        m_footprintReader->Load( m_netlist );
    }
}
/**
 * Read a file to detect the type.
 * @param aFile - open file to be read. File pointer will be closed.
 * @param aFileName - file name to be read
 * @param aName - wxString to receive the module name iff type is LEGACY
 */
static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName,
                                            wxString* aName )
{
    FILE_LINE_READER freader( aFile, aFileName.GetFullPath() );
    WHITESPACE_FILTER_READER reader( freader );
    IO_MGR::PCB_FILE_T file_type;

    wxASSERT( aName );

    reader.ReadLine();
    char* line = reader.Line();

    if( !strncasecmp( line, "(module", strlen( "(module" ) ) )
    {
        file_type = IO_MGR::KICAD_SEXP;
        *aName = aFileName.GetName();
    }
    else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
    {
        file_type = IO_MGR::LEGACY;

        while( reader.ReadLine() )
        {
            if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) )
            {
                *aName = FROM_UTF8( StrPurge( line + strlen( "$MODULE" ) ) );
                break;
            }
        }
    }
    else if( !strncasecmp( line, "Element", strlen( "Element" ) ) )
    {
        file_type = IO_MGR::GEDA_PCB;
        *aName = aFileName.GetName();
    }
    else
    {
        file_type = IO_MGR::FILE_TYPE_NONE;
    }

    return file_type;
}
bool EXCELLON_IMAGE::LoadFile( const wxString & aFullFileName )
{
    // Set the default parmeter values:
    ResetDefaultValues();
    ClearMessageList();

    m_Current_File = wxFopen( aFullFileName, wxT( "rt" ) );

    if( m_Current_File == NULL )
        return false;

    m_FileName = aFullFileName;

    LOCALE_IO toggleIo;

    // FILE_LINE_READER will close the file.
    FILE_LINE_READER excellonReader( m_Current_File, m_FileName );

    while( true )
    {
        if( excellonReader.ReadLine() == 0 )
            break;

        char* line = excellonReader.Line();
        char* text = StrPurge( line );

        if( *text == ';' )       // comment: skip line
            continue;

        if( m_State == EXCELLON_IMAGE::READ_HEADER_STATE )
        {
            Execute_HEADER_Command( text );
        }
        else
        {
            switch( *text )
            {
            case 'M':
                Execute_HEADER_Command( text );
                break;

            case 'G': /* Line type Gxx : command */
                Execute_EXCELLON_G_Command( text );
                break;

            case 'X':
            case 'Y':               // command like X12550Y19250
                Execute_Drill_Command(text);
                break;

            case 'I':
            case 'J':               /* Auxiliary Move command */
                m_IJPos = ReadIJCoord( text );
                if( *text == '*' )  // command like X35142Y15945J504
                {
                    Execute_Drill_Command( text);
                }
                break;

            case 'T': // Tool command
                Select_Tool( text );
                break;

            case '%':
                break;

            default:
            {
                wxString msg;
                msg.Printf( wxT( "Unexpected symbol <%c>" ), *text );
                AddMessageToList( msg );
            }
                break;
            }   // End switch
        }
    }

    // Add our file attribute, to identify the drill file
    X2_ATTRIBUTE dummy;
    char* text = (char*)file_attribute;
    dummy.ParseAttribCmd( m_Current_File, NULL, 0, text );
    delete m_FileFunction;
    m_FileFunction = new X2_ATTRIBUTE_FILEFUNCTION( dummy );

    m_InUse = true;

    return true;
}
Esempio n. 6
0
int WinEDA_CvpcbFrame::ReadViewlogicNetList(void)
{
int ii, LineNum;
char Line[1024], *Text;
wxString PkgFileName;
char PinName[256], NetName[256], RefName[256], *Data;
STORECMP * Cmp;
wxString msg;

	modified = 0;
	Rjustify = 1;

	/* Raz buffer et variable de gestion */
	if( BaseListeCmp ) FreeMemoryComponants();

	Cmp = NULL; LineNum = 0;
	memset(Line, 0, sizeof(Line) );

	/* Tst de la presence du fichier principal Netliste, et son format:
		Si format = PCBNEW, appel de rdorcad
	*/
	source = wxFopen(FFileName, wxT("rt") );
	if (source == 0)
		 {
		 msg = _("File not found ") + FFileName;
		 DisplayError(this, msg); return(-1);
		 }

	if ( fgets(Line, sizeof(Line)-1, source) == 0 )
		{	/* fichier vide */
		fclose(source);	return(-1);
		}

	fclose(source);
	Text = StrPurge(Line);

	ii = strnicmp(Line,"( { ",4) ;	 /* net type PCB2 */
	if( ii != 0 ) ii =  strnicmp(Line,"# EESchema",4) ;	  /* net type EESchema */
	if( ii == 0 )
		{
		ii = rdorcad(); return(ii);
		}


	/* Traitement reel de la netliste Viewlogic ( .net et .pkg ) */
	SetStatusText( _("Format Netlist: ViewLogic net&pkg"), 0);

	/* Calcul du nom (full file name) du fichier .pkg */
	PkgFileName = FFileName;
	ChangeFileNameExt(PkgFileName, PkgInExtBuffer);

	/* Ouverture du fichier .pkg */
	source = wxFopen(PkgFileName, wxT("rt"));
	if (source == 0)
	{
		msg = _("File not found ") + PkgFileName;
		DisplayError(this, msg);
		return(-1);
	}

	nbcomp = GenListeComposants(source);
	fclose(source);

	/* reclassement alpab‚tique : */
	BaseListeCmp = TriListeComposantss( BaseListeCmp, nbcomp);

	/* Ouverture du fichier netliste */
	source = wxFopen(FFileName, wxT("rt"));
	if (source == 0)
	{
		msg = _("File not found ") + FFileName;
		DisplayError(this, msg);
		return(-1);
	}

	/* Lecture de la liste ( fichier netliste ) */
	LineNum = 0;
	for ( ;; )
		{
		LineNum++;
		if ( fgets(Line, sizeof(Line)-1, source) == 0 )  break ;
		Text = StrPurge(Line);
		if (*Text < ' ' ) continue; /* Ligne vide */

		/* Lecture du NetName */
		for( ii = 0; ii < 80; ii++, Text++)
			{
			if( *Text == 0 ) break;
			if( *Text == ';' ) break;
			NetName[ii] = *Text;
			}
		NetName[ii] = 0; if ( *Text == ';' ) Text++;
		if( NetName[0] == 0 )
			{
			msg.Printf( wxT("Err. Pin Name ligne %s"),Line);
			DisplayError(this, msg, 20);
			}

		/* Lecture des attributions de pins */
		while( *Text != 0 )
			{
			Data = RefName; RefName[0] = PinName[0] = 0;
			for( ii = 0; ii < 1000; ii++, Text++ )
				{
				if( *Text == 0 ) break;
				if( *Text == ',' ) break;
				if( *Text == '^' )
					{
					*Data = 0; Data = PinName; continue;
					}
				*Data = *Text; Data++;
				}
			*Data = 0;
			if( (PinName[0] == 0 ) || (PinName[0] == 0 ) )
				{
				msg.Printf( wxT("Err. Pin Name ligne %s"),Line);
				DisplayError(this, msg, 20); break;
				}
			GenPin( BaseListeCmp, RefName, PinName, NetName);
			if ( *Text == ',' ) /* Autre element a traiter, ou nouvelle */
								/* ligne a lire ( continuation de ligne ) */
				{
				Text++; Text = StrPurge(Text);
				if( *Text == 0 )	/* Nouvelle ligne a lire */
					{
					LineNum++;
					if ( fgets(Line, sizeof(Line)-1, source) == 0 )  break ;
					Text = StrPurge(Line);
					}
				}
			}
		}

	fclose(source);

	return(0);
}
Esempio n. 7
0
static int GenListeComposants(FILE * PkgFile)
/******************************************/
/* Cree la liste des composants cites dans le fichier .pkg
	Retourne le nombre de composants
*/
{
int ii, LineNum, NbComp;
char Line[1024], *Text;
char Valeur[256], Package[256], Name[256];
STORECMP * Cmp;

	LineNum = 0; NbComp = 0;

	/* Lecture de la liste ( fichier .pkg ) */
	for ( ;; )
		{
		LineNum++;
		if ( fgets(Line, sizeof(Line)-1, PkgFile) == 0 )  break ;
		Text = StrPurge(Line);
		if (*Text < ' ' ) continue; /* Ligne vide */

		/* Lecture de la Valeur */
		for( ii = 0; ii < 80; ii++, Text++)
			{
			if( *Text == 0 ) break;
			if( *Text == ';' ) break;
			Valeur[ii] = *Text;
			}
		Valeur[ii] = 0; if ( *Text == ';' ) Text++;

		/* Lecture du type du boitier */
		for( ii = 0; ii < 80; ii++, Text++)
			{
			if( *Text == 0 ) break;
			if( *Text == ';' ) break;
			Package[ii] = *Text;
			}
		Package[ii] = 0; if ( *Text == ';' ) Text++;

		/* Lecture des composants */
		while( *Text )
			{
			/* Lecture du nom du composant */
			for( ii = 0; ii < 80; ii++, Text++)
			{
				if( *Text <= ' ' ) break;
				if( *Text == ',' ) break;
				Name[ii] = *Text;
			}
			Name[ii] = 0;
			Cmp = new STORECMP();
			Cmp->Pnext = BaseListeCmp;
			BaseListeCmp = Cmp;
			NbComp++ ;
			Cmp->m_Reference = CONV_FROM_UTF8( StrPurge(Name) );
			Cmp->m_Valeur = CONV_FROM_UTF8( StrPurge(Valeur) );
			Cmp->m_Module = CONV_FROM_UTF8( StrPurge(Package) );
			Cmp->m_TimeStamp = wxT("00000000");

			if ( *Text == ',' ) /* Autre element a traiter, ou nouvelle */
								/* ligne a lire ( continuation de ligne ) */
				{
				Text++; Text = StrPurge(Text);
				if( *Text == 0 )	/* Nouvelle ligne a lire */
					{
					LineNum++;
					if ( fgets(Line, sizeof(Line)-1, PkgFile) == 0 )  break ;
					Text = StrPurge(Line);
					}
				}
			}
		}
	return(NbComp);
}
Esempio n. 8
0
wxString WinEDA_BasePcbFrame::Select_1_Module_From_List(
				wxWindow * active_window,
				const wxString & Library,
				const wxString & Mask, const wxString & KeyWord)
/***************************************************************/
/*
 Affiche la liste des modules des librairies
	Recherche dans la librairie Library ou generale si Library == NULL
	Mask = Filtre d'affichage( Mask = wxEmptyString pour listage non filtré )
	KeyWord = Liste de mots cles, Recherche limitee aux composants
		ayant ces mots cles ( KeyWord = wxEmptyString pour listage de tous les modules )

	retourne wxEmptyString si abort ou probleme
	ou le nom du module
*/
{
int LineNum;
unsigned ii, NbModules;
char Line[1024];
wxString FullLibName;
static wxString OldName;	/* Memorise le nom du dernier composant charge */
wxString CmpName;
FILE * lib_module;
wxString msg;
	
WinEDAListBox * ListBox = new WinEDAListBox(active_window, wxEmptyString,
			NULL, OldName, DisplayCmpDoc, wxColour(200, 200, 255) );

	wxBeginBusyCursor();

	/* Recherche des composants en librairies */
	NbModules = 0;
	for( ii = 0; ii < g_LibName_List.GetCount(); ii++)
	{
		/* Calcul du nom complet de la librairie */
		if( Library.IsEmpty() )
		{
			FullLibName = MakeFileName(g_RealLibDirBuffer,
						g_LibName_List[ii], LibExtBuffer);
		}
		else
			FullLibName = MakeFileName(g_RealLibDirBuffer,Library,LibExtBuffer);

		ReadDocLib(FullLibName );

		if( ! KeyWord.IsEmpty())	/* Inutile de lire la librairie si selection
						par mots cles, deja lus */
		{
			if( ! Library.IsEmpty() ) break;
			continue ;
		}

		if ((lib_module = wxFopen(FullLibName, wxT("rt")))  == NULL )
		{
			if( ! Library.IsEmpty() ) break;
			continue ;
		}

		msg = _("Library: "); msg << FullLibName;
		Affiche_Message(msg);

		/* lecture entete */
		LineNum = 0;
		GetLine(lib_module, Line, &LineNum, sizeof(Line) -1);

		if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0)
		{
			DisplayError(this, wxT("This file is not an Eeschema libray file"), 20); continue;
		}

		/* Lecture de la librairie */
		while( GetLine(lib_module,Line, &LineNum, sizeof(Line) -1) )
		{
			if( Line[0] != '$' ) continue;
			if( strnicmp( Line, "$MODULE",6) == 0 ) break;
			if( strnicmp( Line,"$INDEX",6) == 0 )
			{
				while( GetLine(lib_module,Line, &LineNum) )
				{
					if( strnicmp( Line,"$EndINDEX",9) == 0 ) break;
                    strupper(Line);
					msg = CONV_FROM_UTF8(StrPurge(Line));
					if ( Mask.IsEmpty() )
					{
						ListBox->Append( msg );
						NbModules++;
					}
					else if ( WildCompareString(Mask, msg, FALSE) )
					{
						ListBox->Append( msg );
						NbModules++;
					}
				}
			} /* Fin Lecture INDEX */
		}  /* Fin lecture 1 Librairie */

		fclose(lib_module) ; lib_module = NULL;
		if( ! Library.IsEmpty() ) break;
	}

	/*  creation de la liste des modules si recherche par mots-cles */
	if( ! KeyWord.IsEmpty() )
	{
		ModList * ItemMod = MList;
		while( ItemMod != NULL )
		{
			if( KeyWordOk(KeyWord, ItemMod->m_KeyWord) )
			{
				NbModules++;
				ListBox->Append( ItemMod->m_Name );
			}
			ItemMod = ItemMod->Next;
		}
	}

	wxEndBusyCursor();

	msg.Printf( _("Modules (%d items)"), NbModules);
	ListBox->SetTitle(msg);
	ListBox->SortList();
	
	ii = ListBox->ShowModal();
	if ( ii >= 0 ) CmpName = ListBox->GetTextSelection();
	else CmpName.Empty();

	ListBox->Destroy();

	/* liberation mem de la liste des textes doc module */
	while( MList != NULL )
	{
		ModList * NewMod = MList->Next;
		delete MList;
		MList = NewMod;
	}

	if( CmpName != wxEmptyString ) OldName = CmpName;

	return(CmpName);
}
Esempio n. 9
0
MODULE* FOOTPRINT_EDIT_FRAME::Import_Module()
{
    // use the clipboard for this in the future?

    // Some day it might be useful save the last library type selected along with the path.
    static int lastFilterIndex = 0;

    wxString        lastOpenedPathForLoading = m_mruPath;
    wxConfigBase*   config = Kiface().KifaceSettings();

    if( config )
        config->Read( EXPORT_IMPORT_LASTPATH_KEY, &lastOpenedPathForLoading );

    wxString wildCard;

    wildCard << wxGetTranslation( KiCadFootprintLibFileWildcard ) << wxChar( '|' )
             << wxGetTranslation( ModLegacyExportFileWildcard ) << wxChar( '|' )
             << wxGetTranslation( ModImportFileWildcard ) << wxChar( '|' )
             << wxGetTranslation( GedaPcbFootprintLibFileWildcard );

    wxFileDialog dlg( this, FMT_IMPORT_MODULE,
                      lastOpenedPathForLoading, wxEmptyString,
                      wildCard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
    dlg.SetFilterIndex( lastFilterIndex );

    if( dlg.ShowModal() == wxID_CANCEL )
        return NULL;

    lastFilterIndex = dlg.GetFilterIndex();

    FILE* fp = wxFopen( dlg.GetPath(), wxT( "rt" ) );

    if( !fp )
    {
        wxString msg = wxString::Format( FMT_FILE_NOT_FOUND, GetChars( dlg.GetPath() ) );
        DisplayError( this, msg );
        return NULL;
    }

    if( config )    // Save file path
    {
        lastOpenedPathForLoading = wxPathOnly( dlg.GetPath() );
        config->Write( EXPORT_IMPORT_LASTPATH_KEY, lastOpenedPathForLoading );
    }

    wxString    moduleName;

    bool        isGeda   = false;
    bool        isLegacy = false;

    {
        FILE_LINE_READER         freader( fp, dlg.GetPath() );   // I own fp, and will close it.
        WHITESPACE_FILTER_READER reader( freader );              // skip blank lines

        reader.ReadLine();
        char* line = reader.Line();

        if( !strnicmp( line, "(module", 7 ) )
        {
            // isKicad = true;
        }
        else if( !strnicmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
        {
            isLegacy = true;

            while( reader.ReadLine() )
            {
                if( !strnicmp( line, "$MODULE", 7 ) )
                {
                    moduleName = FROM_UTF8( StrPurge( line + sizeof( "$MODULE" ) -1 ) );
                    break;
                }
            }
        }
        else if( !strnicmp( line, "Element", 7 ) )
        {
            isGeda = true;
        }
        else
        {
            DisplayError( this, FMT_NOT_MODULE );
            return NULL;
        }

        // fp is closed here by ~FILE_LINE_READER()
    }

    MODULE*   module;

    if( isGeda )
    {
        try
        {
            wxFileName fn = dlg.GetPath();
            PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::GEDA_PCB ) );

            moduleName = fn.GetName();
            module = pi->FootprintLoad( fn.GetPath(), moduleName );

            if( !module )
            {
                wxString msg = wxString::Format(
                    FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( fn.GetPath() ) );

                DisplayError( this, msg );
                return NULL;
            }
        }
        catch( const IO_ERROR& ioe )
        {
            DisplayError( this, ioe.errorText );
            return NULL;
        }
    }
    else if( isLegacy )
    {
        try
        {
            PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );

            module = pi->FootprintLoad( dlg.GetPath(), moduleName );

            if( !module )
            {
                wxString msg = wxString::Format(
                    FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( dlg.GetPath() ) );

                DisplayError( this, msg );
                return NULL;
            }
        }
        catch( const IO_ERROR& ioe )
        {
            DisplayError( this, ioe.errorText );
            return NULL;
        }
    }
    else    //  if( isKicad )
    {
        try
        {
            // This technique was chosen to create an example of how reading
            // the s-expression format from clipboard could be done.

            wxString    fcontents;
            PCB_IO      pcb_io;
            wxFFile     f( dlg.GetPath() );

            if( !f.IsOpened() )
            {
                wxString msg = wxString::Format( FMT_BAD_PATH, GetChars( dlg.GetPath() ) );

                DisplayError( this, msg );
                return NULL;
            }

            f.ReadAll( &fcontents );

            module = dyn_cast<MODULE*>( pcb_io.Parse( fcontents ) );

            if( !module )
            {
                wxString msg = wxString::Format( FMT_BAD_PATH, GetChars( dlg.GetPath() ) );

                DisplayError( this, msg );
                return NULL;
            }
        }
        catch( const IO_ERROR& ioe )
        {
            DisplayError( this, ioe.errorText );
            return NULL;
        }
    }

    // Insert footprint in list
    GetBoard()->Add( module );

    // Display info :
    SetMsgPanel( module );
    PlaceModule( module, NULL );

    if( IsGalCanvasActive() )
        module->SetPosition( wxPoint( 0, 0 ) );

    GetBoard()->m_Status_Pcb = 0;
    GetBoard()->BuildListOfNets();
    updateView();

    return module;
}
Esempio n. 10
0
/*
 * Function ReadOldFmtdNetList
 * Update footprints (load missing footprints and delete on request extra
 * footprints)
 * Update References, values, "TIME STAMP" and connectivity data
 * return true if Ok
 *
 *  the format of the netlist is something like:
 * # EESchema Netlist Version 1.0 generee le  18/5/2005-12:30:22
 *  (
 *  ( 40C08647 $noname R20 4,7K {Lib=R}
 *  (    1 VCC )
 *  (    2 MODB_1 )
 *  )
 *  ( 40C0863F $noname R18 4,7_k {Lib=R}
 *  (    1 VCC )
 *  (    2 MODA_1 )
 *  )
 *  }
 * #End
 */
bool NETLIST_READER::ReadOldFmtdNetList( FILE* aFile )
{
    int  state = 0;
    bool is_comment = false;

    /* First, read the netlist: Build the list of footprints found in netlist
     */

    // netlineReader dtor will close aFile
    FILE_LINE_READER netlineReader( aFile, m_netlistFullName );

    COMPONENT_INFO *curComponent = NULL;
    while( netlineReader.ReadLine() )
    {
        char* line = StrPurge( netlineReader.Line() );

        if( is_comment ) // Comments in progress
        {
            // Test for end of the current comment
            if( ( line = strchr( line, '}' ) ) == NULL )
                continue;

            is_comment = false;
        }
        if( *line == '{' ) // Start Comment or Pcbnew info section
        {
            is_comment = true;
            if( ReadLibpartSectionOpt() && state == 0 &&
                (strnicmp( line, "{ Allowed footprints", 20 ) == 0) )
            {
                ReadOldFmtFootprintFilterList( netlineReader );
                continue;
            }
            if( ( line = strchr( line, '}' ) ) == NULL )
                continue;
        }

        if( *line == '(' )
            state++;

        if( *line == ')' )
            state--;

        if( state == 2 )
        {
            curComponent = (COMPONENT_INFO*) ReadOldFmtNetlistModuleDescr( line, BUILDLIST );
            continue;
        }

        if( state >= 3 ) // First pass: pad descriptions are not read here.
        {
            if( curComponent )
                curComponent->m_pinCount++;

            state--;
        }
    }

    if( IsCvPcbMode() )
    {
        for( ; ; )
        {
            /* Search the beginning of Allowed footprints section */

            if( netlineReader.ReadLine( ) == 0 )
                break;
            char* line = StrPurge( netlineReader.Line() );
            if( strnicmp( line, "{ Allowed footprints", 20 ) == 0 )
            {
                ReadOldFmtFootprintFilterList( netlineReader );
                return true;
            }
        }
        return true;
    }

    if( BuildModuleListOnlyOpt() )
        return true;  // at this point, the module list is read and built.

    // Load new footprints
    bool success = InitializeModules();

    if( !success )
        wxMessageBox( _( "Some footprints are not found in libraries" ) );

    TestFootprintsMatchingAndExchange();

    /* Second read , All footprints are on board.
     * Update the schematic info (pad netnames)
     */
    netlineReader.Rewind();
    m_currModule = NULL;
    state = 0;
    is_comment = false;

    while( netlineReader.ReadLine() )
    {
        char* line = StrPurge( netlineReader.Line() );

        if( is_comment )   // we are reading a comment
        {
            // Test for end of the current comment
            if( ( line = strchr( line, '}' ) ) == NULL )
                continue;
            is_comment = false;
        }

        if( *line == '{' ) // this is the beginning of a comment
        {
            is_comment = true;

            if( ( line = strchr( line, '}' ) ) == NULL )
                continue;
        }

        if( *line == '(' )
            state++;

        if( *line == ')' )
            state--;

        if( state == 2 )
        {
            m_currModule = (MODULE*) ReadOldFmtNetlistModuleDescr( line, READMODULE );
            continue;
        }

        if( state >= 3 )
        {
            if( m_currModule )
                SetPadNetName( line );
            state--;
        }
    }

    return true;
}
Esempio n. 11
0
static bool CreateDocLibrary(const wxString & LibName)
/*****************************************************/
/* Creation du fichier .dcm associe a la librairie LibName
	(full file name)
*/
{
char Line[1024];
wxString Name, Doc, KeyWord;
wxString LibDocName;
FILE * LibMod, *LibDoc;

	LibDocName = LibName;
	ChangeFileNameExt(LibDocName, EXT_DOC);

	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;
	}

	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));

				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( (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));

				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 */

	fclose( LibMod );
	fprintf( LibDoc,"#\n$EndLIBDOC\n");
	fclose( LibDoc );
	return TRUE;
}
Esempio n. 12
0
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
*/
{
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);

	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;

	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;
	}

	/* 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;

		 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);

	/* Creation de la nouvelle librairie */

	if ((lib_module = wxFopen(LibName, wxT("rt")))  == NULL )
	{
		DisplayError(this, wxT("Librairi.cpp: Error oldlib not found"));
		return(0);
	}

	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() ;

	/* Creation de l'entete avec nouvelle date */
	fprintf(dest,ENTETE_LIBRAIRIE);
	fprintf(dest,"  %s\n$INDEX\n", DateAndTime(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;
	}

	fprintf(dest,"$EndINDEX\n");

	/* 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);
		}

	/* 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;

	fclose(dest) ;	fclose(lib_module) ;

wxEndBusyCursor() ;

	/* L'ancien fichier librairie est renomme en .bak */
	OldLib = LibName;
	ChangeFileNameExt ( OldLib, OLD_EXT);

	if( wxFileExists(OldLib) ) wxRemoveFile(OldLib);

	if ( ! wxRenameFile(LibName, OldLib ) )
		DisplayError(this, wxT("Librairi.cpp: rename .bak err") );

	/* 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);
}
Esempio n. 13
0
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;

	/* 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;

	OldLib = libname;

	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) ;

	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;
	}

	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;
		}

wxBeginBusyCursor();

	/* 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;
	}

	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);
	}

	fclose(lib_module);
	fclose(dest) ;

wxEndBusyCursor();

	/* Le fichier ancienne librairie est renommee en .bak */
wxString BakFilename = OldLib;
	ChangeFileNameExt( BakFilename, OLD_EXT);

	if( wxFileExists(BakFilename) ) wxRemoveFile(BakFilename);

	if( ! wxRenameFile(OldLib, BakFilename) )
	{
		DisplayError(this, wxT("Librairi.cpp: rename .bak err"));
		return;
	}

	/* Le fichier temporaire est renommee comme l'ancienne Lib */
	if( ! wxRenameFile(NewLib,OldLib) )
	{
		DisplayError(this, wxT("Librairi.cpp: rename err 2") );
		return;
	}

	msg.Printf( _("Component %s deleted in library %s"), CmpName.GetData(), OldLib.GetData() ) ;
	Affiche_Message(msg) ;

	CreateDocLibrary(OldLib);
}
Esempio n. 14
0
int listlib(void)
/*********************/
/* Routine lisant la liste des librairies, et generant la liste chainee
 des modules disponibles
*/
{
char buffer[1024];
wxString FullLibName;
int errorlevel = 0, end;
int flag_librairie;
STOREMOD * ItemLib;
unsigned ii;
	
	if( BaseListePkg )	/* Liste Deja existante, a supprimer */
		{
		FreeMemoryModules(); BaseListePkg = NULL;
		}

	if ( g_LibName_List.GetCount() == 0 ) return -4;

	/* init recherche */
	SetRealLibraryPath("modules");
	nblib = 0;

	/* Lecture des Librairies */
	for( ii= 0 ; ii < g_LibName_List.GetCount(); ii++)
	{
		/* Calcul du nom complet de la librairie */
		FullLibName = MakeFileName(g_RealLibDirBuffer, g_LibName_List[ii], LibExtBuffer);
		/* acces a une librairie */
		if ((name_libmodules = fopen(FullLibName.GetData(),"rt"))  == NULL )
		{
			sprintf(cbuf,_("Library file <%s> not found"),FullLibName.GetData());
			DisplayError(NULL, cbuf, 20);
			continue;
		}

		/* Controle du type de la librairie : */
		flag_librairie = 0;
		fgets(buffer,32,name_libmodules) ;
		if( strncmp(buffer,ENTETE_LIBRAIRIE,L_ENTETE_LIB) != 0 )
			{
			sprintf(cbuf,_("Library file <%s> is not a module library"),
					FullLibName.GetData());
			DisplayError(NULL, cbuf, 20);
			fclose(name_libmodules); continue;
			}

		/* Lecture du nombre de composants */
		fseek(name_libmodules,0,0) ;

		 /* lecture nom des composants : */
		end = 0;
		while( !end && fgets(buffer,255,name_libmodules) != NULL )
			{
			if(strnicmp(buffer,"$INDEX",6) == 0 )
				{
				while( fgets(buffer,255,name_libmodules) != NULL )
					{
					if(strnicmp(buffer,"$EndINDEX",6) == 0 )
						{ end = 1; break; }
				
					ItemLib = (STOREMOD * ) MyZMalloc( sizeof(STOREMOD) );
					ItemLib->Pnext = BaseListePkg;
					BaseListePkg = ItemLib;
					ItemLib->Type = STRUCT_MODULE ;

					strncpy(ItemLib->Module,StrPurge(buffer),
											sizeof(ItemLib->Module)-1);
					strncpy(ItemLib->LibName,FullLibName.GetData(),
											sizeof(ItemLib->LibName)-1);

					nblib++;
					}
				if( !end ) errorlevel = -3;
				}
			}
		fclose(name_libmodules);
		ReadDocLib(FullLibName );
	}

	/* classement alphabetique: */
	if( BaseListePkg )
		BaseListePkg = TriListeModules(BaseListePkg, nblib);

	return(errorlevel) ;
}
Esempio n. 15
0
MODULE * WinEDA_BasePcbFrame::Get_Librairie_Module(wxWindow * winaff,
		const wxString & library, const wxString & ModuleName, bool show_msg_err)
/*******************************************************************************/
/*
	Analyse les LIBRAIRIES pour trouver le module demande
	Si ce module est trouve, le copie en memoire, et le
	chaine en fin de liste des modules
		- Entree:
			name_cmp = nom du module
		- Retour:
			Pointeur sur le nouveau module.
*/
{
int LineNum, Found= 0;
wxString fulllibname;
char Line[512];
wxString Name;
wxString ComponentName, msg;
MODULE * Module;
MODULE * NewModule;
FILE * lib_module = NULL;
unsigned ii;

	ComponentName = ModuleName;

	/* Calcul de l'adresse du dernier module: */
	Module = m_Pcb->m_Modules;
	if( Module ) while( Module->Pnext ) Module = (MODULE*) Module->Pnext;

	for( ii = 0; ii < g_LibName_List.GetCount(); ii++)
	{
		fulllibname = g_LibName_List[ii];

		/* Calcul du nom complet de la librairie */
		fulllibname = MakeFileName(g_RealLibDirBuffer,fulllibname,LibExtBuffer);

		if ((lib_module = wxFopen(fulllibname, wxT("rt")))  == NULL )
		{
			msg.Printf(_("Library <%s> not found"),fulllibname.GetData());
			Affiche_Message(msg);
			continue ;
		}

		msg.Printf(_("Scan Lib: %s"),fulllibname.GetData());
		Affiche_Message(msg);

		/* lecture entete chaine definie par ENTETE_LIBRAIRIE */
		LineNum = 0;
		GetLine(lib_module, Line, &LineNum) ;
		StrPurge(Line);
		if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0)
		{
			DisplayError(winaff, _("File is Not a library") );
			return(NULL);
		}

		/* Lecture de la liste des composants de la librairie */
		Found = 0;
		while( !Found && GetLine(lib_module,Line, &LineNum) )
		{
			if( strnicmp( Line, "$MODULE",6) == 0 ) break;
			if( strnicmp( Line,"$INDEX",6) == 0 )
			{
				while( GetLine(lib_module,Line, &LineNum) )
				{
					if( strnicmp( Line,"$EndINDEX",9) == 0 ) break;
					StrPurge(Line);
					msg = CONV_FROM_UTF8(Line);
					if( msg.CmpNoCase(ComponentName) == 0 )
					{
						Found = 1; break; /* Trouve! */
					}
				}
			}
		}

		/* Lecture de la librairie */
		while( Found && GetLine(lib_module,Line, &LineNum) )
		{
			if( Line[0] != '$' ) continue;
			if( Line[1] != 'M' ) continue;
			if( strnicmp( Line, "$MODULE",7) != 0 ) continue;
			/* Lecture du nom du composant */
			Name = CONV_FROM_UTF8(Line+8);
			if( Name.CmpNoCase(ComponentName) == 0 )  /* composant localise */
			{
				NewModule = new MODULE(m_Pcb);
				NewModule->ReadDescr(lib_module, &LineNum);
				if( Module == NULL )	/* 1er Module */
				{
					m_Pcb->m_Modules = NewModule;
					NewModule->Pback = m_Pcb;
				}

				else
				{
					Module->Pnext = NewModule;
					NewModule->Pback = Module;
				}
				fclose(lib_module) ;
				Affiche_Message(wxEmptyString) ;
				return(NewModule) ;
			}
		}
		fclose(lib_module) ; lib_module = 0;
	}

	if( lib_module ) fclose(lib_module) ;

	if ( show_msg_err )
	{
		msg.Printf(_("Module <%s> not found"),ComponentName.GetData());
		DisplayError(winaff, msg);
	}
	return(NULL) ;
}
Esempio n. 16
0
bool EXCELLON_IMAGE::Read_EXCELLON_File( FILE * aFile,
                                        const wxString & aFullFileName )
{
    /* Set the gerber scale: */
    ResetDefaultValues();

    m_FileName = aFullFileName;
    m_Current_File = aFile;

    SetLocaleTo_C_standard();

    // FILE_LINE_READER will close the file.
    if( m_Current_File == NULL )
    {
        wxMessageBox( wxT("NULL!"), m_FileName );
        return false;
    }

    FILE_LINE_READER excellonReader( m_Current_File, m_FileName );
    while( true )
    {
        if( excellonReader.ReadLine() == 0 )
            break;

        char* line = excellonReader.Line();
        char* text = StrPurge( line );

        if( *text == ';' )       // comment: skip line
            continue;

        if( m_State == EXCELLON_IMAGE::READ_HEADER_STATE )
        {
            Execute_HEADER_Command( text );
        }
        else
        {
            switch( *text )
            {
            case 'M':
                Execute_HEADER_Command( text );
                break;

            case 'G': /* Line type Gxx : command */
                Execute_EXCELLON_G_Command( text );
                break;

            case 'X':
            case 'Y':               // command like X12550Y19250
                Execute_Drill_Command(text);
                break;

            case 'I':
            case 'J':               /* Auxiliary Move command */
                m_IJPos = ReadIJCoord( text );
                if( *text == '*' )  // command like X35142Y15945J504
                {
                    Execute_Drill_Command( text);
                }
                break;

            case 'T': // Tool command
                Select_Tool( text );
                break;

            case '%':
                break;

            default:
            {
                wxString msg;
                msg.Printf( wxT( "Unexpected symbol &lt;%c&gt;" ), *text );
                if( GetParent() )
                    GetParent()->ReportMessage( msg );
            }
                break;
            }   // End switch
        }
    }
    SetLocaleTo_Default();
    return true;
}
Esempio n. 17
0
/* Read a gerber file, RS274D or RS274X format.
 */
bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName,
                                           const wxString& D_Code_FullFileName )
{
    int      G_command = 0;        // command number for G commands like G04
    int      D_commande = 0;       // command number for D commands like D02

    char     line[GERBER_BUFZ];

    wxString msg;
    char*    text;
    int layer;         // current layer used in GerbView

    layer = getActiveLayer();

    if( g_GERBER_List[layer] == NULL )
    {
        g_GERBER_List[layer] = new GERBER_IMAGE( this, layer );
    }

    GERBER_IMAGE* gerber = g_GERBER_List[layer];
    ClearMessageList( );

    /* Set the gerber scale: */
    gerber->ResetDefaultValues();

    /* Read the gerber file */
    gerber->m_Current_File = wxFopen( GERBER_FullFileName, wxT( "rt" ) );
    if( gerber->m_Current_File == 0 )
    {
        msg.Printf( _( "File <%s> not found" ), GetChars( GERBER_FullFileName ) );
        DisplayError( this, msg, 10 );
        return false;
    }

    gerber->m_FileName = GERBER_FullFileName;

    wxString path = wxPathOnly( GERBER_FullFileName );
    if( path != wxEmptyString )
        wxSetWorkingDirectory( path );

    SetLocaleTo_C_standard();

    while( true )
    {
        if( fgets( line, sizeof(line), gerber->m_Current_File ) == NULL )
        {
            if( gerber->m_FilesPtr == 0 )
                break;

            fclose( gerber->m_Current_File );

            gerber->m_FilesPtr--;
            gerber->m_Current_File =
                gerber->m_FilesList[gerber->m_FilesPtr];

            continue;
        }

        text = StrPurge( line );

        while( text && *text )
        {
            switch( *text )
            {
            case ' ':
            case '\r':
            case '\n':
                text++;
                break;

            case '*':       // End command
                gerber->m_CommandState = END_BLOCK;
                text++;
                break;

            case 'M':       // End file
                gerber->m_CommandState = CMD_IDLE;
                while( *text )
                    text++;
                break;

            case 'G':    /* Line type Gxx : command */
                G_command = gerber->GCodeNumber( text );
                gerber->Execute_G_Command( text, G_command );
                break;

            case 'D':       /* Line type Dxx : Tool selection (xx > 0) or
                             * command if xx = 0..9 */
                D_commande = gerber->DCodeNumber( text );
                gerber->Execute_DCODE_Command( text, D_commande );
                break;

            case 'X':
            case 'Y':                   /* Move or draw command */
                gerber->m_CurrentPos = gerber->ReadXYCoord( text );
                if( *text == '*' )      // command like X12550Y19250*
                {
                    gerber->Execute_DCODE_Command( text,
                                                   gerber->m_Last_Pen_Command );
                }
                break;

            case 'I':
            case 'J':       /* Auxiliary Move command */
                gerber->m_IJPos = gerber->ReadIJCoord( text );
                if( *text == '*' )      // command like X35142Y15945J504*
                {
                    gerber->Execute_DCODE_Command( text,
                                                   gerber->m_Last_Pen_Command );
                }
                break;

            case '%':
                if( gerber->m_CommandState != ENTER_RS274X_CMD )
                {
                    gerber->m_CommandState = ENTER_RS274X_CMD;
                    gerber->ReadRS274XCommand( line, text );
                }
                else        //Error
                {
                    ReportMessage( wxT("Expected RS274X Command")  );
                    gerber->m_CommandState = CMD_IDLE;
                    text++;
                }
                break;

            default:
                text++;
                msg.Printf( wxT("Unexpected symbol <%c>"), *text );
                ReportMessage( msg );
                break;
            }
        }
    }
    fclose( gerber->m_Current_File );
    SetLocaleTo_Default();

    gerber->m_InUse = true;

    // Display errors list
    if( m_Messages.size() > 0 )
    {
        HTML_MESSAGE_BOX dlg( this, _("Errors") );
        dlg.ListSet(m_Messages);
        dlg.ShowModal();
    }

    /* if the gerber file is only a RS274D file
     * (i.e. without any aperture information), wran the user:
     */
    if( !gerber->m_Has_DCode )
    {
        msg = _("Warning: this file has no D-Code definition\n"
                "It is perhaps an old RS274D file\n"
                "Therefore the size of items is undefined");
        wxMessageBox( msg );
    }

    return true;
}