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
 Function OnKifaceStart is called just once shortly after the DSO is loaded. More...
 
void OnKifaceEnd () override
 Function OnKifaceEnd is called just once just before the DSO is to be unloaded. More...
 
wxWindow * CreateWindow (wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
 Function CreateWindow creates 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
 Function StartFlags returns whatever was passed as aCtlBits to OnKifaceStart() More...
 
bool IsSingle () const
 Function IsSingle is this KIFACE_I running under single_top? More...
 
const wxString & GetHelpFileName () const
 Function GetHelpFileName returns 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 56 of file gerbview.cpp.

Constructor & Destructor Documentation

◆ IFACE()

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

Definition at line 60 of file gerbview.cpp.

60  :
61  KIFACE_I( aName, aType )
62  {}
KIFACE_I(const char *aKifaceName, KIWAY::FACE_T aId)
Constructor.
Definition: kiface_i.h:78

Member Function Documentation

◆ CreateWindow()

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

Function CreateWindow creates 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
wxWindow* - 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 68 of file gerbview.cpp.

69  {
70  switch( aClassId )
71  {
72  case FRAME_GERBER:
73  {
74  GERBVIEW_FRAME* frame = new GERBVIEW_FRAME( aKiway, aParent );
75  return frame;
76  }
77  break;
78 
79  default:
80  ;
81  }
82 
83  return NULL;
84  }
#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 99 of file kiface_i.cpp.

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

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

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

◆ GetHelpFileName()

const wxString& KIFACE_I::GetHelpFileName ( ) const
inlineinherited

Function GetHelpFileName returns just the basename portion of the current help file.

Definition at line 123 of file kiface_i.h.

123 { return m_bm.m_help_file; }
BIN_MOD m_bm
Definition: kiface_i.h:132
wxString m_help_file
Definition: bin_mod.h:65

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 94 of file gerbview.cpp.

95  {
96  return NULL;
97  }
#define NULL

References NULL.

◆ InitSettings()

void KIFACE_I::InitSettings ( APP_SETTINGS_BASE aSettings)
inlineinherited

Definition at line 105 of file kiface_i.h.

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

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

Referenced by BMP2CMP::IFACE::CreateWindow(), CV::IFACE::OnKifaceStart(), PGE::IFACE::OnKifaceStart(), PCBCALC::IFACE::OnKifaceStart(), OnKifaceStart(), SCH::IFACE::OnKifaceStart(), and PCB::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 127 of file kiface_i.h.

127 { return m_bm.m_search; }
BIN_MOD m_bm
Definition: kiface_i.h:132
SEARCH_STACK m_search
Definition: bin_mod.h:67

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

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

◆ KifaceSettings()

◆ Name()

const wxString KIFACE_I::Name ( )
inlineinherited

Definition at line 101 of file kiface_i.h.

101 { return wxString::FromUTF8( m_bm.m_name ); }
BIN_MOD m_bm
Definition: kiface_i.h:132
const char * m_name
name of this binary module, static C string.
Definition: bin_mod.h:62

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

◆ OnKifaceEnd()

void IFACE::OnKifaceEnd ( )
overridevirtual

Function OnKifaceEnd is 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.

Implements KIFACE.

Definition at line 145 of file gerbview.cpp.

146 {
147  end_common();
148 }
void end_common()
Common things to do for a top program module, during OnKifaceEnd();.
Definition: kiface_i.cpp:99

References KIFACE_I::end_common().

◆ OnKifaceStart()

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

Function OnKifaceStart is called just once shortly after the DSO is loaded.

It is the second function called, immediately after the KIFACE_GETTER(). However before either of those, static C++ constructors are called. The DSO implementation should do process level initialization here, not project specific since there will be multiple projects open eventually.

Parameters
aProgramis the process block: PGM_BASE*
aCtlBitsconsists of bit flags from the set of KFCTL_* #defines above.
Returns
bool - true if DSO initialized OK, false if not. When returning false, the loader may optionally decide to terminate the process or not, but will not put out any UI because that is the duty of this function to say why it is returning false. Never return false without having reported to the UI why.

Implements KIFACE_I.

Definition at line 136 of file gerbview.cpp.

137 {
140  start_common( aCtlBits );
141  return true;
142 }
bool start_common(int aCtlBits)
Common things to do for a top program module, during OnKifaceStart().
Definition: kiface_i.cpp:89
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_i.h:103
int PGM_BASE * aProgram
Definition: gerbview.cpp:123
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:105

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 
)
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).

Definition at line 151 of file gerbview.cpp.

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

◆ start_common()

bool KIFACE_I::start_common ( int  aCtlBits)
protectedinherited

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

Definition at line 89 of file kiface_i.cpp.

90 {
91  m_start_flags = aCtlBits;
92  m_bm.Init();
94 
95  return true;
96 }
KIWAY::FACE_T m_id
Definition: kiface_i.h:130
void Init()
Definition: bin_mod.cpp:41
BIN_MOD m_bm
Definition: kiface_i.h:132
int m_start_flags
flags provided in OnKifaceStart()
Definition: kiface_i.h:134
SEARCH_STACK m_search
Definition: bin_mod.h:67
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(), IFACE::OnKifaceStart(), CV::IFACE::OnKifaceStart(), PGE::IFACE::OnKifaceStart(), PCBCALC::IFACE::OnKifaceStart(), OnKifaceStart(), SCH::IFACE::OnKifaceStart(), and PCB::IFACE::OnKifaceStart().

◆ StartFlags()

int KIFACE_I::StartFlags ( ) const
inlineinherited

Function StartFlags returns whatever was passed as aCtlBits to OnKifaceStart()

Definition at line 111 of file kiface_i.h.

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

References KIFACE_I::m_start_flags.


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