KiCad PCB EDA Suite
IMPORT_PROJ_HELPER Class Reference

A helper class to import non Kicad project. More...

#include <import_proj.h>

Public Member Functions

 IMPORT_PROJ_HELPER (KICAD_MANAGER_FRAME *aframe, const wxString &aFile, const wxString &aSchFileExtension, const wxString &aPcbFileExtension)
 
const wxFileName & GetProj ()
 
wxString GetProjPath ()
 
void SetProjPath (const wxString aPath)
 
wxString GetProjFullPath ()
 
wxString GetProjName ()
 
void CreateEmptyDirForProject ()
 Appends a new directory with the name of the project file Keep iterating until an empty directory is found. More...
 
void SetProjAbsolutePath ()
 
bool CopyImportedFiles (bool displayError=true)
 Copies project files to the destination directory. More...
 
void AssociateFilesWithProj (int aImportedSchFileType, int aImportedPcbFileType)
 Converts imported files to kicad type files. More...
 

Private Member Functions

bool CopyImportedFile (KICAD_T aKicad_T, bool displayError=true)
 
void OutputCopyError (const wxFileName &aSrc, const wxFileName &aFileCopy)
 
void AssociateFileWithProj (KICAD_T aKicad_T, int aImportedFileType)
 

Private Attributes

KICAD_MANAGER_FRAMEm_frame
 
wxFileName m_sch
 
wxFileName m_shCopy
 
wxFileName m_pcb
 
wxFileName m_pcbCopy
 
wxFileName m_pro
 

Detailed Description

A helper class to import non Kicad project.

Definition at line 11 of file import_proj.h.

Constructor & Destructor Documentation

◆ IMPORT_PROJ_HELPER()

IMPORT_PROJ_HELPER::IMPORT_PROJ_HELPER ( KICAD_MANAGER_FRAME aframe,
const wxString &  aFile,
const wxString &  aSchFileExtension,
const wxString &  aPcbFileExtension 
)

Definition at line 31 of file import_proj.cpp.

34 :
35 m_frame( aFrame ),
36 m_sch( aFile ), m_pcb( m_sch ), m_pro( m_sch )
37{
38 m_sch.SetExt( aSchFileExtension );
39 m_pcb.SetExt( aPcbFileExtension );
41}
wxFileName m_pcb
Definition: import_proj.h:48
KICAD_MANAGER_FRAME * m_frame
Definition: import_proj.h:45
wxFileName m_pro
Definition: import_proj.h:50
wxFileName m_sch
Definition: import_proj.h:46
const std::string ProjectFileExtension

References m_pcb, m_pro, m_sch, and ProjectFileExtension.

Member Function Documentation

◆ AssociateFilesWithProj()

void IMPORT_PROJ_HELPER::AssociateFilesWithProj ( int  aImportedSchFileType,
int  aImportedPcbFileType 
)

Converts imported files to kicad type files.

Types of imported files are needed for conversion

Parameters
aImportedSchFileTypetype of the imported schematic
aImportedPcbFileTypetype of the imported PCB

Definition at line 202 of file import_proj.cpp.

204{
205 AssociateFileWithProj( SCHEMATIC_T, aImportedSchFileType );
206 AssociateFileWithProj( PCB_T, aImportedPcbFileType );
207}
void AssociateFileWithProj(KICAD_T aKicad_T, int aImportedFileType)
@ PCB_T
Definition: typeinfo.h:82
@ SCHEMATIC_T
Definition: typeinfo.h:188

References AssociateFileWithProj(), PCB_T, and SCHEMATIC_T.

Referenced by KICAD_MANAGER_CONTROL::ImportNonKicadProj(), and KICAD_MANAGER_FRAME::ImportNonKiCadProject().

◆ AssociateFileWithProj()

void IMPORT_PROJ_HELPER::AssociateFileWithProj ( KICAD_T  aKicad_T,
int  aImportedFileType 
)
private

Definition at line 158 of file import_proj.cpp.

