00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <iostream.h>
00025
00026 void TGo4ParaEdit::init()
00027 {
00028 TGo4LockGuard glob;
00029 fxTGo4GUIRegistry = TGo4GUIRegistry::Instance();
00030 char SlotName[256];
00031 char Caption[256];
00032 snprintf(SlotName,255,"%s%s",name(),"_Slots" );
00033 snprintf(Caption,255,"%s%s","Edit Parameter: " , name());
00034 setCaption( trUtf8( Caption ) );
00035 PleaseUpdateLabel->setShown(false);
00037
00038 fxFileMenu =0;
00039 fxControlMenu=0;
00040 fxMenuBar=0;
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 MenuDummy->setShown(false);
00058
00059
00060
00061 adjustSize();
00062
00063 fxTGo4ParaEditSlots = (TGo4ParaEditSlots *) fxTGo4GUIRegistry->GetSlotClass(SlotName);
00064 if(fxTGo4ParaEditSlots !=0) {
00065 fxTGo4ParaEditSlots->SetGUI(this);
00066 }else{
00067 fxTGo4ParaEditSlots = new TGo4ParaEditSlots (SlotName, "Slots Class for Qt GUI", this);
00068 }
00069 fxTGo4ParaEditStatus= dynamic_cast <TGo4ParaEditStatus *> (fxTGo4ParaEditSlots->GetStatus());
00070 }
00071
00072 void TGo4ParaEdit::destroy()
00073 {
00074 TGo4LockGuard glob;
00075 fxTGo4GUIRegistry->UnRegisterClass(fxTGo4ParaEditSlots,fxTGo4ParaEditStatus);
00076 delete fxTGo4ParaEditSlots;
00077 }
00078
00079 void TGo4ParaEdit::closeEvent( QCloseEvent *ce )
00080 {
00081 TGo4LockGuard glob;
00082 ce->accept();
00083 fxTGo4ParaEditSlots->SetGUI(0);
00084 delete this;
00085 }
00086
00087 void TGo4ParaEdit::clearTextFields()
00088 {
00089 TGo4LockGuard glob;
00090 int numrows=MemberTable->numRows();
00091 for(int row=0; row<numrows;++row)
00092 {
00093 MemberTable->setText(row,fiColValue,"");
00094 fxTGo4ParaEditStatus->SetParaMemVal(row,"");
00095 }
00096 if(fbEditorMode) ParameterName->clear();
00097 StatusMessage("Cleared.");
00098 PleaseUpdateLabel->setShown(true);
00099 }
00100
00101
00102
00103
00104
00105 void TGo4ParaEdit::RefreshDisplay( TGo4ParaEditStatus * state )
00106 {
00107
00108 if(state==0) state=fxTGo4ParaEditStatus;
00109 if(state==0) return;
00110 TGo4LockGuard glob;
00111
00112 ParameterName->setText(state->GetParaName());
00113
00114 MemberTable->hide();
00115 int memnum=state->GetMemNumber();
00116 QHeader* header=MemberTable->horizontalHeader();
00117 header->setLabel(fiColType,"Type");
00118 header->setLabel(fiColName,"Name");
00119 header->setLabel(fiColValue,"Value");
00120 header->setLabel(fiColComment,"Comments");
00121 MemberTable->setNumRows(memnum);
00122 MemberTable->setColumnReadOnly(fiColType,true);
00123 MemberTable->setColumnReadOnly(fiColName,true);
00124 MemberTable->setColumnReadOnly(fiColComment,true);
00125 MemberTable->setLeftMargin(0);
00126 MemberTable->verticalHeader()->hide();
00127 for(int row=0; row<memnum;++row)
00128 {
00129 const char* type = state->GetParaMemType(row);
00130 const char* name = state->GetParaMember(row);
00131 const char* value = state->GetParaMemVal(row);
00132 const char* comment = state->GetParaMemComment(row);
00133 MemberTable->setText(row,fiColType, type);
00134 MemberTable->setText(row,fiColName, name);
00135 MemberTable->setText(row,fiColValue, value);
00136 MemberTable->setText(row,fiColComment, comment);
00137 if(strstr(value,"Unknown") || strstr(value,"Edit"))
00138 {
00139
00140 QTableItem* item=MemberTable->item(row,fiColValue);
00141 if(item) item->setEnabled(false);
00142 }
00143 if(!state->IsParaMemVisible(row))
00144 MemberTable->hideRow(row);
00145 else
00146 MemberTable->showRow(row);
00147 }
00148 MemberTable->show();
00149 PleaseUpdateLabel->setShown(false);
00150 polish();
00151 update();
00152 show();
00153
00154
00155 raise();
00156 }
00157
00158
00159
00160
00161
00162 void TGo4ParaEdit::ChangeParaName(const QString & s )
00163 {
00164
00165 fxTGo4ParaEditStatus->SetParaName(s);
00166 PleaseUpdateLabel->setShown(true);
00167 }
00168
00169 void TGo4ParaEdit::ChangeClassName(const QString & s )
00170 {
00171 fxTGo4ParaEditStatus->SetParaClass(s);
00172 RefreshDisplay(fxTGo4ParaEditStatus);
00173 PleaseUpdateLabel->setShown(true);
00174 }
00175
00176
00177 void TGo4ParaEdit::RefreshClicked()
00178 {
00179 fxTGo4ParaEditSlots->SendRefreshCommand();
00180 StatusMessage("Refreshed parameter from analysis.");
00181 }
00182
00183 void TGo4ParaEdit::ApplyClicked()
00184 {
00185 fxTGo4ParaEditSlots->SendApplyCommand();
00186 StatusMessage("Applied parameter to analysis.");
00187 PleaseUpdateLabel->setShown(false);
00188 }
00189
00190
00191
00192 void TGo4ParaEdit::NewEntry()
00193 {
00194 TGo4LockGuard Global;
00195 const Text_t* name="New Parameter";
00196 Text_t slotname[256];
00197 snprintf(slotname,256,"%s_Slots",name);
00198 TGo4ParaEdit* neditor=0;
00199 TGo4ParaEditSlots* nslots=0;
00200 nslots = dynamic_cast <TGo4ParaEditSlots *> (fxTGo4GUIRegistry->GetSlotClass(slotname));
00201 if (nslots ==0)
00202 {
00203
00204 neditor=new TGo4ParaEdit(fxTGo4GUIRegistry->GetCentralWindow(),
00205 name);
00206 }
00207 else
00208 {
00209
00210 neditor = dynamic_cast <TGo4ParaEdit *> (fxTGo4GUIRegistry->GetGUIClass(nslots));
00211 if (neditor==0)
00212 {
00213
00214 neditor=new TGo4ParaEdit(fxTGo4GUIRegistry->GetCentralWindow(),
00215 name);
00216 }
00217 else {}
00218 }
00219
00220 neditor->SetNewParaMode(true);
00221 neditor->RefreshDisplay(0);
00222 neditor->polish();
00223 neditor->update();
00224 neditor->show();
00225
00226
00227 neditor->raise();
00228 }
00229
00230 void TGo4ParaEdit::ChangedTable( int row, int col )
00231 {
00232 TGo4LockGuard glob;
00233 QString txt= MemberTable->text( row, col );
00234
00235 switch(col)
00236 {
00237 case fiColValue:
00238 fxTGo4ParaEditStatus->SetParaMemVal(row,txt);
00239 break;
00240 case fiColType:
00241
00242 break;
00243 case fiColName:
00244
00245 break;
00246 default:
00247
00248 cout <<"Change table received out of range column "<<col << endl;
00249 break;
00250 }
00251 PleaseUpdateLabel->setShown(true);
00252 }
00253
00254 void TGo4ParaEdit::SetNewParaMode( bool on )
00255 {
00256 TGo4LockGuard glob;
00257 fbEditorMode=on;
00258 if(on)
00259 {
00260
00261 ParameterClass->setEnabled(true);
00262 ParameterName->setEnabled(true);
00263 RefreshButton->setEnabled(false);
00264 NewButton->setEnabled(false);
00265 ApplyButton->setText("Apply");
00266
00267
00268
00269
00270
00271 fxTGo4ParaEditStatus->ResetParameterList();
00272 ParameterClass->clear();
00273
00274 char* clname=0;
00275 int ix=0;
00276 int currentix=0;
00277 while((clname=const_cast<char*>(fxTGo4ParaEditStatus->NextParameterClass()))!=0)
00278 {
00279
00280 ParameterClass->insertItem(clname);
00281 if(!strcmp(clname,fxTGo4ParaEditStatus->GetParaClass()))
00282 currentix=ix;
00283 ++ix;
00284 }
00285 ParameterClass->setCurrentItem(currentix);
00286 }
00287 else
00288 {
00289
00290 ParameterClass->setEnabled(false);
00291 ParameterName->setEnabled(false);
00292 RefreshButton->setEnabled(true);
00293 NewButton->setEnabled(true);
00294 ApplyButton->setText("Apply");
00295
00296
00297
00298 ParameterClass->clear();
00299 ParameterClass->insertItem(fxTGo4ParaEditStatus->GetParaClass(),0);
00300
00301 }
00302 }
00303
00304 void TGo4ParaEdit::TableDoubleClick( int row, int col )
00305 {
00306
00307 if(col!=fiColName) return;
00308 fiCurrentRow=row;
00309 if(IsArray(row))
00310 ExpandArray();
00311 else if(IsFitter(row))
00312 EditFitter();
00313 else ;
00314 }
00315
00316 void TGo4ParaEdit::ContextMenu( int row, int col )
00317 {
00318 if(col!=fiColName) return;
00319
00320 if(IsArray(row))
00321 {
00322
00323 TGo4LockGuard glob;
00324 fiCurrentRow=row;
00325 QPopupMenu* contextMenu = new QPopupMenu( this );
00326 Q_CHECK_PTR( contextMenu );
00327 QLabel *caption = new QLabel( "<font color=darkblue><u><b>"
00328 "Array View</b></u></font>", this );
00329 caption->setAlignment( Qt::AlignCenter );
00330
00331 contextMenu->insertItem( caption );
00332 contextMenu->insertItem( "+ \t(next index)", this, SLOT(IncArrayIndex()));
00333 contextMenu->insertItem( "-- \t(prev index)", this, SLOT(DecArrayIndex()));
00334 contextMenu->insertItem( "Expand/Shrink", this, SLOT(ExpandArray() ));
00335
00336
00337
00338 if(IsFitter(row))
00339 {
00340
00341 contextMenu->insertItem( "Edit...", this, SLOT(EditFitter()));
00342 contextMenu->insertItem( "Update from FitGUI workspace", this, SLOT(UpdateFitter()));
00343 }
00344 contextMenu->exec( QCursor::pos() );
00345
00346
00347 delete contextMenu;
00348
00349
00350 }
00351 else if(IsFitter(row))
00352 {
00353
00354 TGo4LockGuard glob;
00355 fiCurrentRow=row;
00356 QPopupMenu* contextMenu = new QPopupMenu( this );
00357 Q_CHECK_PTR( contextMenu );
00358 QLabel *caption = new QLabel( "<font color=darkblue><u><b>"
00359 "Modify Fitter</b></u></font>", this );
00360 caption->setAlignment( Qt::AlignCenter );
00361 contextMenu->insertItem( caption );
00362 contextMenu->insertItem( "Edit...", this, SLOT(EditFitter()));
00363 contextMenu->insertItem( "Update from FitGUI workspace", this, SLOT(UpdateFitter()));
00364 contextMenu->exec( QCursor::pos() );
00365 delete contextMenu;
00366 }
00367 else
00368 {
00369
00370 }
00371 }
00372
00373 void TGo4ParaEdit::IncArrayIndex()
00374 {
00375
00376 TGo4LockGuard glob;
00377 int xoldindex=fxTGo4ParaEditStatus->GetParaMemArrIndex(fiCurrentRow);
00378 int yoldindex=fxTGo4ParaEditStatus->GetParaMemArrIndey(fiCurrentRow);
00379 int newrow=fiCurrentRow+1;
00380 if(fxTGo4ParaEditStatus->IsParaMemVisible(newrow)) return;
00381
00382 int xnewindex=fxTGo4ParaEditStatus->GetParaMemArrIndex(newrow);
00383 int ynewindex=fxTGo4ParaEditStatus->GetParaMemArrIndey(newrow);
00384
00385 if(xnewindex>xoldindex || ynewindex>yoldindex)
00386 {
00387
00388 MemberTable->hideRow(fiCurrentRow);
00389 fxTGo4ParaEditStatus->SetParaMemVisible(fiCurrentRow,false);
00390 MemberTable->showRow(newrow);
00391 fxTGo4ParaEditStatus->SetParaMemVisible(newrow,true);
00392 MemberTable->adjustColumn(fiColName);
00393 MemberTable->setCurrentCell(newrow,fiColValue);
00394 }
00395 else
00396 {
00397
00398 }
00399 }
00400
00401 void TGo4ParaEdit::DecArrayIndex()
00402 {
00403
00404 TGo4LockGuard glob;
00405 int xoldindex=fxTGo4ParaEditStatus->GetParaMemArrIndex(fiCurrentRow);
00406 int yoldindex=fxTGo4ParaEditStatus->GetParaMemArrIndey(fiCurrentRow);
00407 if(xoldindex<1 && yoldindex<1) return;
00408 int newrow=fiCurrentRow-1;
00409 if(fxTGo4ParaEditStatus->IsParaMemVisible(newrow)) return;
00410
00411 MemberTable->hideRow(fiCurrentRow);
00412 fxTGo4ParaEditStatus->SetParaMemVisible(fiCurrentRow,false);
00413 MemberTable->showRow(newrow);
00414 fxTGo4ParaEditStatus->SetParaMemVisible(newrow,true);
00415 MemberTable->adjustColumn(fiColName);
00416 MemberTable->setCurrentCell(newrow,fiColValue);
00417 }
00418
00419
00420 void TGo4ParaEdit::ExpandArray()
00421 {
00422
00423
00424
00425 TGo4LockGuard glob;
00426 int row=fiCurrentRow;
00427 const char* arfullname=fxTGo4ParaEditStatus->GetParaMember(row);
00428 char arname[256];
00429 char* arend=strstr(arfullname,"[");
00430 int arlen=arend-arfullname;
00431 snprintf(arname,arlen+1,"%s",arfullname);
00432
00433 int memnum=fxTGo4ParaEditStatus->GetMemNumber();
00434 MemberTable->hide();
00435 for(int r=0; r<memnum;++r)
00436 {
00437 const char* memname=fxTGo4ParaEditStatus->GetParaMember(r);
00438 if(strstr(memname,arname))
00439 {
00440 if(fxTGo4ParaEditStatus->IsParaMemVisible(r))
00441 {
00442 MemberTable->hideRow(r);
00443 fxTGo4ParaEditStatus->SetParaMemVisible(r,false);
00444 }
00445 else
00446 {
00447 MemberTable->showRow(r);
00448 fxTGo4ParaEditStatus->SetParaMemVisible(r,true);
00449 }
00450 }
00451 }
00452
00453 MemberTable->showRow(row);
00454 fxTGo4ParaEditStatus->SetParaMemVisible(row,true);
00455 MemberTable->adjustColumn(fiColName);
00456 MemberTable->setCurrentCell(row,fiColValue);
00457 MemberTable->show();
00458 polish();
00459 update();
00460
00461 raise();
00462 show();
00463
00464 }
00465
00466
00467 bool TGo4ParaEdit::IsArray(int row)
00468 {
00469
00470 int arrindex=fxTGo4ParaEditStatus->GetParaMemArrIndex(row);
00471 if(arrindex<0)
00472 return false;
00473 else
00474 return true;
00475 }
00476
00477
00478 bool TGo4ParaEdit::IsFitter(int row)
00479 {
00480 const char* type=fxTGo4ParaEditStatus->GetParaMemType(row);
00481 if(type && !strcmp(type,"TGo4Fitter*"))
00482 return true;
00483 else
00484 return false;
00485 }
00486
00487
00488
00489
00490 void TGo4ParaEdit::openFile()
00491 {
00492 TGo4LockGuard glob;
00493 TGo4DiskFileBrowserSlots *filebrowserslots = dynamic_cast <TGo4DiskFileBrowserSlots *> (fxTGo4GUIRegistry->GetSlotClass("TGo4DiskFileBrowserSlots"));
00494 TObject* ob=0;
00495 const Text_t* filename;
00496 if(filebrowserslots)
00497 filename=filebrowserslots->LoadObject(&ob,ParameterName->text().stripWhiteSpace());
00498 else
00499 filename=0;
00500 fxTGo4ParaEditSlots->AddObject(dynamic_cast<TNamed*>(ob));
00501
00502 RefreshDisplay(0);
00503 char buf[256];
00504 if(filename)
00505 snprintf(buf,256,"Loaded %s from %s",ParameterName->text().ascii(), filename);
00506 else
00507 snprintf(buf,256,"Failed to load %s",ParameterName->text().ascii());
00508 StatusMessage(buf);
00509 delete ob;
00510 }
00511
00512 void TGo4ParaEdit::saveFile()
00513 {
00514 TGo4LockGuard glob;
00515 TGo4DiskFileBrowserSlots *filebrowserslots = dynamic_cast <TGo4DiskFileBrowserSlots *> (fxTGo4GUIRegistry->GetSlotClass("TGo4DiskFileBrowserSlots"));
00516 const Text_t* filename;
00517 if(filebrowserslots)
00518 filename=filebrowserslots->SaveObject(fxTGo4ParaEditStatus->GetParameter(),
00519 ParameterName->text().stripWhiteSpace().data());
00520 else
00521 filename=0;
00522 RefreshDisplay(0);
00523 char buf[256];
00524 if(filename)
00525 snprintf(buf,256,"Saved %s to file %s",ParameterName->text().stripWhiteSpace().data(), filename);
00526 else
00527 snprintf(buf,256,"Failed to save %s",ParameterName->text().stripWhiteSpace().data());
00528 StatusMessage(buf);
00529 }
00530
00531
00532 void TGo4ParaEdit::StatusMessage( const char * txt )
00533 {
00534
00535
00536
00537
00538
00539 QString text="Parameter Editor ";
00540 text.append(name());
00541 text.append(" :");
00542 text.append(txt);
00543
00544 TGo4MainWindow *MW= dynamic_cast<TGo4MainWindow *>(fxTGo4GUIRegistry->GetMainWindow());
00545 if(MW) MW->StatusMessage(text);
00546 }
00547
00548
00549
00550
00551 void TGo4ParaEdit::EditFitter()
00552 {
00553 TGo4LockGuard glob;
00554 int row=fiCurrentRow;
00555 long address=fxTGo4ParaEditStatus->GetMemberAddress(row);
00556 fxTGo4ParaEditStatus->SetFitPointerAddress(address);
00557 TGo4Fitter* fitter= fxTGo4ParaEditStatus->GetLastFitter();
00558 if(fitter)
00559 {
00560 TGo4MainWindow* mainwin=dynamic_cast <TGo4MainWindow *> (fxTGo4GUIRegistry->GetMainWindow());
00561 TGo4FitPanel*FitPanel=mainwin->FitPanelSlot();
00562 FitPanel->raise();
00563 FitPanel->show();
00564 FitPanel->ActivateByFitter(fitter);
00565 char mess[256];
00566 snprintf(mess,256,"Started editing fitter %s (%s)",
00567 fxTGo4ParaEditStatus->GetParaMember(row),
00568 fitter->GetName());
00569 StatusMessage(mess);
00570 }
00571 }
00572
00573
00574 void TGo4ParaEdit::UpdateFitter()
00575 {
00576
00577 TGo4LockGuard glob;
00578 int row=fiCurrentRow;
00579 long address=fxTGo4ParaEditStatus->GetMemberAddress(row);
00580 fxTGo4ParaEditStatus->SetFitPointerAddress(address);
00581
00582
00583 TGo4Fitter* fitter=0;
00584 TGo4FitPanelSlots* fitpanelslots=dynamic_cast <TGo4FitPanelSlots *> (fxTGo4GUIRegistry->GetSlotClass("TGo4FitPanelSlots"));
00585 if(fitpanelslots)
00586 fitter=fitpanelslots->GetFitter();
00587 if(fitter)
00588 {
00589 fxTGo4ParaEditStatus->UpdateLastFitter(fitter);
00590 char mess[256];
00591 snprintf(mess,256,"Member %s updated from fitter %s",
00592 fxTGo4ParaEditStatus->GetParaMember(row),
00593 fitter->GetName());
00594 StatusMessage(mess);
00595 PleaseUpdateLabel->setShown(true);
00596 }
00597 }
00598
00599