|
hipp
1.0
|
00001 /* 00002 Copyright 2011 Certec, Lund University, Sweden 00003 00004 This file is part of HIPP. 00005 00006 HIPP is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 HIPP is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with HIPP. If not, see <http://www.gnu.org/licenses/>. 00018 00019 */ 00020 00038 #ifndef HIPPAPP_H_ 00039 #define HIPPAPP_H_ 00040 00041 #include <wx/wx.h> 00042 #include <wx/app.h> 00043 #include <wx/docview.h> 00044 #include <H3D/X3DSAX2Handlers.h> 00045 #include <H3D/MagneticSurface.h> 00046 #include <H3D/SFString.h> 00047 #include <wx/cmdline.h> 00048 #include <wx/intl.h> 00049 #include <wx/translation.h> 00050 #include <wx/wfstream.h> 00051 00052 #include "HippFrame.h" 00053 00054 using namespace std; 00055 using namespace H3D; 00056 using H3D::AutoUpdate; 00057 00058 namespace hipp { 00059 inline string toStr(const wxString &s) { 00060 # if(wxUSE_UNICODE) 00061 char *b = new char[s.size()+1]; 00062 const wchar_t *wb = s.c_str(); 00063 for( unsigned int i = 0; i < s.size(); i++ ) { 00064 b[i] = (char)(wb[i]); 00065 } 00066 00067 b[s.size()] = '\0'; 00068 string sb(b); 00069 delete[] b; 00070 return sb; 00071 #else 00072 return string(s.c_str()); 00073 #endif 00074 } 00075 00076 H3D_API_EXCEPTION( QuitAPIException ); 00077 00078 class QuitAPIField: public AutoUpdate<SFString> { 00079 virtual void update() { 00080 string s = static_cast<SFString *> (routes_in[0])->getValue(); 00081 if (s[0] == 27) { 00082 throw QuitAPIException(); 00083 } 00084 } 00085 }; 00086 00087 const wxCmdLineEntryDesc gCmdLineDesc[] = { { wxCMD_LINE_PARAM, NULL, NULL, 00088 _("File to load"), wxCMD_LINE_VAL_STRING, 00089 wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_NONE, NULL, NULL, NULL, 00090 wxCMD_LINE_VAL_NONE, 0 } }; 00091 00092 00104 class HippApp: public wxApp { 00105 public: 00106 HippApp(); 00107 virtual ~HippApp(); 00108 00110 virtual bool OnInit(); 00112 virtual int OnExit(); 00113 virtual void OnIdle(wxIdleEvent& event); 00114 virtual bool OnExceptionInMainLoop(); 00115 virtual void OnInitCmdLine(wxCmdLineParser& parser) { 00116 parser.SetDesc(gCmdLineDesc); 00117 } 00118 00119 virtual bool OnCmdLineParsed(wxCmdLineParser& parser) { 00120 for (int i = 0; i < (int) parser.GetParamCount(); i++) { 00121 cmd_line_filename = parser.GetParam(i); 00122 } 00123 00124 return true; 00125 } 00126 00127 wxLocale m_locale; 00128 00129 static wxString GetHippRoot(){ 00130 #ifdef _DEBUG 00131 wxString hipp_root("../hipp/"); 00132 return hipp_root; 00133 #endif 00134 #ifndef _DEBUG 00135 wxString key_path = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\hipp.exe"; 00136 wxRegKey key(wxRegKey::HKLM, key_path); 00137 if( key.Exists() ){ 00138 wxString hipp_root; 00139 wxString value_lookup = "Root"; 00140 if(key.QueryValue(value_lookup, hipp_root)) 00141 return hipp_root; 00142 else 00143 wxLogError(_("Could not find the \"%s\" value in the Windows Registry key \"%s\"."), value_lookup, key_path); 00144 }else{ 00145 wxLogError(_("Could not find the \"%s\" key in the Windows Registry."), key_path); 00146 } 00147 #endif 00148 return wxString(); 00149 } 00150 00151 static wxString GetLanguagePath(){ 00152 #ifdef _DEBUG 00153 wxString hipp_root("../languages"); 00154 return hipp_root; 00155 #endif 00156 #ifndef _DEBUG 00157 wxString key_path = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\hipp.exe"; 00158 wxRegKey key(wxRegKey::HKLM, key_path); 00159 if( key.Exists() ){ 00160 wxString langs_root; 00161 wxString value_lookup = "LangsRoot"; 00162 if(key.QueryValue(value_lookup, langs_root)) 00163 return langs_root; 00164 else 00165 wxLogError(_("Could not find the \"%s\" value in the Windows Registry key \"%s\"."), value_lookup, key_path); 00166 }else{ 00167 wxLogError(_("Could not find the \"%s\" key in the Windows Registry."), key_path); 00168 } 00169 #endif 00170 return wxString(); 00171 } 00172 00173 wxFileOutputStream* GetLogStream(){ 00174 if( !logstream || !logstream->IsOk() ) 00175 logstream = new wxFileOutputStream(HippApp::GetHippRoot() + "hipp.log"); 00176 00177 return logstream; 00178 } 00179 00180 protected: 00181 wxString cmd_line_filename; 00182 HippFrame *frame; 00183 DECLARE_EVENT_TABLE() 00184 private: 00185 wxDocManager* m_docManager; 00186 wxFileOutputStream* logstream; 00187 }; 00188 wxDECLARE_APP( HippApp ); 00189 } 00190 #endif /* HIPPAPP_H_ */
1.7.5.1