35#include <nlohmann/json.hpp>
46using json = nlohmann::json;
64 int aCtlBits = 0 )
override
107 void SaveFileAs(
const wxString& aProjectBasePath,
const wxString& aProjectName,
108 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
109 const wxString& aSrcFilePath, wxString& aErrors )
override;
116using namespace GERBV;
164 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
165 const wxString& aSrcFilePath, wxString& aErrors )
167 wxFileName destFile( aSrcFilePath );
168 wxString destPath = destFile.GetPathWithSep();
169 wxUniChar pathSep = wxFileName::GetPathSeparator();
170 wxString ext = destFile.GetExt();
172 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
174 destPath.Replace( aProjectBasePath, aNewProjectBasePath,
false );
175 destFile.SetPath( destPath );
180 wxString destFileName = destFile.GetName();
182 if( destFileName.StartsWith( aProjectName +
"-" ) )
184 destFileName.Replace( aProjectName, aNewProjectName,
false );
185 destFile.SetName( destFileName );
188 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
192 if( destFile.GetName() == aProjectName + wxT(
"-job" ) )
193 destFile.SetName( aNewProjectName + wxT(
"-job" ) );
200 while( ( line = jobfileReader.
ReadLine() ) !=
nullptr )
201 data << line <<
'\n';
204 if( !data.Contains( wxT(
"{" ) ) )
206 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
210 bool success =
false;
217 for(
auto& entry : js[
"FilesAttributes"] )
219 wxString
path = wxString( entry[
"Path"].get<std::string>() );
221 if(
path.StartsWith( aProjectName + wxT(
"-" ) ) )
223 path.Replace( aProjectName, aNewProjectName,
false );
224 entry[
"Path"] =
path.ToStdString();
228 wxFFile destJobFile( destFile.GetFullPath(), wxT(
"wb" ) );
230 if( destJobFile.IsOpened() )
231 success = destJobFile.Write( js.dump( 0 ) );
244 if( !aErrors.empty() )
245 aErrors += wxT(
"\n" );
247 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
253 wxString destFileName = destFile.GetName();
255 if( destFileName == aProjectName )
256 destFileName = aNewProjectName;
257 else if( destFileName.StartsWith( aProjectName + wxT(
"-" ) ) )
258 destFileName.Replace( aProjectName, aNewProjectName,
false );
260 destFile.SetName( destFileName );
262 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
266 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
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.
GERBV::IFACE KIFACE_BASE kiface("gerbview", KIWAY::FACE_GERBVIEW)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
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.