bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary() { wxString libPath = getLibPath(); wxString footprintName = Select_1_Module_From_List( this, libPath, wxEmptyString, wxEmptyString ); if( !footprintName ) return false; // Confirmation wxString msg = wxString::Format( FMT_OK_DELETE, footprintName.GetData(), libPath.GetData() ); if( !IsOK( this, msg ) ) return false; IO_MGR::PCB_FILE_T pluginType = IO_MGR::GuessPluginTypeFromLibPath( libPath ); try { PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) ); pi->FootprintDelete( libPath, footprintName ); } catch( IO_ERROR ioe ) { DisplayError( NULL, ioe.errorText ); return false; } msg.Printf( FMT_MOD_DELETED, footprintName.GetData(), libPath.GetData() ); SetStatusText( msg ); return true; }
MODULE * WinEDA_BasePcbFrame::Load_Module_From_Library(const wxString & library, wxDC * DC) /****************************************************************************/ /* Permet de charger un module directement a partir de la librairie */ { MODULE * module; wxPoint curspos = m_CurrentScreen->m_Curseur; wxString ModuleName, keys; static wxArrayString HistoryList; bool AllowWildSeach = TRUE; /* Ask for a component name or key words */ ModuleName = GetComponentName(this, HistoryList, _("Module name:"), NULL); ModuleName.MakeUpper(); if( ModuleName.IsEmpty() ) /* Cancel command */ { DrawPanel->MouseToCursorSchema(); return NULL; } if( ModuleName[0] == '=' ) // Selection by keywords { AllowWildSeach = FALSE; keys = ModuleName.AfterFirst('='); ModuleName = Select_1_Module_From_List(this, library, wxEmptyString, keys); if( ModuleName.IsEmpty() ) /* Cancel command */ { DrawPanel->MouseToCursorSchema(); return NULL; } } else if( (ModuleName.Contains(wxT("?"))) || (ModuleName.Contains(wxT("*"))) ) // Selection wild card { AllowWildSeach = FALSE; ModuleName = Select_1_Module_From_List(this, library, ModuleName, wxEmptyString); if( ModuleName.IsEmpty() ) { DrawPanel->MouseToCursorSchema(); return NULL; /* annulation de commande */ } } module = Get_Librairie_Module(this, library, ModuleName, FALSE); if( (module == NULL) && AllowWildSeach ) /* Attemp to search with wildcard */ { AllowWildSeach = FALSE; wxString wildname = wxChar('*') + ModuleName + wxChar('*'); ModuleName = wildname; ModuleName = Select_1_Module_From_List(this, library, ModuleName, wxEmptyString); if( ModuleName.IsEmpty() ) { DrawPanel->MouseToCursorSchema(); return NULL; /* annulation de commande */ } else module = Get_Librairie_Module(this, library, ModuleName, TRUE); } m_CurrentScreen->m_Curseur = curspos; DrawPanel->MouseToCursorSchema(); if( module ) { AddHistoryComponentName(HistoryList, ModuleName); module->m_Flags = IS_NEW; module->m_Link = 0; module->m_TimeStamp = GetTimeStamp(); m_Pcb->m_Status_Pcb = 0 ; module->SetPosition(curspos); build_liste_pads(); module->Draw(DrawPanel, DC, wxPoint(0,0), GR_OR); } return module; }
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); }