KiCad PCB EDA Suite
SAVE_AS_TRAVERSER Class Reference
Inheritance diagram for SAVE_AS_TRAVERSER:

Public Member Functions

 SAVE_AS_TRAVERSER (KICAD_MANAGER_FRAME *aFrame, const wxString &aSrcProjectDirPath, const wxString &aSrcProjectName, const wxString &aNewProjectDirPath, const wxString &aNewProjectName)
 
virtual wxDirTraverseResult OnFile (const wxString &aSrcFilePath) override
 
virtual wxDirTraverseResult OnDir (const wxString &aSrcDirPath) override
 
wxString GetErrors ()
 
wxFileName GetNewProjectFile ()
 

Private Attributes

KICAD_MANAGER_FRAMEm_frame
 
wxString m_projectDirPath
 
wxString m_projectName
 
wxString m_newProjectDirPath
 
wxString m_newProjectName
 
wxFileName m_newProjectFile
 
wxString m_errors
 

Detailed Description

Definition at line 341 of file kicad_manager_control.cpp.

Constructor & Destructor Documentation

◆ SAVE_AS_TRAVERSER()

SAVE_AS_TRAVERSER::SAVE_AS_TRAVERSER ( KICAD_MANAGER_FRAME aFrame,
const wxString &  aSrcProjectDirPath,
const wxString &  aSrcProjectName,
const wxString &  aNewProjectDirPath,
const wxString &  aNewProjectName 
)
inline

Definition at line 344 of file kicad_manager_control.cpp.

348  :
349  m_frame( aFrame ),
350  m_projectDirPath( aSrcProjectDirPath ),
351  m_projectName( aSrcProjectName ),
352  m_newProjectDirPath( aNewProjectDirPath ),
353  m_newProjectName( aNewProjectName )
354  {
355  }
KICAD_MANAGER_FRAME * m_frame

Member Function Documentation

◆ GetErrors()

wxString SAVE_AS_TRAVERSER::GetErrors ( )
inline

Definition at line 503 of file kicad_manager_control.cpp.

503 { return m_errors; }

References m_errors.

Referenced by KICAD_MANAGER_CONTROL::SaveProjectAs().

◆ GetNewProjectFile()

wxFileName SAVE_AS_TRAVERSER::GetNewProjectFile ( )
inline

Definition at line 505 of file kicad_manager_control.cpp.

505 { return m_newProjectFile; }

References m_newProjectFile.

Referenced by KICAD_MANAGER_CONTROL::SaveProjectAs().

◆ OnDir()

virtual wxDirTraverseResult SAVE_AS_TRAVERSER::OnDir ( const wxString &  aSrcDirPath)
inlineoverridevirtual

Definition at line 460 of file kicad_manager_control.cpp.

461  {
462  // Recursion guard for a Save As to a location inside the source project.
463  if( aSrcDirPath.StartsWith( m_newProjectDirPath ) )
464  return wxDIR_CONTINUE;
465 
466  wxFileName destDir( aSrcDirPath );
467  wxString destDirPath = destDir.GetPathWithSep();
468  wxUniChar pathSep = wxFileName::GetPathSeparator();
469 
470  if( destDirPath.StartsWith( m_projectDirPath + pathSep )
471  || destDirPath.StartsWith( m_projectDirPath + PROJECT_BACKUPS_DIR_SUFFIX ) )
472  {
473  destDirPath.Replace( m_projectDirPath, m_newProjectDirPath, false );
474  destDir.SetPath( destDirPath );
475  }
476 
477  if( destDir.GetName() == m_projectName )
478  {
479  if( destDir.GetExt() == "pretty" )
480  destDir.SetName( m_newProjectName );
481 #if 0
482  // WAYNE STAMBAUGH TODO:
483  // If we end up with a symbol equivalent to ".pretty" we'll want to handle it here....
484  else if( destDir.GetExt() == "sym_lib_dir_extension" )
485  destDir.SetName( m_newProjectName );
486 #endif
487  }
488 
489  if( !wxMkdir( destDir.GetFullPath() ) )
490  {
491  wxString msg;
492 
493  if( !m_errors.empty() )
494  m_errors += "\n";
495 
496  msg.Printf( _( "Cannot copy folder '%s'." ), destDir.GetFullPath() );
497  m_errors += msg;
498  }
499 
500  return wxDIR_CONTINUE;
501  }
#define _(s)
#define PROJECT_BACKUPS_DIR_SUFFIX
Project settings path will be <projectname> + this.

