35 #include <nlohmann/json.hpp> 59 int aCtlBits = 0 )
override 97 void SaveFileAs(
const wxString& aProjectBasePath,
const wxString& aProjectName,
98 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
99 const wxString& aSrcFilePath, wxString& aErrors )
override;
106 using namespace GERBV;
154 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
155 const wxString& aSrcFilePath, wxString& aErrors )
157 wxFileName destFile( aSrcFilePath );
158 wxString destPath = destFile.GetPathWithSep();
159 wxUniChar pathSep = wxFileName::GetPathSeparator();
160 wxString ext = destFile.GetExt();
162 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
164 destPath.Replace( aProjectBasePath, aNewProjectBasePath,
false );
165 destFile.SetPath( destPath );
170 wxString destFileName = destFile.GetName();
172 if( destFileName.StartsWith( aProjectName +
"-" ) )
174 destFileName.Replace( aProjectName, aNewProjectName,
false );
175 destFile.SetName( destFileName );
178 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
180 else if( ext == wxT(
"gbrjob" ) )
182 if( destFile.GetName() == aProjectName + wxT(
"-job" ) )
183 destFile.SetName( aNewProjectName + wxT(
"-job" ) );
190 while( ( line = jobfileReader.ReadLine() ) )
191 data << line <<
'\n';
194 if( !data.Contains( wxT(
"{" ) ) )
196 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
200 bool success =
false;
207 for(
auto& entry : js[
"FilesAttributes"] )
209 wxString
path = wxString( entry[
"Path"].get<std::string>() );
211 if(
path.StartsWith( aProjectName + wxT(
"-" ) ) )
213 path.Replace( aProjectName, aNewProjectName,
false );
214 entry[
"Path"] =
path.ToStdString();
218 wxFFile destJobFile( destFile.GetFullPath(), wxT(
"wb" ) );
220 if( destJobFile.IsOpened() )
221 success = destJobFile.Write( js.dump( 0 ) );
234 if( !aErrors.empty() )
235 aErrors += wxT(
"\n" );
237 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
241 else if( ext == wxT(
"drl" ) )
243 wxString destFileName = destFile.GetName();
245 if( destFileName == aProjectName )
246 destFileName = aNewProjectName;
247 else if( destFileName.StartsWith( aProjectName + wxT(
"-" ) ) )
248 destFileName.Replace( aProjectName, aNewProjectName,
false );
250 destFile.SetName( destFileName );
252 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
256 wxFAIL_MSG( wxT(
"Unexpected filetype for GerbView::SaveFileAs()" ) );
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
virtual SETTINGS_MANAGER & GetSettingsManager() const
wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
PGM_BASE & Pgm()
The global Program "get" accessor.
Container for data for KiCad programs.
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
bool IsProtelExtension(const wxString &ext)
This file contains miscellaneous commonly used macros and functions.
static PGM_BASE * process
void InitSettings(APP_SETTINGS_BASE *aSettings)
IFACE(const char *aName, KIWAY::FACE_T aType)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
A LINE_READER that reads from an open file.
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition of file extensions used in Kicad.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
FACE_T
Known KIFACE implementations.
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
GERBV::IFACE KIFACE_BASE kiface("gerbview", KIWAY::FACE_GERBVIEW)
Implement a participant in the KIWAY alchemy.
void SaveFileAs(const wxString &aProjectBasePath, const wxString &aProjectName, const wxString &aNewProjectBasePath, const wxString &aNewProjectName, const wxString &aSrcFilePath, wxString &aErrors) override
Saving a file under a different name is delegated to the various KIFACEs because the project doesn't ...
APP_SETTINGS_BASE * KifaceSettings() const
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...