35#include <nlohmann/json.hpp>
50using json = nlohmann::json;
69 int aCtlBits = 0 )
override
103 std::vector<TOOL_ACTION*> actions;
104 std::vector<ACTION_TOOLBAR_CONTROL*> controls;
107 actions.push_back( action );
110 controls.push_back( control );
142 void SaveFileAs(
const wxString& aProjectBasePath,
const wxString& aProjectName,
143 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
144 const wxString& aSrcFilePath, wxString& aErrors )
override;
151using namespace GERBV;
181 const wxString& aNewProjectBasePath,
const wxString& aNewProjectName,
182 const wxString& aSrcFilePath, wxString& aErrors )
184 wxFileName destFile( aSrcFilePath );
185 wxString destPath = destFile.GetPathWithSep();
186 wxUniChar pathSep = wxFileName::GetPathSeparator();
187 wxString ext = destFile.GetExt();
189 if( destPath.StartsWith( aProjectBasePath + pathSep ) )
191 destPath.Replace( aProjectBasePath, aNewProjectBasePath,
false );
192 destFile.SetPath( destPath );
197 wxString destFileName = destFile.GetName();
199 if( destFileName.StartsWith( aProjectName +
"-" ) )
201 destFileName.Replace( aProjectName, aNewProjectName,
false );
202 destFile.SetName( destFileName );
205 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
209 if( destFile.GetName() == aProjectName + wxT(
"-job" ) )
210 destFile.SetName( aNewProjectName + wxT(
"-job" ) );
217 while( ( line = jobfileReader.
ReadLine() ) !=
nullptr )
218 data << line <<
'\n';
221 if( !data.Contains( wxT(
"{" ) ) )
223 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
227 bool success =
false;
234 for(
auto& entry : js[
"FilesAttributes"] )
236 wxString
path = wxString( entry[
"Path"].get<std::string>() );
238 if(
path.StartsWith( aProjectName + wxT(
"-" ) ) )
240 path.Replace( aProjectName, aNewProjectName,
false );
241 entry[
"Path"] =
path.ToStdString();
245 wxFFile destJobFile( destFile.GetFullPath(), wxT(
"wb" ) );
247 if( destJobFile.IsOpened() )
248 success = destJobFile.Write( js.dump( 0 ) );
261 if( !aErrors.empty() )
262 aErrors += wxT(
"\n" );
264 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
270 wxString destFileName = destFile.GetName();
272 if( destFileName == aProjectName )
273 destFileName = aNewProjectName;
274 else if( destFileName.StartsWith( aProjectName + wxT(
"-" ) ) )
275 destFileName.Replace( aProjectName, aNewProjectName,
false );
277 destFile.SetName( destFileName );
279 KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
283 wxFAIL_MSG( wxT(
"Unexpected filetype for GerbView::SaveFileAs()" ) );
constexpr EDA_IU_SCALE gerbIUScale
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
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)
Take ownership of the pointer passed in.
T * GetToolbarSettings(const wxString &aFilename)
Return a handle to the given toolbar settings.
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
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.