35#include <nlohmann/json.hpp>
47using json = nlohmann::json;
66 int aCtlBits = 0 )
override
121 void SaveFileAs(
const wxString& aProjectBasePath,
const wxString& aProjectName,
122 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
123 const wxString& aSrcFilePath, wxString& aErrors )
override;
130using namespace GERBV;
160 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
161 const wxString& aSrcFilePath, wxString& aErrors )
163 wxFileName destFile( aSrcFilePath );
164 wxString destPath = destFile.GetPathWithSep();
165 wxUniChar pathSep = wxFileName::GetPathSeparator();
166 wxString ext = destFile.GetExt();
168 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
170 destPath.Replace( aProjectBasePath, aNewProjectBasePath,
false );
171 destFile.SetPath( destPath );
176 wxString destFileName = destFile.GetName();
178 if( destFileName.StartsWith( aProjectName +
"-" ) )
180 destFileName.Replace( aProjectName, aNewProjectName,
false );
181 destFile.SetName( destFileName );
184 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
188 if( destFile.GetName() == aProjectName + wxT(
"-job" ) )
189 destFile.SetName( aNewProjectName + wxT(
"-job" ) );
196 while( ( line = jobfileReader.
ReadLine() ) !=
nullptr )
197 data << line <<
'\n';
200 if( !data.Contains( wxT(
"{" ) ) )
202 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
206 bool success =
false;
213 for(
auto& entry : js[
"FilesAttributes"] )
215 wxString
path = wxString( entry[
"Path"].get<std::string>() );
217 if(
path.StartsWith( aProjectName + wxT(
"-" ) ) )
219 path.Replace( aProjectName, aNewProjectName,
false );
220 entry[
"Path"] =
path.ToStdString();
224 wxFFile destJobFile( destFile.GetFullPath(), wxT(
"wb" ) );
226 if( destJobFile.IsOpened() )
227 success = destJobFile.Write( js.dump( 0 ) );
240 if( !aErrors.empty() )
241 aErrors += wxT(
"\n" );
243 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
249 wxString destFileName = destFile.GetName();
251 if( destFileName == aProjectName )
252 destFileName = aNewProjectName;
253 else if( destFileName.StartsWith( aProjectName + wxT(
"-" ) ) )
254 destFileName.Replace( aProjectName, aNewProjectName,
false );
256 destFile.SetName( destFileName );
258 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
262 wxFAIL_MSG( wxT(
"Unexpected filetype for GerbView::SaveFileAs()" ) );
constexpr EDA_IU_SCALE gerbIUScale
The base frame for deriving all KiCad main window classes.
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...
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
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.
T * GetAppSettings(const wxString &aFilename)
Returns a handle to the a given settings by type If the settings have already been loaded,...
void SetUserUnits(EDA_UNITS aUnits)
@ PANEL_GBR_DISPLAY_OPTIONS
@ PANEL_GBR_EXCELLON_OPTIONS
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
static const std::string GerberJobFileExtension
static const std::string DrillFileExtension
static bool IsGerberFileExtension(const wxString &ext)
This file contains miscellaneous commonly used macros and functions.
GERBV::IFACE KIFACE_BASE, UNITS_PROVIDER kiface("gerbview", KIWAY::FACE_GERBVIEW)
PGM_BASE & Pgm()
The global Program "get" accessor.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
bool OnKifaceStart(PGM_BASE *aProgram, int aCtlBits, KIWAY *aKiway) override
Typically start_common() is called from here.
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 ...
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, KIWAY *aKiway) override
Typically start_common() is called from here.
Implement a participant in the KIWAY alchemy.
Definition of file extensions used in Kicad.