NIREP
|
00001 00002 // Name: ViewDisplayDescription.cpp 00003 // Purpose: 00004 // Author: 00005 // Modified by: 00006 // Created: 02/08/2010 16:53:38 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 00023 00024 00025 #include "ViewDisplayDescription.h" 00026 #include <sstream> 00027 #include "DisplayDescription.h" 00028 #include "wx/generic/gridctrl.h" 00029 00030 00031 00032 /* 00033 * ViewDisplayDescription type definition 00034 */ 00035 00036 IMPLEMENT_CLASS( ViewDisplayDescription, wxFrame ) 00037 00038 00039 /* 00040 * ViewDisplayDescription event table definition 00041 */ 00042 00043 BEGIN_EVENT_TABLE( ViewDisplayDescription, wxFrame ) 00044 00045 EVT_GRID_CMD_CELL_CHANGE( ID_WIDGET_COMMANDS, ViewDisplayDescription::OnWidgetCommandsCellChange ) 00046 00047 EVT_BUTTON( ID_ADD_RDL, ViewDisplayDescription::OnAddRdlClick ) 00048 00049 EVT_BUTTON( ID_REMOVE_RDL, ViewDisplayDescription::OnRemoveRdlClick ) 00050 00051 EVT_BUTTON( ID_SAVE, ViewDisplayDescription::OnSaveClick ) 00052 00053 EVT_BUTTON( wxID_CANCEL, ViewDisplayDescription::OnCancelClick ) 00054 00055 EVT_TEXT( ID_ROW, ViewDisplayDescription::OnRowTextUpdated ) 00056 00057 EVT_TEXT( ID_COLUMN, ViewDisplayDescription::OnColumnTextUpdated ) 00058 00059 EVT_MENU( ID_MENU_NEW, ViewDisplayDescription::OnMenuNewClick ) 00060 00061 EVT_MENU( ID_MENU_OPEN, ViewDisplayDescription::OnMenuOpenClick ) 00062 00063 EVT_MENU( ID_MENU_SAVE, ViewDisplayDescription::OnMenuSaveClick ) 00064 00065 EVT_MENU( wxID_EXIT, ViewDisplayDescription::OnExitClick ) 00066 00067 EVT_GRID_CMD_CELL_RIGHT_CLICK( ID_WIDGET_COMMANDS, ViewDisplayDescription::OnWidgetCommandsCellRightClick ) 00068 00069 END_EVENT_TABLE() 00070 00071 00072 /* 00073 * ViewDisplayDescription constructors 00074 */ 00075 00076 ViewDisplayDescription::ViewDisplayDescription() 00077 { 00078 Init(); 00079 } 00080 00081 ViewDisplayDescription::ViewDisplayDescription( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) 00082 { 00083 Init(); 00084 Create( parent, id, caption, pos, size, style ); 00085 } 00086 00087 00088 /* 00089 * ViewDisplayDescription creator 00090 */ 00091 00092 bool ViewDisplayDescription::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) 00093 { 00094 wxFrame::Create( parent, id, caption, pos, size, style ); 00095 00096 CreateControls(); 00097 Centre(); 00098 return true; 00099 } 00100 00101 00102 /* 00103 * ViewDisplayDescription destructor 00104 */ 00105 00106 ViewDisplayDescription::~ViewDisplayDescription() 00107 { 00108 } 00109 00110 00111 /* 00112 * Member initialisation 00113 */ 00114 00115 void ViewDisplayDescription::Init() 00116 { 00117 m_rdlList = NULL; 00118 m_variableList = NULL; 00119 m_evaluatorList = NULL; 00120 m_displayAttributesList = NULL; 00121 m_widgetCommands = NULL; 00122 m_row = NULL; 00123 m_col = NULL; 00124 } 00125 00126 00127 /* 00128 * Control creation for ViewDisplayDescription 00129 */ 00130 00131 void ViewDisplayDescription::CreateControls() 00132 { 00133 ViewDisplayDescription* itemFrame1 = this; 00134 00135 wxMenuBar* menuBar = new wxMenuBar; 00136 wxMenu* itemMenu34 = new wxMenu; 00137 itemMenu34->Append(ID_MENU_NEW, _("New"), wxEmptyString, wxITEM_NORMAL); 00138 itemMenu34->Append(ID_MENU_OPEN, _("Open"), wxEmptyString, wxITEM_NORMAL); 00139 itemMenu34->Append(ID_MENU_SAVE, _("Save"), wxEmptyString, wxITEM_NORMAL); 00140 itemMenu34->AppendSeparator(); 00141 itemMenu34->Append(wxID_EXIT, _("Exit"), wxEmptyString, wxITEM_NORMAL); 00142 menuBar->Append(itemMenu34, _("File")); 00143 00144 wxMenu* itemMenu35 = new wxMenu; 00145 itemMenu35->Append(wxID_ANY, _("View Help"), wxEmptyString, wxITEM_NORMAL); 00146 itemMenu35->Append(wxID_ANY, _("About"), wxEmptyString, wxITEM_NORMAL); 00147 menuBar->Append(itemMenu35, _("Help")); 00148 00149 itemFrame1->SetMenuBar(menuBar); 00150 00151 wxScrolledWindow* itemScrolledWindow2 = new wxScrolledWindow( itemFrame1, ID_SCROLLEDWINDOW2, wxDefaultPosition, wxSize(100, 100), wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL ); 00152 itemScrolledWindow2->SetScrollbars(1, 1, 0, 0); 00153 wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(0, 1, 0, 0); 00154 itemFlexGridSizer3->AddGrowableCol(0); 00155 itemScrolledWindow2->SetSizer(itemFlexGridSizer3); 00156 00157 wxStaticText* itemStaticText4 = new wxStaticText( itemScrolledWindow2, wxID_STATIC, _("Resource Description List"), wxDefaultPosition, wxDefaultSize, 0 ); 00158 itemFlexGridSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00159 00160 wxArrayString itemListBox5Strings; 00161 m_rdlList = new wxListBox( itemScrolledWindow2, ID_RDL_LIST, wxDefaultPosition, wxDefaultSize, itemListBox5Strings, wxLB_SINGLE ); 00162 itemFlexGridSizer3->Add(m_rdlList, 0, wxGROW|wxGROW|wxALL, 5); 00163 00164 wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL); 00165 itemFlexGridSizer3->Add(itemBoxSizer6, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00166 wxButton* itemButton7 = new wxButton( itemScrolledWindow2, ID_ADD_RDL, _("Add Resource Description List"), wxDefaultPosition, wxDefaultSize, 0 ); 00167 itemBoxSizer6->Add(itemButton7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00168 00169 wxButton* itemButton8 = new wxButton( itemScrolledWindow2, ID_REMOVE_RDL, _("Remove Resource Decription List"), wxDefaultPosition, wxDefaultSize, 0 ); 00170 itemBoxSizer6->Add(itemButton8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00171 00172 wxStaticLine* itemStaticLine9 = new wxStaticLine( itemScrolledWindow2, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); 00173 itemFlexGridSizer3->Add(itemStaticLine9, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5); 00174 00175 wxStaticText* itemStaticText10 = new wxStaticText( itemScrolledWindow2, wxID_STATIC, _("Variables"), wxDefaultPosition, wxDefaultSize, 0 ); 00176 itemFlexGridSizer3->Add(itemStaticText10, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00177 00178 00179 m_variableList = new IntelliTextCtrl( itemScrolledWindow2, ID_TEXTCTRL9, wxEmptyString, wxDefaultPosition, wxSize(-1, 200), wxTE_MULTILINE ); 00180 itemFlexGridSizer3->Add(m_variableList, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5); 00181 00182 00183 00184 00185 00186 wxStaticLine* itemStaticLine13 = new wxStaticLine( itemScrolledWindow2, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); 00187 itemFlexGridSizer3->Add(itemStaticLine13, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5); 00188 00189 wxStaticText* itemStaticText14 = new wxStaticText( itemScrolledWindow2, wxID_STATIC, _("Evaluator Commands"), wxDefaultPosition, wxDefaultSize, 0 ); 00190 itemFlexGridSizer3->Add(itemStaticText14, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00191 00192 m_evaluatorList = new IntelliTextCtrl( itemScrolledWindow2, ID_INTELLITEXTCTRL1, wxEmptyString, wxDefaultPosition, wxSize(-1, 200), wxTE_MULTILINE ); 00193 itemFlexGridSizer3->Add(m_evaluatorList, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5); 00194 std::vector<wxString> rightClickText; 00195 for(EvaluatorCmdList::iterator i= EvalCmd.begin(); i != EvalCmd.end(); i++) { 00196 rightClickText.push_back(wxString(i->second.c_str(), wxConvUTF8)); 00197 } 00198 m_evaluatorList->SetRightClickText(rightClickText); 00199 00200 wxStaticLine* itemStaticLine17 = new wxStaticLine( itemScrolledWindow2, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); 00201 itemFlexGridSizer3->Add(itemStaticLine17, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5); 00202 00203 wxBoxSizer* itemBoxSizer18 = new wxBoxSizer(wxHORIZONTAL); 00204 itemFlexGridSizer3->Add(itemBoxSizer18, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00205 wxStaticText* itemStaticText19 = new wxStaticText( itemScrolledWindow2, wxID_STATIC, _("Number Of Rows"), wxDefaultPosition, wxDefaultSize, 0 ); 00206 itemBoxSizer18->Add(itemStaticText19, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00207 00208 m_row = new wxTextCtrl( itemScrolledWindow2, ID_ROW, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); 00209 itemBoxSizer18->Add(m_row, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00210 00211 wxBoxSizer* itemBoxSizer21 = new wxBoxSizer(wxHORIZONTAL); 00212 itemFlexGridSizer3->Add(itemBoxSizer21, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00213 wxStaticText* itemStaticText22 = new wxStaticText( itemScrolledWindow2, wxID_STATIC, _("Number Of Columns"), wxDefaultPosition, wxDefaultSize, 0 ); 00214 itemBoxSizer21->Add(itemStaticText22, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00215 00216 m_col= new wxTextCtrl( itemScrolledWindow2, ID_COLUMN, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); 00217 itemBoxSizer21->Add(m_col, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00218 00219 wxStaticText* itemStaticText24 = new wxStaticText( itemScrolledWindow2, wxID_STATIC, _("Widget Commands"), wxDefaultPosition, wxDefaultSize, 0 ); 00220 itemFlexGridSizer3->Add(itemStaticText24, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00221 00222 m_widgetCommands = new wxGrid( itemScrolledWindow2, ID_WIDGET_COMMANDS, wxDefaultPosition, wxSize(200, 150), wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL ); 00223 m_widgetCommands->SetDefaultColSize(150); 00224 m_widgetCommands->SetDefaultRowSize(25); 00225 m_widgetCommands->SetColLabelSize(25); 00226 m_widgetCommands->SetRowLabelSize(50); 00227 m_widgetCommands->CreateGrid(0, 0, wxGrid::wxGridSelectCells); 00228 itemFlexGridSizer3->Add(m_widgetCommands, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5); 00229 00230 wxStaticLine* itemStaticLine26 = new wxStaticLine( itemScrolledWindow2, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); 00231 itemFlexGridSizer3->Add(itemStaticLine26, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5); 00232 00233 wxStaticText* itemStaticText27 = new wxStaticText( itemScrolledWindow2, wxID_STATIC, _("Widget Attributes"), wxDefaultPosition, wxDefaultSize, 0 ); 00234 itemFlexGridSizer3->Add(itemStaticText27, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00235 00236 m_displayAttributesList = new IntelliTextCtrl( itemScrolledWindow2, ID_TEXTCTRL12, wxEmptyString, wxDefaultPosition, wxSize(-1, 100), wxTE_MULTILINE ); 00237 itemFlexGridSizer3->Add(m_displayAttributesList, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5); 00238 wxString text = wxString(DisplayAttributeCmd.find("Rowsize")->second.c_str(), wxConvUTF8); 00239 text.Append(wxT("(")); 00240 text.Append(m_row->GetValue()); 00241 text.Append(wxT(")\n")); 00242 m_displayAttributesList->AppendText(text); 00243 00244 wxString textTwo = wxString(DisplayAttributeCmd.find("Columnsize")->second.c_str(), wxConvUTF8); 00245 textTwo.Append(wxT("(")); 00246 textTwo.Append(m_row->GetValue()); 00247 textTwo.Append(wxT(")\n")); 00248 m_displayAttributesList->AppendText(textTwo); 00249 00250 rightClickText.clear(); 00251 for(DisplayAttributeCmdList::iterator i= DisplayAttributeCmd.begin(); i != DisplayAttributeCmd.end(); i++) { 00252 rightClickText.push_back(wxString(i->second.c_str(), wxConvUTF8)); 00253 } 00254 m_displayAttributesList->SetRightClickText(rightClickText); 00255 00256 wxStaticLine* itemStaticLine29 = new wxStaticLine( itemScrolledWindow2, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); 00257 itemFlexGridSizer3->Add(itemStaticLine29, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00258 00259 wxBoxSizer* itemBoxSizer30 = new wxBoxSizer(wxHORIZONTAL); 00260 itemFlexGridSizer3->Add(itemBoxSizer30, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00261 wxButton* itemButton31 = new wxButton( itemScrolledWindow2, ID_SAVE, _("Save"), wxDefaultPosition, wxDefaultSize, 0 ); 00262 itemBoxSizer30->Add(itemButton31, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00263 00264 wxButton* itemButton32 = new wxButton( itemScrolledWindow2, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); 00265 itemBoxSizer30->Add(itemButton32, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00266 00267 this->SetDefaults(); 00268 00269 itemScrolledWindow2->FitInside(); 00270 } 00271 00272 00273 /* 00274 * Should we show tooltips? 00275 */ 00276 00277 bool ViewDisplayDescription::ShowToolTips() 00278 { 00279 return true; 00280 } 00281 00282 /* 00283 * Get bitmap resources 00284 */ 00285 00286 wxBitmap ViewDisplayDescription::GetBitmapResource( const wxString& name ) 00287 { 00288 // Bitmap retrieval 00289 wxUnusedVar(name); 00290 return wxNullBitmap; 00291 } 00292 00293 /* 00294 * Get icon resources 00295 */ 00296 00297 wxIcon ViewDisplayDescription::GetIconResource( const wxString& name ) 00298 { 00299 wxUnusedVar(name); 00300 return wxNullIcon; 00301 } 00302 00303 00304 /* 00305 * wxEVT_GRID_CMD_CELL_CHANGE event handler for ID_WIDGET_COMMANDS 00306 */ 00307 00308 void ViewDisplayDescription::OnWidgetCommandsCellChange( wxGridEvent& event ) 00309 { 00310 event.Skip(); 00311 00312 } 00313 00314 /* 00315 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ADD_RDL 00316 */ 00317 00318 void ViewDisplayDescription::OnAddRdlClick( wxCommandEvent& event ) 00319 { 00320 wxFileDialog * filedialog = new wxFileDialog(this, wxT("Choose a Resource Description List file to add to list"), wxT(""), wxT("untitled.rdl"), wxT("(*.rdl)|*.rdl|(*.*)|*.*"), 0, wxDefaultPosition, wxDefaultSize, wxT("Pick")); 00321 if( filedialog->ShowModal() == wxID_CANCEL ){ delete filedialog; return;} 00322 00323 00324 m_rdlList->Append(filedialog->GetPath()); 00325 00326 delete filedialog; 00327 } 00328 00329 00330 /* 00331 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_REMOVE_RDL 00332 */ 00333 00334 void ViewDisplayDescription::OnRemoveRdlClick( wxCommandEvent& event ) 00335 { 00336 if(m_rdlList->GetSelection() !=wxNOT_FOUND) { 00337 m_rdlList->Delete(m_rdlList->GetSelection()); 00338 } 00339 else if(m_rdlList->GetCount() != 0) { 00340 m_rdlList->Delete(m_rdlList->GetCount()-1); 00341 } 00342 } 00343 00344 /* 00345 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CREATE 00346 */ 00347 00348 void ViewDisplayDescription::OnSaveClick( wxCommandEvent& event ) 00349 { 00350 this->Save(); 00351 this->Close(); 00352 } 00353 00354 void ViewDisplayDescription::Save() 00355 { 00356 wxFileDialog * filedialog = new wxFileDialog(this, wxT("Choose a location to save the Display Description"), wxT(""), wxT("untitled.nd3"), wxT("(*.nd3)|*.nd3|(*.*)|*.*"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT, wxDefaultPosition, wxDefaultSize, wxT("Save")); 00357 if( filedialog->ShowModal() == wxID_CANCEL ){ delete filedialog; return;} 00358 00359 FILE *tempFile = fopen(filedialog->GetPath().mb_str(), "w+"); 00360 00361 fprintf(tempFile,"Begin ResourcedescriptionList\n\n"); 00362 for(int i=0; i< m_rdlList->GetCount(); i++) { 00363 fprintf(tempFile,"%s\n", m_rdlList->GetString(i)); 00364 } 00365 fprintf(tempFile,"End ResourceDescriptionList\n\n\n"); 00366 00367 fprintf(tempFile,"begin variablelist\n\n"); 00368 for(int i=0; i< m_variableList->GetNumberOfLines(); i++) { 00369 fprintf(tempFile,"%s\n", m_variableList->GetLineText(i).c_str() ); 00370 } 00371 fprintf(tempFile,"end variablelist\n\n\n"); 00372 00373 fprintf(tempFile,"begin evaluatorlist\n\n"); 00374 for(int i=0; i< m_evaluatorList->GetNumberOfLines(); i++) { 00375 fprintf(tempFile,"%s\n", m_evaluatorList->GetLineText(i).c_str() ); 00376 } 00377 fprintf(tempFile,"end evaluatorlist\n\n\n"); 00378 00379 fprintf(tempFile,"begin widgetlist\n\n"); 00380 for(int i=0; i< m_widgetCommands->GetNumberRows();i++) { 00381 for(int j=0; j< m_widgetCommands->GetNumberCols(); j++) { 00382 wxString temp = wxT("w"); 00383 std::stringstream out; 00384 out << i; 00385 temp.Append( wxString(out.str().c_str(), wxConvUTF8)); 00386 out.flush(); 00387 temp.Append(wxT(",")); 00388 std::stringstream outTwo; 00389 outTwo << j; 00390 temp.Append(wxString(outTwo.str().c_str(), wxConvUTF8)); 00391 outTwo.flush(); 00392 temp.Append(wxT("=")); 00393 temp.Append(m_widgetCommands->GetCellValue(j,i) ); 00394 00395 fprintf(tempFile,"%s\n", temp.c_str() ); 00396 } 00397 } 00398 fprintf(tempFile,"end widgetlist\n\n\n"); 00399 00400 fprintf(tempFile,"begin displayattributes\n"); 00401 for(int i=0; i< m_displayAttributesList->GetNumberOfLines(); i++) { 00402 fprintf(tempFile,"%s\n", m_displayAttributesList->GetLineText(i).c_str() ); 00403 } 00404 fprintf(tempFile,"end displayattributes\n"); 00405 00406 00407 fclose(tempFile); 00408 } 00409 00410 00411 /* 00412 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL 00413 */ 00414 00415 void ViewDisplayDescription::OnCancelClick( wxCommandEvent& event ) 00416 { 00417 this->Close(); 00418 } 00419 00420 /* 00421 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_ROW 00422 */ 00423 00424 //When the user updates the input field for the number of rows 00425 //we need to update the size of the widget grid and also update the 00426 //display attribute that contains Rowsize 00427 void ViewDisplayDescription::OnRowTextUpdated( wxCommandEvent& event ) 00428 { 00429 if(m_widgetCommands != NULL) { 00430 double row = 0; 00431 m_row->GetValue().ToDouble(&row); 00432 if(row > m_widgetCommands->GetNumberRows() ) { 00433 for(int i= m_widgetCommands->GetNumberRows(); i< row; i++) { 00434 m_widgetCommands->AppendRows(); 00435 for(int j=0; j< m_widgetCommands->GetNumberCols(); j++) { 00436 m_widgetCommands->SetCellRenderer(i , j, new wxGridCellAutoWrapStringRenderer); 00437 m_widgetCommands->SetCellEditor( i, j , new wxGridCellAutoWrapStringEditor); 00438 } 00439 } 00440 } 00441 else { 00442 for(int i= m_widgetCommands->GetNumberRows(); i> row; i--) { 00443 m_widgetCommands->DeleteRows(m_widgetCommands->GetNumberRows() - 1); 00444 } 00445 } 00446 } 00447 if(m_displayAttributesList != NULL) { 00448 bool found = false; 00449 int start = 0; 00450 for(int i=0; i < m_displayAttributesList->GetNumberOfLines() && found == false; i++) { 00451 wxString text = m_displayAttributesList->GetLineText(i); 00452 start += m_displayAttributesList->GetLineLength(i); 00453 size_t firstP = text.find_first_of(wxT("(")); 00454 if(firstP != wxString::npos) { 00455 wxString command(text, firstP); 00456 if(command.compare(wxString(DisplayAttributeCmd.find("Rowsize")->second.c_str(), wxConvUTF8)) == 0) { 00457 size_t lastP = text.find_first_of(wxT(")")); 00458 m_displayAttributesList->Replace(start-lastP+firstP,start-1,m_row->GetValue()); 00459 } 00460 } 00461 start+=2; 00462 } 00463 } 00464 } 00465 00466 00467 /* 00468 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_COLUMN 00469 */ 00470 00471 //When the user updates the input field for the number of columns 00472 //we need to update the size of the widget grid and also update the 00473 //display attribute that contains Columnsize 00474 void ViewDisplayDescription::OnColumnTextUpdated( wxCommandEvent& event ) 00475 { 00476 if(m_widgetCommands != NULL) { 00477 double col = 0; 00478 m_col->GetValue().ToDouble(&col); 00479 00480 //figure out if we need to add columns or delete columns 00481 if(col > m_widgetCommands->GetNumberCols() ) { 00482 for(int i= m_widgetCommands->GetNumberCols(); i< col; i++) { 00483 m_widgetCommands->AppendCols(); 00484 for(int j=0; j< m_widgetCommands->GetNumberRows(); j++) { 00485 //A nice feature that will wrap the text 00486 m_widgetCommands->SetCellRenderer(j , i, new wxGridCellAutoWrapStringRenderer); 00487 m_widgetCommands->SetCellEditor( j, i , new wxGridCellAutoWrapStringEditor); 00488 } 00489 } 00490 } 00491 else { 00492 for(int i= m_widgetCommands->GetNumberCols(); i> col; i--) { 00493 m_widgetCommands->DeleteCols(m_widgetCommands->GetNumberCols() - 1); 00494 } 00495 } 00496 } 00497 00498 //Update the display attribute with the new value 00499 if(m_displayAttributesList != NULL) { 00500 bool found = false; 00501 int start = 0; 00502 00503 //Go through the lines of m_displayAttributesList and find Columnsize and update 00504 //the value. If Columnsize is not in m_displayAttributesList then Columnsize will 00505 //currently not be put in the list. Also, if the user forgets to put in a ")" then 00506 //when this replaces it will replace the new line 00507 for(int i=0; i < m_displayAttributesList->GetNumberOfLines() && found == false; i++) { 00508 wxString text = m_displayAttributesList->GetLineText(i); 00509 start += m_displayAttributesList->GetLineLength(i); 00510 size_t firstP = text.find_first_of(wxT("(")); 00511 if(firstP != wxString::npos) { 00512 wxString command(text, firstP); 00513 if(command.compare(wxString(DisplayAttributeCmd.find("Columnsize")->second.c_str(), wxConvUTF8)) == 0) { 00514 size_t lastP = text.find_first_of(wxT(")")); 00515 m_displayAttributesList->Replace(start-lastP+firstP,start-1,m_col->GetValue()); 00516 } 00517 } 00518 start+=2; 00519 } 00520 } 00521 } 00522 00523 /* 00524 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENUITEM3 00525 */ 00526 00527 //Clear out the values of the input fields and 00528 //set the defaults 00529 //We could change this to opening a new 00530 //viewDisplayDescription 00531 void ViewDisplayDescription::OnMenuNewClick( wxCommandEvent& event ) 00532 { 00533 this->ClearAll(); 00534 this->SetDefaults(); 00535 } 00536 00537 00538 /* 00539 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENUITEM1 00540 */ 00541 00542 //Open a display description when the user 00543 //selected open from the file menu 00544 //Once the display description is opened 00545 //then go through and populate the input fields with 00546 //the appropriate values 00547 void ViewDisplayDescription::OnMenuOpenClick( wxCommandEvent& event ) 00548 { 00549 this->ClearAll(); 00550 wxFileDialog * filedialog = new wxFileDialog(this, wxT("Choose the Display Description to open"), wxT(""), wxT("untitled.nd3"), wxT("(*.nd3)|*.nd3|(*.*)|*.*"), wxFD_OPEN, wxDefaultPosition, wxDefaultSize, wxT("Open")); 00551 if( filedialog->ShowModal() == wxID_CANCEL ){ delete filedialog; return;} 00552 DisplayDescription *dd = new DisplayDescription(); 00553 dd->Read(std::string(filedialog->GetPath().mb_str())); 00554 00555 std::string rdlFilename = dd->GetRDL()->GetFilename(); 00556 m_rdlList->Append(wxString(rdlFilename.c_str(), wxConvUTF8)); 00557 00558 std::map<std::string, std::string> *variables = dd->GetVariableList()->GetVariableList(); 00559 for(std::map<std::string, std::string>::iterator i = variables->begin(); i!= variables->end(); i++) { 00560 m_variableList->AppendText(wxString(i->first.c_str(), wxConvUTF8)); 00561 m_variableList->AppendText(wxT("=")); 00562 m_variableList->AppendText(wxString(i->second.c_str(), wxConvUTF8)); 00563 m_variableList->AppendText(wxT("\n")); 00564 } 00565 00566 std::map<std::string, std::string> *evaluatorCommands = dd->GetEvaluatorList()->GetList(); 00567 for(std::map<std::string, std::string>::iterator i = evaluatorCommands->begin(); i!= evaluatorCommands->end(); i++) { 00568 m_evaluatorList->AppendText(wxString(i->first.c_str(), wxConvUTF8)); 00569 m_evaluatorList->AppendText(wxT("=")); 00570 m_evaluatorList->AppendText(wxString(i->second.c_str(), wxConvUTF8)); 00571 m_evaluatorList->AppendText(wxT("\n")); 00572 } 00573 00574 std::map<std::string, std::vector< std::vector<std::string> > > *attributes = dd->GetDisplayAttributes()->GetAttributes(); 00575 for(std::map<std::string, std::vector< std::vector<std::string> > >::iterator i = attributes->begin(); i!= attributes->end(); i++) { 00576 00577 for(int j=0; j< i->second.size(); j++) { 00578 m_displayAttributesList->AppendText(wxString(i->first.c_str(), wxConvUTF8)); 00579 m_displayAttributesList->AppendText(wxT("(")); 00580 for(int k=0; k< i->second.at(j).size(); k++) { 00581 m_displayAttributesList->AppendText(wxString(i->second.at(j).at(k).c_str(), wxConvUTF8)); 00582 m_displayAttributesList->AppendText(wxT(",")); 00583 } 00584 if(i->second.at(j).size() != 0 ) { 00585 m_displayAttributesList->Remove(m_displayAttributesList->GetInsertionPoint()-1,m_displayAttributesList->GetInsertionPoint()); 00586 } 00587 m_displayAttributesList->AppendText(wxT(")\n")); 00588 } 00589 } 00590 00591 m_row->SetValue(wxString(attributes->find(DisplayAttributeCmd.find("Rowsize")->second)->second.at(0).at(0).c_str(), wxConvUTF8) ); 00592 m_col->SetValue(wxString(attributes->find(DisplayAttributeCmd.find("Columnsize")->second)->second.at(0).at(0).c_str(), wxConvUTF8) ); 00593 00594 delete dd; 00595 00596 delete filedialog; 00597 } 00598 00599 00600 /* 00601 * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENUITEM 00602 */ 00603 00604 //Save the display description when the user 00605 //selected save in the File menu 00606 void ViewDisplayDescription::OnMenuSaveClick( wxCommandEvent& event ) 00607 { 00608 this->Save(); 00609 } 00610 00611 00612 /* 00613 * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_EXIT 00614 */ 00615 00616 //Close the display when the user selected exit 00617 //in the File menu 00618 void ViewDisplayDescription::OnExitClick( wxCommandEvent& event ) 00619 { 00620 this->Close(); 00621 } 00622 00623 //Clear out the values in all input location 00624 void ViewDisplayDescription::ClearAll() 00625 { 00626 m_rdlList->Clear(); 00627 m_variableList->Clear(); 00628 m_evaluatorList->Clear(); 00629 m_displayAttributesList->Clear(); 00630 m_widgetCommands->ClearGrid(); 00631 m_row->Clear(); 00632 m_col->Clear(); 00633 } 00634 00635 //Have a central location of what the defaults will be for 00636 //this display 00637 void ViewDisplayDescription::SetDefaults() 00638 { 00639 m_widgetCommands->SetDefaultColSize(50); 00640 m_widgetCommands->SetDefaultRowSize(25); 00641 m_widgetCommands->SetColLabelSize(25); 00642 m_widgetCommands->SetRowLabelSize(50); 00643 00644 m_col->SetValue(wxT("3")); 00645 m_row->SetValue(wxT("2")); 00646 00647 wxString text = wxString(DisplayAttributeCmd.find("Rowsize")->second.c_str(), wxConvUTF8); 00648 text.Append(wxT("(")); 00649 text.Append(m_row->GetValue()); 00650 text.Append(wxT(")\n")); 00651 m_displayAttributesList->AppendText(text); 00652 00653 wxString textTwo = wxString(DisplayAttributeCmd.find("Columnsize")->second.c_str(), wxConvUTF8); 00654 textTwo.Append(wxT("(")); 00655 textTwo.Append(m_row->GetValue()); 00656 textTwo.Append(wxT(")\n")); 00657 m_displayAttributesList->AppendText(textTwo); 00658 00659 } 00660 00661 00662 /* 00663 * wxEVT_GRID_CMD_CELL_RIGHT_CLICK event handler for ID_WIDGET_COMMANDS 00664 */ 00665 00666 //The user right clicked on the grid widgetCommand 00667 //Need to display to the user a popup menu of the 00668 //widget choices 00669 void ViewDisplayDescription::OnWidgetCommandsCellRightClick( wxGridEvent& event ) 00670 { 00671 wxMenu *temp = new wxMenu(); 00672 for(WidgetCmdList::iterator i=WidgetCmd.begin(); i !=WidgetCmd.end(); i++) { 00673 temp->Append(wxID_ANY, wxString(i->second.c_str(), wxConvUTF8), wxEmptyString, wxITEM_NORMAL); 00674 this->Connect(temp->GetMenuItems().back()->GetId(),wxEVT_COMMAND_MENU_SELECTED, 00675 wxCommandEventHandler(ViewDisplayDescription::OnRightClickSelect), 00676 NULL, this); 00677 LocationAndText lt; 00678 lt.text = wxString(i->second.c_str(), wxConvUTF8); 00679 lt.row = event.GetRow(); 00680 lt.col = event.GetCol(); 00681 m_clickToText.insert(std::pair<int,LocationAndText>(temp->GetMenuItems().back()->GetId(), lt)); 00682 } 00683 00684 this->PopupMenu(temp,ScreenToClient(wxGetMousePosition())); 00685 00686 delete temp; 00687 } 00688 00689 00690 //The user selected an option from the popup menu 00691 //Need to get the selection and append the results 00692 //to the correct row and column of the widget commands 00693 void ViewDisplayDescription::OnRightClickSelect(wxCommandEvent& event) 00694 { 00695 int id = event.GetId(); 00696 LocationAndText lt = m_clickToText.find(id)->second; 00697 wxString text = lt.text; 00698 text.Append(wxT("()")); 00699 wxGridCellCoordsArray temp = m_widgetCommands->GetSelectedCells(); 00700 wxString cv = m_widgetCommands->GetCellValue(lt.row,lt.col); 00701 cv.Append(text); 00702 m_widgetCommands->SetCellValue(cv, lt.row, lt.col); 00703 m_clickToText.clear(); 00704 }