159{
160 wxFileName fileCopy, importedFile;
161 FRAME_T frame_type;
162 switch( aFT )
163 {
164 case SCHEMATIC_T:
165 importedFile = m_sch;
166 fileCopy = m_shCopy;
167 frame_type = FRAME_SCH;
168 break;
169
170 case PCB_T:
171 importedFile = m_pcb;
172 fileCopy = m_pcbCopy;
173 frame_type = FRAME_PCB_EDITOR;
174 break;
175
176 default: return;
177 }
178
179 if( fileCopy.FileExists() )
180 {
181 KIWAY_PLAYER* frame = m_frame->Kiway().Player( frame_type, true );
182
183 std::string packet =
184 StrPrintf( "%d\n%s", aImportedFileType, TO_UTF8( fileCopy.GetFullPath() ) );
185 frame->Kiway().ExpressMail( frame_type, MAIL_IMPORT_FILE, packet, m_frame );
186
187 if( !frame->IsShown() )
188 frame->Show( true );
189
190 // On Windows, Raise() does not bring the window on screen, when iconized
191 if( frame->IsIconized() )
192 frame->Iconize( false );
193
194 frame->Raise();
195
196 if( !fileCopy.SameAs( importedFile ) ) // Do not delete the original file!
197 wxRemoveFile( fileCopy.GetFullPath() );
198 }
199}
wxFileName m_shCopy
Definition: import_proj.h:47
wxFileName m_pcbCopy
Definition: import_proj.h:49
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:394
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:491
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
@ FRAME_PCB_EDITOR
Definition: frame_type.h:40
@ FRAME_SCH
Definition: frame_type.h:34
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
@ MAIL_IMPORT_FILE
Definition: mail_type.h:48
int StrPrintf(std::string *result, const char *format,...)
This is like sprintf() but the output is appended to a std::string instead of to a character array.
Definition: richio.cpp:84

References KIWAY::ExpressMail(), FRAME_PCB_EDITOR, FRAME_SCH, KIWAY_HOLDER::Kiway(), m_frame, m_pcb, m_pcbCopy, m_sch, m_shCopy, MAIL_IMPORT_FILE, PCB_T, KIWAY::Player(), SCHEMATIC_T, StrPrintf(), and TO_UTF8.

Referenced by AssociateFilesWithProj().

◆ CopyImportedFile()

bool IMPORT_PROJ_HELPER::CopyImportedFile ( KICAD_T  aKicad_T,
bool  displayError = true 
)
private

Definition at line 100 of file import_proj.cpp.

101{
102 wxASSERT( m_pro.GetExt() == ProjectFileExtension );
103
104 wxFileName fileCopy( m_pro );
105
106 wxFileName src, dest;
107 switch( aFT )
108 {
109 case SCHEMATIC_T: src = m_sch; break;
110
111 case PCB_T: src = m_pcb; break;
112
113 default: break;
114 }
115
116 fileCopy.SetExt( src.GetExt() );
117
118 if( src.Exists() && !fileCopy.SameAs( src ) )
119 {
120 if( !wxCopyFile( src.GetFullPath(), fileCopy.GetFullPath(), true ) )
121 {
122 if( displayError )
123 OutputCopyError( src, fileCopy );
124 return false;
125 }
126 }
127
128 switch( aFT )
129 {
130 case SCHEMATIC_T: m_shCopy = fileCopy; break;
131
132 case PCB_T: m_pcbCopy = fileCopy; break;
133
134 default: break;
135 }
136
137 return true;
138}
void OutputCopyError(const wxFileName &aSrc, const wxFileName &aFileCopy)

References m_pcb, m_pcbCopy, m_pro, m_sch, m_shCopy, OutputCopyError(), PCB_T, ProjectFileExtension, and SCHEMATIC_T.

Referenced by CopyImportedFiles().

◆ CopyImportedFiles()

bool IMPORT_PROJ_HELPER::CopyImportedFiles ( bool  displayError = true)

Copies project files to the destination directory.

Parameters
displayErrorcalls OutputCopyError() if true

Definition at line 140 of file import_proj.cpp.

141{
142 return CopyImportedFile( SCHEMATIC_T, displayError ) && CopyImportedFile( PCB_T, displayError );
143}
bool CopyImportedFile(KICAD_T aKicad_T, bool displayError=true)

References CopyImportedFile(), PCB_T, and SCHEMATIC_T.

Referenced by KICAD_MANAGER_CONTROL::ImportNonKicadProj(), and KICAD_MANAGER_FRAME::ImportNonKiCadProject().

◆ CreateEmptyDirForProject()

void IMPORT_PROJ_HELPER::CreateEmptyDirForProject ( )

Appends a new directory with the name of the project file Keep iterating until an empty directory is found.

Definition at line 74 of file import_proj.cpp.

75{
76 // Append a new directory with the same name of the project file
77 // Keep iterating until we find an empty directory
78 wxString newDir = m_pro.GetName();
79 int attempt = 0;
80
81 m_pro.AppendDir( newDir );
82
83 while( m_pro.DirExists() )
84 {
85 m_pro.RemoveLastDir();
86 wxString suffix = wxString::Format( "_%d", ++attempt );
87 m_pro.AppendDir( newDir + suffix );
88 }
89}
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format(), and m_pro.

