35#include <nlohmann/json.hpp>
62 int aCtlBits = 0 )
override
105 void SaveFileAs(
const wxString& aProjectBasePath,
const wxString& aProjectName,
106 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
107 const wxString& aSrcFilePath, wxString& aErrors )
override;
114using namespace GERBV;
162 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
163 const wxString& aSrcFilePath, wxString& aErrors )
165 wxFileName destFile( aSrcFilePath );
166 wxString destPath = destFile.GetPathWithSep();
167 wxUniChar pathSep = wxFileName::GetPathSeparator();
168 wxString ext = destFile.GetExt();
170 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
172 destPath.Replace( aProjectBasePath, aNewProjectBasePath,
false );
173 destFile.SetPath( destPath );
178 wxString destFileName = destFile.GetName();
180 if( destFileName.StartsWith( aProjectName +
"-" ) )
182 destFileName.Replace( aProjectName, aNewProjectName,
false );
183 destFile.SetName( destFileName );
186 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
190 if( destFile.GetName() == aProjectName + wxT(
"-job" ) )
191 destFile.SetName( aNewProjectName + wxT(
"-job" ) );
198 while( ( line = jobfileReader.
ReadLine() ) )
199 data << line <<
'\n';
202 if( !data.Contains( wxT(
"{" ) ) )
204 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
208 bool success =
false;
215 for(
auto& entry : js[
"FilesAttributes"] )
217 wxString
path = wxString( entry[
"Path"].get<std::string>() );
219 if(
path.StartsWith( aProjectName + wxT(
"-" ) ) )
221 path.Replace( aProjectName, aNewProjectName,
false );
222 entry[
"Path"] =
path.ToStdString();
226 wxFFile destJobFile( destFile.GetFullPath(), wxT(
"wb" ) );
228 if( destJobFile.IsOpened() )
229 success = destJobFile.Write( js.dump( 0 ) );
242 if( !aErrors.empty() )
243 aErrors += wxT(
"\n" );
245 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
251 wxString destFileName = destFile.GetName();
253 if( destFileName == aProjectName )
254 destFileName = aNewProjectName;
255 else if( destFileName.StartsWith( aProjectName + wxT(
"-" ) ) )
256 destFileName.Replace( aProjectName, aNewProjectName,
false );
258 destFile.SetName( destFileName );
260 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
264 wxFAIL_MSG( wxT(
"Unexpected filetype for GerbView::SaveFileAs()" ) );
A LINE_READER that reads from an open file.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
void InitSettings(APP_SETTINGS_BASE *aSettings)
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
APP_SETTINGS_BASE * KifaceSettings() const
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
FACE_T
Known KIFACE implementations.
Container for data for KiCad programs.
virtual SETTINGS_MANAGER & GetSettingsManager() const
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
@ PANEL_GBR_DISPLAY_OPTIONS
@ PANEL_GBR_EXCELLON_OPTIONS
MY_API(KIFACE *) KIFACE_GETTER(int *aKIFACEversion
static PGM_BASE * process
PGM_BASE & Pgm()
The global Program "get" accessor.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
const std::string GerberJobFileExtension
const std::string DrillFileExtension
bool IsGerberFileExtension(const wxString &ext)
This file contains miscellaneous commonly used macros and functions.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
GERBV::IFACE KIFACE_BASE kiface("gerbview", KIWAY::FACE_GERBVIEW)
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 ...
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
void * IfaceOrAddress(int aDataId) override
Return a pointer to the requested object.
void OnKifaceEnd() override
Called just once just before the DSO is to be unloaded.
IFACE(const char *aName, KIWAY::FACE_T aType)
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits) override
Typically start_common() is called from here.
Implement a participant in the KIWAY alchemy.
Definition of file extensions used in Kicad.