References _, m_errors, m_newProjectDirPath, m_newProjectName, m_projectDirPath, m_projectName, and PROJECT_BACKUPS_DIR_SUFFIX.

◆ OnFile()

virtual wxDirTraverseResult SAVE_AS_TRAVERSER::OnFile ( const wxString &  aSrcFilePath)
inlineoverridevirtual

Definition at line 357 of file kicad_manager_control.cpp.

358  {
359  // Recursion guard for a Save As to a location inside the source project.
360  if( aSrcFilePath.StartsWith( m_newProjectDirPath ) )
361  return wxDIR_CONTINUE;
362 
363  wxFileName destFile( aSrcFilePath );
364  wxString ext = destFile.GetExt();
365  bool atRoot = destFile.GetPath() == m_projectDirPath;
366 
367  if( ext == "pro" )
368  {
369  wxString destPath = destFile.GetPath();
370 
371  if( destPath.StartsWith( m_projectDirPath ) )
372  {
373  destPath.Replace( m_projectDirPath, m_newProjectDirPath, false );
374  destFile.SetPath( destPath );
375  }
376 
377  if( destFile.GetName() == m_projectName )
378  {
379  destFile.SetName( m_newProjectName );
380 
381  if( atRoot )
382  m_newProjectFile = destFile;
383  }
384 
385  // Currently all paths in the settings file are relative, so we can just do a
386  // straight copy
387  KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors );
388  }
389  else if( ext == KiCadSchematicFileExtension
397  || ext == NetlistFileExtension
398  || destFile.GetName() == "sym-lib-table" )
399  {
402  m_newProjectName, aSrcFilePath, m_errors );
403  }
404  else if( ext == KiCadPcbFileExtension
406  || ext == LegacyPcbFileExtension
410  || destFile.GetName() == "fp-lib-table" )
411  {
414  m_newProjectName, aSrcFilePath, m_errors );
415  }
416  else if( ext == DrawingSheetFileExtension )
417  {
418  KIFACE* pleditor = m_frame->Kiway().KiFACE( KIWAY::FACE_PL_EDITOR );
420  m_newProjectName, aSrcFilePath, m_errors );
421  }
422  else if( ext == GerberFileExtension
423  || ext == GerberJobFileExtension
424  || ext == DrillFileExtension
425  || IsProtelExtension( ext ) )
426  {
427  KIFACE* gerbview = m_frame->Kiway().KiFACE( KIWAY::FACE_GERBVIEW );
429  m_newProjectName, aSrcFilePath, m_errors );
430  }
431  else
432  {
433  // Everything we don't recognize just gets a straight copy.
434  wxString destPath = destFile.GetPathWithSep();
435  wxString destName = destFile.GetName();
436  wxUniChar pathSep = wxFileName::GetPathSeparator();
437 
438  wxString srcProjectFootprintLib = pathSep + m_projectName + ".pretty" + pathSep;
439  wxString newProjectFootprintLib = pathSep + m_newProjectName + ".pretty" + pathSep;
440 
441  if( destPath.StartsWith( m_projectDirPath ) )
442  {
443  destPath.Replace( m_projectDirPath, m_newProjectDirPath, false );
444  destFile.SetPath( destPath );
445  }
446 
447  if( destName == m_projectName )
448  destFile.SetName( m_newProjectName );
449 
450  destPath.Replace( srcProjectFootprintLib, newProjectFootprintLib, true );
451  destFile.SetPath( destPath );
452 
453 
454  KiCopyFile( aSrcFilePath, destFile.GetFullPath(), m_errors );
455  }
456 
457  return wxDIR_CONTINUE;
458  }
const std::string NetlistFileExtension
const std::string LegacyFootprintLibPathExtension
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
const std::string KiCadFootprintFileExtension
const std::string LegacyPcbFileExtension
const std::string LegacySymbolLibFileExtension
const std::string BackupFileSuffix
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition: gestfich.cpp:326
const std::string SchematicSymbolFileExtension
const std::string GerberFileExtension
const std::string KiCadPcbFileExtension
bool IsProtelExtension(const wxString &ext)
const std::string FootprintAssignmentFileExtension
const std::string LegacySymbolDocumentFileExtension
const std::string GerberJobFileExtension
pcbnew DSO
Definition: kiway.h:269
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:196
const std::string LegacySchematicFileExtension
virtual void SaveFileAs(const wxString &srcProjectBasePath, const wxString &srcProjectName, const wxString &newProjectBasePath, const wxString &newProjectName, const wxString &srcFilePath, wxString &aErrors)
Saving a file under a different name is delegated to the various KIFACEs because the project doesn't ...
Definition: kiway.h:208
eeschema DSO
Definition: kiway.h:268
KICAD_MANAGER_FRAME * m_frame
const std::string DrawingSheetFileExtension
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:148
const std::string KiCadSchematicFileExtension
const std::string DrillFileExtension
const std::string KiCadSymbolLibFileExtension