Referenced by KICAD_MANAGER_CONTROL::ImportNonKicadProj(), and KICAD_MANAGER_FRAME::ImportNonKiCadProject().

◆ GetProj()

const wxFileName & IMPORT_PROJ_HELPER::GetProj ( )

Definition at line 44 of file import_proj.cpp.

45{
46 return m_pro;
47}

References m_pro.

Referenced by KICAD_MANAGER_CONTROL::ImportNonKicadProj(), and KICAD_MANAGER_FRAME::ImportNonKiCadProject().

◆ GetProjFullPath()

wxString IMPORT_PROJ_HELPER::GetProjFullPath ( )

Definition at line 62 of file import_proj.cpp.

63{
64 return m_pro.GetFullPath();
65}

References m_pro.

Referenced by KICAD_MANAGER_CONTROL::ImportNonKicadProj(), and KICAD_MANAGER_FRAME::ImportNonKiCadProject().

◆ GetProjName()

wxString IMPORT_PROJ_HELPER::GetProjName ( )

Definition at line 68 of file import_proj.cpp.

69{
70 return m_pro.GetName();
71}

References m_pro.

◆ GetProjPath()

wxString IMPORT_PROJ_HELPER::GetProjPath ( )

Definition at line 50 of file import_proj.cpp.

51{
52 return m_pro.GetPath();
53}

References m_pro.

Referenced by KICAD_MANAGER_CONTROL::ImportNonKicadProj(), and KICAD_MANAGER_FRAME::ImportNonKiCadProject().

◆ OutputCopyError()

void IMPORT_PROJ_HELPER::OutputCopyError ( const wxFileName &  aSrc,
const wxFileName &  aFileCopy 
)
private

Definition at line 145 of file import_proj.cpp.

146{
147 wxString msg;
148 msg.Printf( _( "Cannot copy file '%s'\n"
149 "to '%s'\n"
150 "The project cannot be imported." ),
151 aSrc.GetFullPath(), aFileCopy.GetFullPath() );
152
153 wxMessageDialog fileCopyErrorDlg( m_frame, msg, _( "Error" ), wxOK_DEFAULT | wxICON_ERROR );
154 fileCopyErrorDlg.ShowModal();
155}
#define _(s)

References _, and m_frame.

Referenced by CopyImportedFile().

◆ SetProjAbsolutePath()

void IMPORT_PROJ_HELPER::SetProjAbsolutePath ( )

Definition at line 92 of file import_proj.cpp.

93{
95 if( !m_pro.IsAbsolute() )
96 m_pro.MakeAbsolute();
97}

References m_pro, and ProjectFileExtension.

Referenced by KICAD_MANAGER_CONTROL::ImportNonKicadProj(), and KICAD_MANAGER_FRAME::ImportNonKiCadProject().

◆ SetProjPath()

void IMPORT_PROJ_HELPER::SetProjPath ( const wxString  aPath)

Definition at line 56 of file import_proj.cpp.

57{
58 m_pro.SetPath( aPath );
59}

References m_pro.

Referenced by KICAD_MANAGER_FRAME::ImportNonKiCadProject().

Member Data Documentation

◆ m_frame

KICAD_MANAGER_FRAME* IMPORT_PROJ_HELPER::m_frame
private

Definition at line 45 of file import_proj.h.

Referenced by AssociateFileWithProj(), and OutputCopyError().

◆ m_pcb

wxFileName IMPORT_PROJ_HELPER::m_pcb
private

Definition at line 48 of file import_proj.h.

Referenced by AssociateFileWithProj(), CopyImportedFile(), and IMPORT_PROJ_HELPER().

◆ m_pcbCopy

wxFileName IMPORT_PROJ_HELPER::m_pcbCopy
private

Definition at line 49 of file import_proj.h.

Referenced by AssociateFileWithProj(), and CopyImportedFile().

◆ m_pro

wxFileName IMPORT_PROJ_HELPER::m_pro
private

◆ m_sch

wxFileName IMPORT_PROJ_HELPER::m_sch
private

Definition at line 46 of file import_proj.h.

Referenced by AssociateFileWithProj(), CopyImportedFile(), and IMPORT_PROJ_HELPER().

◆ m_shCopy

wxFileName IMPORT_PROJ_HELPER::m_shCopy
private

Definition at line 47 of file import_proj.h.

Referenced by AssociateFileWithProj(), and CopyImportedFile().


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