KiCad PCB EDA Suite
GERBV::IFACE Struct Reference
Inheritance diagram for GERBV::IFACE:
KIFACE_BASE KIFACE

Public Member Functions

 IFACE (const char *aName, KIWAY::FACE_T aType)
 
bool OnKifaceStart (PGM_BASE *aProgram, int aCtlBits) override
 Typically start_common() is called from here. More...
 
void OnKifaceEnd () override
 Called just once just before the DSO is to be unloaded. More...
 
wxWindow * CreateWindow (wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
 Create a wxWindow for the current project. More...
 
void * IfaceOrAddress (int aDataId) override
 Return a pointer to the requested object. More...
 
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 know the internal format of the various files (which may have paths in them that need updating). More...
 
const wxString Name ()
 
APP_SETTINGS_BASEKifaceSettings () const
 
void InitSettings (APP_SETTINGS_BASE *aSettings)
 
int StartFlags () const
 Return whatever was passed as aCtlBits to OnKifaceStart(). More...
 
bool IsSingle () const
 Is this KIFACE running under single_top? More...
 
const wxString & GetHelpFileName () const
 Return just the basename portion of the current help file. More...
 
SEARCH_STACKKifaceSearch ()
 Only for DSO specific 'non-library' files. More...
 

Protected Member Functions

bool start_common (int aCtlBits)
 Common things to do for a top program module, during OnKifaceStart(). More...
 
void end_common ()
 Common things to do for a top program module, during OnKifaceEnd();. More...
 

Detailed Description

Definition at line 46 of file gerbview.cpp.

Constructor & Destructor Documentation

◆ IFACE()

GERBV::IFACE::IFACE ( const char *  aName,
KIWAY::FACE_T  aType 
)
inline

Definition at line 50 of file gerbview.cpp.

50  :
51  KIFACE_BASE( aName, aType )
52  {}
KIFACE_BASE(const char *aKifaceName, KIWAY::FACE_T aId)
Definition: kiface_base.h:64

Member Function Documentation

◆ CreateWindow()

wxWindow* GERBV::IFACE::CreateWindow ( wxWindow *  aParent,
int  aClassId,
KIWAY aKIWAY,
int  aCtlBits = 0 
)
inlineoverridevirtual

Create a wxWindow for the current project.

The caller must cast the return value into the known type.

Parameters
aParentmay be NULL or is otherwise the parent to connect under. If NULL then caller may want to connect the returned wxWindow into some hierarchy after this function returns.
aClassIdidentifies which wxFrame or wxDialog to retrieve, using a value known to the implementing KIFACE.
aKIWAYtells the window which KIWAY (and PROJECT) it is a participant in.
aCtlBitsconsists of bit flags from the set of KFCTL_* #defines above.
Returns
the window created and if not NULL, should be cast into the known type using and old school cast. dynamic_cast is problematic since it needs typeinfo probably not contained in the caller's link image.

Implements KIFACE_BASE.

Definition at line 58 of file gerbview.cpp.

60  {
61  switch( aClassId )
62  {
63  case FRAME_GERBER:
64  {
65  GERBVIEW_FRAME* frame = new GERBVIEW_FRAME( aKiway, aParent );
66  return frame;
67  }
68  break;
69 
70  default:
71  ;
72  }
73 
74  return nullptr;
75  }

References FRAME_GERBER.

◆ end_common()

void KIFACE_BASE::end_common ( )
protectedinherited

Common things to do for a top program module, during OnKifaceEnd();.

Definition at line 107 of file kiface_base.cpp.

108 {
109  m_bm.End();
110 }
BIN_MOD m_bm
Definition: kiface_base.h:118
void End()
Definition: bin_mod.cpp:50

References BIN_MOD::End(), and KIFACE_BASE::m_bm.

Referenced by PCBCALC::IFACE::OnKifaceEnd(), KIFACE_BASE::OnKifaceEnd(), CV::IFACE::OnKifaceEnd(), PGE::IFACE::OnKifaceEnd(), OnKifaceEnd(), PCB::IFACE::OnKifaceEnd(), and SCH::IFACE::OnKifaceEnd().

◆ GetHelpFileName()

const wxString& KIFACE_BASE::GetHelpFileName ( ) const
inlineinherited

Return just the basename portion of the current help file.

Definition at line 109 of file kiface_base.h.

109 { return m_bm.m_help_file; }
BIN_MOD m_bm
Definition: kiface_base.h:118
wxString m_help_file
Definition: bin_mod.h:58

References KIFACE_BASE::m_bm, and BIN_MOD::m_help_file.

Referenced by EDA_BASE_FRAME::help_name().

◆ IfaceOrAddress()

void* GERBV::IFACE::IfaceOrAddress ( int  aDataId)
inlineoverridevirtual

Return a pointer to the requested object.

The safest way to use this is to retrieve a pointer to a static instance of an interface, similar to how the KIFACE interface is exported. But if you know what you are doing use it to retrieve anything you want.

Parameters
aDataIdidentifies which object you want the address of.
Returns
the object requested and must be cast into the know type.

Implements KIFACE_BASE.

Definition at line 87 of file gerbview.cpp.

88  {
89  return nullptr;
90  }

◆ InitSettings()

void KIFACE_BASE::InitSettings ( APP_SETTINGS_BASE aSettings)
inlineinherited

Definition at line 94 of file kiface_base.h.

94 { m_bm.InitSettings( aSettings ); }
BIN_MOD m_bm
Definition: kiface_base.h:118
void InitSettings(APP_SETTINGS_BASE *aPtr)
Takes ownership of a new application settings object.
Definition: bin_mod.h:53

References BIN_MOD::InitSettings(), and KIFACE_BASE::m_bm.

Referenced by BMP2CMP::IFACE::CreateWindow(), PCBCALC::IFACE::OnKifaceStart(), CV::IFACE::OnKifaceStart(), PGE::IFACE::OnKifaceStart(), OnKifaceStart(), PCB::IFACE::OnKifaceStart(), and SCH::IFACE::OnKifaceStart().

◆ IsSingle()

◆ KifaceSearch()

SEARCH_STACK& KIFACE_BASE::KifaceSearch ( )
inlineinherited

Only for DSO specific 'non-library' files.

(The library search path is in the PROJECT class.)

Definition at line 113 of file kiface_base.h.

113 { return m_bm.m_search; }
BIN_MOD m_bm
Definition: kiface_base.h:118
SEARCH_STACK m_search
Definition: bin_mod.h:60

References KIFACE_BASE::m_bm, and BIN_MOD::m_search.

Referenced by CVPCB_MAINFRAME::buildEquivalenceList(), DS_DATA_MODEL::ResolvePath(), and EDA_BASE_FRAME::sys_search().

◆ KifaceSettings()

◆ Name()

const wxString KIFACE_BASE::Name ( )
inlineinherited

Definition at line 87 of file kiface_base.h.

88  {
89  return wxString::FromUTF8( m_bm.m_name );
90  }
BIN_MOD m_bm
Definition: kiface_base.h:118
const char * m_name
name of this binary module, static C string.
Definition: bin_mod.h:55

References KIFACE_BASE::m_bm, and BIN_MOD::m_name.

◆ OnKifaceEnd()

void IFACE::OnKifaceEnd ( )
overridevirtual

Called just once just before the DSO is to be unloaded.

It is called before static C++ destructors are called. A default implementation is supplied.

Reimplemented from KIFACE_BASE.

Definition at line 147 of file gerbview.cpp.

148 {
149  end_common();
150 }
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.

References KIFACE_BASE::end_common().

◆ OnKifaceStart()

bool IFACE::OnKifaceStart ( PGM_BASE aProgram,
int  aCtlBits 
)
overridevirtual

Typically start_common() is called from here.

Implements KIFACE_BASE.

Definition at line 138 of file gerbview.cpp.

139 {
142  start_common( aCtlBits );
143  return true;
144 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:129
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
int PGM_BASE * aProgram
Definition: gerbview.cpp:118
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition: kiface_base.h:94
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition: kiface_base.cpp:97
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:92

References aProgram, PGM_BASE::GetSettingsManager(), KIFACE_BASE::InitSettings(), KIFACE_BASE::KifaceSettings(), SETTINGS_MANAGER::RegisterSettings(), and KIFACE_BASE::start_common().

◆ SaveFileAs()

void IFACE::SaveFileAs ( const wxString &  aProjectBasePath,
const wxString &  aProjectName,
const wxString &  aNewProjectBasePath,
const wxString &  aNewProjectName,
const wxString &  aSrcFilePath,
wxString &  aErrors 
)
overridevirtual

Saving a file under a different name is delegated to the various KIFACEs because the project doesn't know the internal format of the various files (which may have paths in them that need updating).

Reimplemented from KIFACE.

Definition at line 153 of file gerbview.cpp.

156 {
157  wxFileName destFile( aSrcFilePath );
158  wxString destPath = destFile.GetPathWithSep();
159  wxUniChar pathSep = wxFileName::GetPathSeparator();
160  wxString ext = destFile.GetExt();
161 
162  if( destPath.StartsWith( aProjectBasePath + pathSep ) )
163  {
164  destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
165  destFile.SetPath( destPath );
166  }
167 
168  if( ext == wxT( "gbr" ) || IsProtelExtension( ext ) )
169  {
170  wxString destFileName = destFile.GetName();
171 
172  if( destFileName.StartsWith( aProjectName + "-" ) )
173  {
174  destFileName.Replace( aProjectName, aNewProjectName, false );
175  destFile.SetName( destFileName );
176  }
177 
178  KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
179  }
180  else if( ext == wxT( "gbrjob" ) )
181  {
182  if( destFile.GetName() == aProjectName + wxT( "-job" ) )
183  destFile.SetName( aNewProjectName + wxT( "-job" ) );
184 
185  FILE_LINE_READER jobfileReader( aSrcFilePath );
186 
187  char* line;
188  wxString data;
189 
190  while( ( line = jobfileReader.ReadLine() ) )
191  data << line << '\n';
192 
193  // detect the file format: old (deprecated) gerber format or official JSON format
194  if( !data.Contains( wxT( "{" ) ) )
195  {
196  KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
197  return;
198  }
199 
200  bool success = false;
201 
202  try
203  {
204  // Will throw on parse error
205  json js = json::parse( TO_UTF8( data ) );
206 
207  for( auto& entry : js["FilesAttributes"] )
208  {
209  wxString path = wxString( entry["Path"].get<std::string>() );
210 
211  if( path.StartsWith( aProjectName + wxT( "-" ) ) )
212  {
213  path.Replace( aProjectName, aNewProjectName, false );
214  entry["Path"] = path.ToStdString();
215  }
216  }
217 
218  wxFFile destJobFile( destFile.GetFullPath(), wxT( "wb" ) );
219 
220  if( destJobFile.IsOpened() )
221  success = destJobFile.Write( js.dump( 0 ) );
222 
223  // wxFFile dtor will close the file
224  }
225  catch( ... )
226  {
227  success = false;
228  }
229 
230  if( !success )
231  {
232  wxString msg;
233 
234  if( !aErrors.empty() )
235  aErrors += wxT( "\n" );
236 
237  msg.Printf( _( "Cannot copy file '%s'." ), destFile.GetFullPath() );
238  aErrors += msg;
239  }
240  }
241  else if( ext == wxT( "drl" ) )
242  {
243  wxString destFileName = destFile.GetName();
244 
245  if( destFileName == aProjectName )
246  destFileName = aNewProjectName;
247  else if( destFileName.StartsWith( aProjectName + wxT( "-" ) ) )
248  destFileName.Replace( aProjectName, aNewProjectName, false );
249 
250  destFile.SetName( destFileName );
251 
252  KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
253  }
254  else
255  {
256  wxFAIL_MSG( wxT( "Unexpected filetype for GerbView::SaveFileAs()" ) );
257  }
258 }
bool parse(std::istream &aStream, bool aVerbose)
Parse a PCB or footprint file from the given input stream.
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition: gestfich.cpp:214
nlohmann::json json
Definition: gerbview.cpp:41
bool IsProtelExtension(const wxString &ext)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
A LINE_READER that reads from an open file.
Definition: richio.h:172
#define _(s)

◆ start_common()

bool KIFACE_BASE::start_common ( int  aCtlBits)
protectedinherited

Common things to do for a top program module, during OnKifaceStart().

Definition at line 97 of file kiface_base.cpp.

98 {
99  m_start_flags = aCtlBits;
100  m_bm.Init();
102 
103  return true;
104 }
BIN_MOD m_bm
Definition: kiface_base.h:118
void Init()
Definition: bin_mod.cpp:38
static void setSearchPaths(SEARCH_STACK *aDst, KIWAY::FACE_T aId)
Initialize aDst SEARCH_STACK with KIFACE (DSO) specific settings.
Definition: kiface_base.cpp:33
int m_start_flags
flags provided in OnKifaceStart()
Definition: kiface_base.h:120
SEARCH_STACK m_search
Definition: bin_mod.h:60
KIWAY::FACE_T m_id
Definition: kiface_base.h:116

References BIN_MOD::Init(), KIFACE_BASE::m_bm, KIFACE_BASE::m_id, BIN_MOD::m_search, KIFACE_BASE::m_start_flags, and setSearchPaths().

Referenced by BMP2CMP::IFACE::OnKifaceStart(), PCBCALC::IFACE::OnKifaceStart(), IFACE::OnKifaceStart(), CV::IFACE::OnKifaceStart(), PGE::IFACE::OnKifaceStart(), OnKifaceStart(), PCB::IFACE::OnKifaceStart(), and SCH::IFACE::OnKifaceStart().

◆ StartFlags()

int KIFACE_BASE::StartFlags ( ) const
inlineinherited

Return whatever was passed as aCtlBits to OnKifaceStart().

Definition at line 99 of file kiface_base.h.

99 { return m_start_flags; }
int m_start_flags
flags provided in OnKifaceStart()
Definition: kiface_base.h:120

References KIFACE_BASE::m_start_flags.


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