References BackupFileSuffix, DrawingSheetFileExtension, DrillFileExtension, eeschema, KIWAY::FACE_GERBVIEW, KIWAY::FACE_PCB, KIWAY::FACE_PL_EDITOR, KIWAY::FACE_SCH, FootprintAssignmentFileExtension, GerberFileExtension, GerberJobFileExtension, IsProtelExtension(), KiCadFootprintFileExtension, KiCadPcbFileExtension, KiCadSchematicFileExtension, KiCadSymbolLibFileExtension, KiCopyFile(), KIWAY::KiFACE(), KIWAY_HOLDER::Kiway(), LegacyFootprintLibPathExtension, LegacyPcbFileExtension, LegacySchematicFileExtension, LegacySymbolDocumentFileExtension, LegacySymbolLibFileExtension, m_errors, m_frame, m_newProjectDirPath, m_newProjectFile, m_newProjectName, m_projectDirPath, m_projectName, NetlistFileExtension, pcbnew, KIFACE::SaveFileAs(), and SchematicSymbolFileExtension.

Member Data Documentation

◆ m_errors

wxString SAVE_AS_TRAVERSER::m_errors
private

Definition at line 516 of file kicad_manager_control.cpp.

Referenced by GetErrors(), OnDir(), and OnFile().

◆ m_frame

KICAD_MANAGER_FRAME* SAVE_AS_TRAVERSER::m_frame
private

Definition at line 508 of file kicad_manager_control.cpp.

Referenced by OnFile().

◆ m_newProjectDirPath

wxString SAVE_AS_TRAVERSER::m_newProjectDirPath
private

Definition at line 512 of file kicad_manager_control.cpp.

Referenced by OnDir(), and OnFile().

◆ m_newProjectFile

wxFileName SAVE_AS_TRAVERSER::m_newProjectFile
private

Definition at line 515 of file kicad_manager_control.cpp.

Referenced by GetNewProjectFile(), and OnFile().

◆ m_newProjectName

wxString SAVE_AS_TRAVERSER::m_newProjectName
private

Definition at line 513 of file kicad_manager_control.cpp.

Referenced by OnDir(), and OnFile().

◆ m_projectDirPath

wxString SAVE_AS_TRAVERSER::m_projectDirPath
private

Definition at line 510 of file kicad_manager_control.cpp.

Referenced by OnDir(), and OnFile().

◆ m_projectName

wxString SAVE_AS_TRAVERSER::m_projectName
private

Definition at line 511 of file kicad_manager_control.cpp.

Referenced by OnDir(), and OnFile().


The documentation for this class was generated from the following file: