KiCad PCB EDA Suite
GERBV::IFACE Struct Reference
Inheritance diagram for GERBV::IFACE:
KIFACE_I 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
 Function IfaceOrAddress 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
 Function SaveFileAs 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_I 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 45 of file gerbview.cpp.

Constructor & Destructor Documentation

◆ IFACE()

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

Definition at line 49 of file gerbview.cpp.

49  :
50  KIFACE_I( aName, aType )
51  {}
KIFACE_I(const char *aKifaceName, KIWAY::FACE_T aId)
Definition: kiface_i.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_I.

Definition at line 57 of file gerbview.cpp.

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

References FRAME_GERBER, and NULL.

◆ end_common()

void KIFACE_I::end_common ( )
protectedinherited

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

Definition at line 98 of file kiface_i.cpp.

99 {
100  m_bm.End();
101 }
BIN_MOD m_bm
Definition: kiface_i.h:118
void End()
Definition: bin_mod.cpp:53

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

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

◆ GetHelpFileName()

const wxString& KIFACE_I::GetHelpFileName ( ) const
inlineinherited

Return just the basename portion of the current help file.

Definition at line 109 of file kiface_i.h.

109 { return m_bm.m_help_file; }
BIN_MOD m_bm
Definition: kiface_i.h:118
wxString m_help_file
Definition: bin_mod.h:66

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

Referenced by EDA_BASE_FRAME::help_name().

◆ IfaceOrAddress()

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

Function IfaceOrAddress 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
void* - and must be cast into the know type.

Implements KIFACE_I.

Definition at line 83 of file gerbview.cpp.

84  {
85  return NULL;
86  }
#define NULL

References NULL.

◆ InitSettings()

void KIFACE_I::InitSettings ( APP_SETTINGS_BASE aSettings)
inlineinherited

Definition at line 94 of file kiface_i.h.

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

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

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

◆ IsSingle()

◆ KifaceSearch()

SEARCH_STACK& KIFACE_I::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_i.h.

113 { return m_bm.m_search; }
BIN_MOD m_bm
Definition: kiface_i.h:118
SEARCH_STACK m_search
Definition: bin_mod.h:68

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

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

◆ KifaceSettings()

◆ Name()

const wxString KIFACE_I::Name ( )
inlineinherited

Definition at line 87 of file kiface_i.h.

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

References KIFACE_I::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_I.

Definition at line 140 of file gerbview.cpp.

141 {
142  end_common();
143 }
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
Definition: kiface_i.cpp:98

References KIFACE_I::end_common().

◆ OnKifaceStart()

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

Typically start_common() is called from here.

Implements KIFACE_I.

Definition at line 131 of file gerbview.cpp.

132 {
135  start_common( aCtlBits );
136  return true;
137 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:167
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition: kiface_i.cpp:88
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_i.h:92
int PGM_BASE * aProgram
Definition: gerbview.cpp:112
JSON_SETTINGS * RegisterSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
void InitSettings(APP_SETTINGS_BASE *aSettings)
Definition: kiface_i.h:94

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

◆ SaveFileAs()

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

Function SaveFileAs 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 146 of file gerbview.cpp.

149 {
150  wxFileName destFile( aSrcFilePath );
151  wxString destPath = destFile.GetPathWithSep();
152  wxUniChar pathSep = wxFileName::GetPathSeparator();
153  wxString ext = destFile.GetExt();
154 
155  if( destPath.StartsWith( aProjectBasePath + pathSep ) )
156  {
157  destPath.Replace( aProjectBasePath, aNewProjectBasePath, false );
158  destFile.SetPath( destPath );
159  }
160 
161  if( ext == "gbr" || IsProtelExtension( ext ) )
162  {
163  wxString destFileName = destFile.GetName();
164 
165  if( destFileName.StartsWith( aProjectName + "-" ) )
166  {
167  destFileName.Replace( aProjectName, aNewProjectName, false );
168  destFile.SetName( destFileName );
169  }
170 
171  KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
172  }
173  else if( ext == "gbrjob" )
174  {
175  if( destFile.GetName() == aProjectName + "-job" )
176  destFile.SetName( aNewProjectName + "-job" );
177 
178  FILE_LINE_READER jobfileReader( aSrcFilePath );
179 
180  char* line;
181  wxString data;
182 
183  while( ( line = jobfileReader.ReadLine() ) )
184  data << line << '\n';
185 
186  // detect the file format: old (deprecated) gerber format or official JSON format
187  if( !data.Contains( "{" ) )
188  {
189  KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
190  return;
191  }
192 
193  bool success = false;
194 
195  try
196  {
197  // Will throw on parse error
198  json js = json::parse( TO_UTF8( data ) );
199 
200  for( auto& entry : js["FilesAttributes"] )
201  {
202  wxString path = wxString( entry["Path"].get<std::string>() );
203 
204  if( path.StartsWith( aProjectName + "-" ) )
205  {
206  path.Replace( aProjectName, aNewProjectName, false );
207  entry["Path"] = path.ToStdString();
208  }
209  }
210 
211  wxFFile destJobFile( destFile.GetFullPath(), "wb" );
212 
213  if( destJobFile.IsOpened() )
214  success = destJobFile.Write( js.dump( 0 ) );
215 
216  // wxFFile dtor will close the file
217  }
218  catch( ... )
219  {
220  success = false;
221  }
222 
223  if( !success )
224  {
225  wxString msg;
226 
227  if( !aErrors.empty() )
228  aErrors += "\n";
229 
230  msg.Printf( _( "Cannot copy file \"%s\"." ), destFile.GetFullPath() );
231  aErrors += msg;
232  }
233  }
234  else if( ext == "drl" )
235  {
236  wxString destFileName = destFile.GetName();
237 
238  if( destFileName == aProjectName )
239  destFileName = aNewProjectName;
240  else if( destFileName.StartsWith( aProjectName + "-" ) )
241  destFileName.Replace( aProjectName, aNewProjectName, false );
242 
243  destFile.SetName( destFileName );
244 
245  KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors );
246  }
247  else
248  {
249  wxFAIL_MSG( "Unexpected filetype for GerbView::SaveFileAs()" );
250  }
251 }
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:363
nlohmann::json json
Definition: gerbview.cpp:40
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)
Definition: 3d_actions.cpp:33

◆ start_common()

bool KIFACE_I::start_common ( int  aCtlBits)
protectedinherited

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

Definition at line 88 of file kiface_i.cpp.

89 {
90  m_start_flags = aCtlBits;
91  m_bm.Init();
93 
94  return true;
95 }
KIWAY::FACE_T m_id
Definition: kiface_i.h:116
void Init()
Definition: bin_mod.cpp:41
BIN_MOD m_bm
Definition: kiface_i.h:118
int m_start_flags
flags provided in OnKifaceStart()
Definition: kiface_i.h:120
SEARCH_STACK m_search
Definition: bin_mod.h:68
static void setSearchPaths(SEARCH_STACK *aDst, KIWAY::FACE_T aId)
Initialize aDst SEARCH_STACK with KIFACE (DSO) specific settings.
Definition: kiface_i.cpp:37

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

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

◆ StartFlags()

int KIFACE_I::StartFlags ( ) const
inlineinherited

Return whatever was passed as aCtlBits to OnKifaceStart().

Definition at line 99 of file kiface_i.h.

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

References KIFACE_I::m_start_flags.


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