NIREP
|
00001 00002 // Name: NIREPEditProjectFile.cxx 00003 // Purpose: 00004 // Author: 00005 // Modified by: 00006 // Created: 31/03/2010 14:46:42 00007 // RCS-ID: 00008 // Copyright: 00009 // Licence: 00011 00012 // For compilers that support precompilation, includes "wx/wx.h". 00013 #include "wx/wxprec.h" 00014 00015 #ifdef __BORLANDC__ 00016 #pragma hdrstop 00017 #endif 00018 00019 #ifndef WX_PRECOMP 00020 #include "wx/wx.h" 00021 #endif 00022 00025 00026 #include "NIREPEditProjectFile.h" 00027 #include <limits.h> 00028 #include "NIREPDisplay.h" 00029 00032 00033 00038 IMPLEMENT_CLASS( NIREPEditProjectFile, wxFrame ) 00039 00040 00041 00045 BEGIN_EVENT_TABLE( NIREPEditProjectFile, wxFrame ) 00046 00048 EVT_BUTTON( ID_RELOAD, NIREPEditProjectFile::OnReloadClick ) 00049 00050 EVT_BUTTON( ID_CANCEL, NIREPEditProjectFile::OnCancelClick ) 00051 00053 00054 END_EVENT_TABLE() 00055 00056 00061 NIREPEditProjectFile::NIREPEditProjectFile() 00062 { 00063 Init(); 00064 } 00065 00066 NIREPEditProjectFile::NIREPEditProjectFile( wxWindow* parent,DisplayDescription *dd, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) 00067 { 00068 PARENT = (NIREPDisplay*)parent; 00069 displayDescription=dd; 00070 Init(); 00071 Create( parent, id, caption, pos, size, style ); 00072 } 00073 00074 00079 bool NIREPEditProjectFile::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) 00080 { 00081 00083 wxFrame::Create( parent, id, caption, pos, size, style ); 00084 00085 CreateControls(); 00086 Centre(); 00088 return true; 00089 } 00090 00091 00096 NIREPEditProjectFile::~NIREPEditProjectFile() 00097 { 00100 } 00101 00102 00107 void NIREPEditProjectFile::Init() 00108 { 00111 } 00112 00113 00118 void NIREPEditProjectFile::CreateControls() 00119 { 00121 NIREPEditProjectFile* itemFrame1 = this; 00122 00123 wxPanel* itemPanel2 = new wxPanel( itemFrame1, ID_PANEL4, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); 00124 00125 wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(2, 1, 0, 0); 00126 itemFlexGridSizer3->AddGrowableRow(0); 00127 itemFlexGridSizer3->AddGrowableCol(0); 00128 itemPanel2->SetSizer(itemFlexGridSizer3); 00129 00130 wxFlexGridSizer* itemFlexGridSizer4 = new wxFlexGridSizer(1, 2, 0, 0); 00131 itemFlexGridSizer4->AddGrowableRow(0); 00132 itemFlexGridSizer4->AddGrowableCol(0); 00133 itemFlexGridSizer4->AddGrowableCol(1); 00134 itemFlexGridSizer3->Add(itemFlexGridSizer4, 0, wxGROW|wxGROW|wxALL, 5); 00135 00136 wxScrolledWindow* itemScrolledWindow5 = new wxScrolledWindow( itemPanel2, ID_SCROLLEDWINDOW, wxDefaultPosition, wxSize(100, 100), wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL|wxALWAYS_SHOW_SB ); 00137 itemFlexGridSizer4->Add(itemScrolledWindow5, 0, wxGROW|wxGROW|wxALL, 5); 00138 itemScrolledWindow5->SetScrollbars(1, 1, 0, 0); 00139 wxFlexGridSizer* itemFlexGridSizer6 = new wxFlexGridSizer(1, 2, 0, 0); 00140 itemScrolledWindow5->SetSizer(itemFlexGridSizer6); 00141 00142 for(std::map<std::string,std::string>::iterator i= this->displayDescription->GetVariableList()->GetVariableList()->begin();i!=this->displayDescription->GetVariableList()->GetVariableList()->end();i++) 00143 { 00144 wxStaticText* itemStaticText7 = new wxStaticText( itemScrolledWindow5, wxID_ANY, wxString(i->first.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0 ); 00145 itemFlexGridSizer6->Add(itemStaticText7, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00146 00147 wxTextCtrl* itemTextCtrl8 = new wxTextCtrl( itemScrolledWindow5, wxID_ANY, wxString(i->second.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0 ); 00148 itemFlexGridSizer6->Add(itemTextCtrl8, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00149 stringToTextCtrl.insert( pair<std::string,wxTextCtrl*>(i->first.c_str(),itemTextCtrl8) ); 00150 } 00151 00152 00153 //wxStaticText* itemStaticText9 = new wxStaticText( itemScrolledWindow5, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0 ); 00154 //itemFlexGridSizer6->Add(itemStaticText9, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00155 00156 //wxTextCtrl* itemTextCtrl10 = new wxTextCtrl( itemScrolledWindow5, ID_TEXTCTRL3, _T(""), wxDefaultPosition, wxDefaultSize, 0 ); 00157 //itemFlexGridSizer6->Add(itemTextCtrl10, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00158 00159 //wxStaticText* itemStaticText11 = new wxStaticText( itemScrolledWindow5, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0 ); 00160 //itemFlexGridSizer6->Add(itemStaticText11, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00161 00162 itemScrolledWindow5->FitInside(); 00163 00164 wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL); 00165 itemFlexGridSizer3->Add(itemBoxSizer12, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00166 00167 wxButton* itemButton13 = new wxButton( itemPanel2, ID_RELOAD, _("Reload"), wxDefaultPosition, wxDefaultSize, 0 ); 00168 itemBoxSizer12->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00169 00170 wxButton* itemButton14 = new wxButton( itemPanel2, ID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); 00171 itemBoxSizer12->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00172 00174 } 00175 00176 00181 bool NIREPEditProjectFile::ShowToolTips() 00182 { 00183 return true; 00184 } 00185 00190 wxBitmap NIREPEditProjectFile::GetBitmapResource( const wxString& name ) 00191 { 00192 // Bitmap retrieval 00194 wxUnusedVar(name); 00195 return wxNullBitmap; 00197 } 00198 00203 wxIcon NIREPEditProjectFile::GetIconResource( const wxString& name ) 00204 { 00205 // Icon retrieval 00207 wxUnusedVar(name); 00208 return wxNullIcon; 00210 } 00211 00212 00217 void NIREPEditProjectFile::OnReloadClick( wxCommandEvent& event ) 00218 { 00219 //const int LINE_MAX_NIREP = 1500; 00220 //wxFileDialog *filedialog = new wxFileDialog(this,"NIREPProjectFile Save File", wxEmptyString,wxEmptyString,wxFileSelectorDefaultWildcardStr,wxSAVE); 00221 //if( filedialog->ShowModal() == wxID_CANCEL ){ delete filedialog; return;} 00222 //wxString path = filedialog->GetPath(); 00223 //delete filedialog; 00224 //std::vector<std::string> inputLines; 00225 //char *line = new char[LINE_MAX_NIREP]; 00226 //FILE *one = fopen(this->displayDescription->GetFileName().c_str(),"r"); 00228 //while (fgets(line, LINE_MAX_NIREP, one) != NULL) { 00229 // std::string temp = line; 00230 // size_t equalSign = temp.find("="); 00231 // if(equalSign == std::string::npos ) { 00232 // inputLines.push_back(temp); 00233 // } 00234 // else { 00235 // wxString space = std::string(temp,0,equalSign).c_str(); 00236 // space.Trim(); 00237 // space.Trim(false); 00238 // inputLines.push_back( space.c_str() ); 00239 // inputLines.push_back(std::string(temp,equalSign,1) ); 00240 // inputLines.push_back(std::string(temp,equalSign+1) ); 00241 // } 00242 //} 00243 00244 //fclose(one); 00245 00246 //FILE *two = fopen(path, "w"); 00247 //for(unsigned int i=0;i<inputLines.size();i++) { 00248 // if(stringToTextCtrl.find(inputLines[i]) != stringToTextCtrl.end() ) { 00249 // std::string check = stringToTextCtrl.find(inputLines[i])->second->GetValue().c_str(); 00250 // check.append("\n"); 00251 // inputLines[i+2] = check; 00252 // 00253 // } 00254 // fprintf(two,"%s",inputLines[i].c_str()); 00255 //} 00256 //fclose(two); 00257 00258 //PARENT->GetDisplayDescription()->Read(path.c_str()); 00259 PARENT->GetDisplayDescription()->GetVariableList()->ClearList(); 00260 for(std::map<std::string,wxTextCtrl*>::iterator temp = stringToTextCtrl.begin(); temp != stringToTextCtrl.end(); temp++) { 00261 PARENT->GetDisplayDescription()->GetVariableList()->SetVariable(temp->first, std::string(temp->second->GetValue().mb_str())); 00262 } 00263 PARENT->GetDisplayDescription()->GetEvaluatorList()->ClearTaskFullName(); 00264 PARENT->UpdatePanels(); 00265 //PARENT->CreateNIREPDisplay(path.c_str()); 00266 //get the changes 00267 00268 //write the project file out to file 00269 //read the project file back in 00270 //close 00271 this->Close(true); 00273 // Before editing this code, remove the block markers. 00274 event.Skip(); 00276 } 00277 00278 00283 void NIREPEditProjectFile::OnCancelClick( wxCommandEvent& event ) 00284 { 00285 this->Close(true); 00286 } 00287