00001
00002
00003
00004
00005
00006
00007
00008 #include "EventDisplayBase/CfgEdit.h"
00009 #include <iostream>
00010 #include <string>
00011 #include <vector>
00012 #include <cstdlib>
00013 extern "C" {
00014 #include <sys/types.h>
00015 #include <unistd.h>
00016 }
00017 #include "TGCanvas.h"
00018 #include "TGLabel.h"
00019 #include "TGWindow.h"
00020 #include "TGButton.h"
00021 #include "TGTextEntry.h"
00022 #include "TGScrollBar.h"
00023 #include "Config/Config.h"
00024 #include "Config/Param.h"
00025 #include "EventDisplayBase/IoModule.h"
00026 #include "XMLInterface/xmli.h"
00027 #include "XMLInterface/Stack.h"
00028 using namespace evdb;
00029
00030 ClassImp(evdb::ParamFrame)
00031 ClassImp(evdb::CfgEdit)
00032
00033
00034
00035 ParamFrame::ParamFrame(const TGWindow* p,
00036 cfg::Config* cfg,
00037 std::vector<std::string>& name,
00038 std::vector<std::string>& tag,
00039 std::vector<std::string>& comment,
00040 std::vector<TGTextEntry*>& fT2)
00041 {
00042
00043
00044 fFrame = new TGGroupFrame(p, "Parameters", kVerticalFrame);
00045
00046 TGLayoutHints* fLH3 = new TGLayoutHints(kLHintsCenterX|kLHintsExpandX,
00047 2,2,2,2);
00048
00049 fML = new TGMatrixLayout(fFrame, 0, 2, 2);
00050 fFrame->SetLayoutManager(fML);
00051 cfg::Config::ParamMap::iterator itr (cfg->ParMap().begin());
00052 cfg::Config::ParamMap::iterator itrEnd(cfg->ParMap().end());
00053
00054 int h=0;
00055
00056 for (;itr!=itrEnd;++itr) {
00057 cfg::Param* p = itr->second;
00058
00059
00060 name. push_back( p->GetName() );
00061 tag. push_back( p->XMLTag() );
00062 comment.push_back( p->GetComment() );
00063
00064
00065 std::ostringstream tag;
00066 tag << p->GetName() << " <" << p->XMLTag() << ">";
00067 TGTextButton*
00068 b = new TGTextButton(fFrame,
00069 tag.str().c_str(),
00070 -1,
00071 TGButton::GetDefaultGC()(),
00072 TGTextButton::GetDefaultFontStruct(),
00073 0);
00074 b->SetToolTipText(p->GetComment());
00075 fFrame->AddFrame(b, fLH3);
00076
00077
00078 std::ostringstream value;
00079 value << (*p);
00080 TGTextEntry* t = new TGTextEntry(fFrame, value.str().c_str());
00081
00082
00083 t->Resize(225,18);
00084 fFrame->AddFrame(t, fLH3);
00085 fT2.push_back(t);
00086 h += 18;
00087 }
00088
00089 fFrame->Resize(fFrame->GetWidth(), 400);
00090
00091 fFrame->Connect("ProcessedEvent(Event_t*)", "evdb::ParamFrame", this,
00092 "HandleMouseWheel(Event_t*)");
00093 fCanvas = 0;
00094
00095 delete fLH3;
00096 }
00097
00098
00099
00100 int ParamFrame::GetHeight() const
00101 {
00102 if (fFrame) return fFrame->GetHeight();
00103 else return 0;
00104 }
00105
00106
00107
00108 int ParamFrame::GetWidth() const
00109 {
00110 if (fFrame) return fFrame->GetWidth();
00111 else return 0;
00112 }
00113
00114
00115
00116 void ParamFrame::HandleMouseWheel(Event_t *event)
00117 {
00118
00119
00120 if (event->fType != kButtonPress && event->fType != kButtonRelease)
00121 return;
00122
00123 Int_t page = 0;
00124 if (event->fCode == kButton4 || event->fCode == kButton5) {
00125 if (!fCanvas) return;
00126 if (fCanvas->GetContainer()->GetHeight())
00127 page = Int_t(Float_t(fCanvas->GetViewPort()->GetHeight() *
00128 fCanvas->GetViewPort()->GetHeight()) /
00129 fCanvas->GetContainer()->GetHeight());
00130 }
00131
00132 if (event->fCode == kButton4) {
00133
00134 Int_t newpos = fCanvas->GetVsbPosition() - page;
00135 if (newpos < 0) newpos = 0;
00136 fCanvas->SetVsbPosition(newpos);
00137 }
00138 if (event->fCode == kButton5) {
00139
00140 Int_t newpos = fCanvas->GetVsbPosition() + page;
00141 fCanvas->SetVsbPosition(newpos);
00142 }
00143 }
00144
00145
00146
00147 CfgEdit::CfgEdit(cfg::Config* cfg, TGMainFrame* ) :
00148 cfg::ConfigEditor(cfg),
00149 TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), 4, 4)
00150 {
00151 int h = 600;
00152 int w = 500;
00153
00154 fLH1 = new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 2,2,2,2);
00155 fLH2 = new TGLayoutHints(kLHintsRight|kLHintsExpandX, 2,2,2,2);
00156 fLH3 = new TGLayoutHints(kLHintsCenterX|kLHintsExpandX,2,2,2,2);
00157 fLH4 = new TGLayoutHints(kLHintsLeft|kLHintsExpandY, 4,4,4,4);
00158
00159
00160 h = 0;
00161 fF1 = new TGCompositeFrame(this, w, h, kVerticalFrame);
00162 std::ostringstream lbl1;
00163 lbl1 << "Configuration " << cfg->GetName() << ", "
00164 << cfg->GetVersion() << " version";
00165
00166 std::ostringstream lbl2;
00167 lbl2 << "Originally from " << cfg->GetSource();
00168
00169 fL1 = new TGLabel(fF1, lbl1.str().c_str());
00170 fL2 = new TGLabel(fF1, lbl2.str().c_str());
00171
00172 fF1->AddFrame(fL1,fLH3);
00173 fF1->AddFrame(fL2,fLH3);
00174
00175 fL1->SetHeight(26);
00176 fL2->SetHeight(20);
00177 this->AddFrame(fF1);
00178 h = 30;
00179
00180
00181 fCanvas = new TGCanvas(this, w, h);
00182 fParam = new ParamFrame(fCanvas->GetViewPort(), cfg, fName, fTag,
00183 fComment, fT2);
00184 fParam->SetCanvas(fCanvas);
00185 fCanvas->SetContainer(fParam->GetFrame());
00186 fParam->GetFrame()->SetCleanup(kDeepCleanup);
00187
00188 h = fParam->GetHeight();
00189 if (h > 600) h = 600;
00190 fCanvas->Resize(w,h);
00191
00192 this->AddFrame(fCanvas);
00193
00194
00195 fF3 = new TGCompositeFrame(this, w, 24, kHorizontalFrame);
00196 this->AddFrame(fF3);
00197
00198 fB3 = new TGTextButton(fF3, "Apply");
00199 fB4 = new TGTextButton(fF3, "Cancel");
00200 fB5 = new TGTextButton(fF3, "Done");
00201 fF3->AddFrame(fB3, fLH1);
00202 fF3->AddFrame(fB4, fLH1);
00203 fF3->AddFrame(fB5, fLH1);
00204
00205 fB3->Connect("Clicked()","evdb::CfgEdit",this,"Apply()");
00206 fB4->Connect("Clicked()","evdb::CfgEdit",this,"Cancel()");
00207 fB5->Connect("Clicked()","evdb::CfgEdit",this,"Done()");
00208
00209 this->Connect("CloseWindow()","evdb::CfgEdit",this,"CloseWindow()");
00210
00211 h += 75;
00212
00213 this->Resize(w+8,h);
00214 this->MapSubwindows();
00215 this->MapWindow();
00216 }
00217
00218
00219
00220 int CfgEdit::EditConfig(cfg::Config& cfg)
00221 {
00222 unsigned int i;
00223 const char* values;
00224 std::ostringstream xml;
00225
00226 xml << "<configdoc>\n";
00227 for (i=0; i<fName.size(); ++i) {
00228 values = fT2[i]->GetText();
00229 xml << "<param name=\"" << fName[i] << "\">\n";
00230 xml << " <" << fTag[i] << "> " << values << " </" << fTag[i] << ">\n";
00231 xml << " " << fComment[i] << "\n";
00232 xml << "</param>\n";
00233 }
00234 xml << "</configdoc>\n";
00235
00236
00237
00238
00239 xmli::ReadString(xml.str().c_str());
00240
00241
00242
00243 xmli::Stack<cfg::Param>& s = xmli::Stack<cfg::Param>::Instance();
00244 for (; !s.empty(); s.pop()) cfg.AdoptParam(new cfg::Param(s.top()));
00245
00246 return 1;
00247 }
00248
00249
00250
00251 CfgEdit::~CfgEdit()
00252 {
00253 unsigned int i;
00254 delete fB5;
00255 delete fB4;
00256 delete fB3;
00257 for (i=0; i<fT2.size(); ++i) delete fT2[i];
00258 delete fL2;
00259 delete fL1;
00260 delete fF3;
00261 delete fF1;
00262 delete fLH4;
00263 delete fLH3;
00264 delete fLH2;
00265 delete fLH1;
00266 }
00267
00268
00269
00270 void CfgEdit::CloseWindow() { delete this; }
00271
00272
00273
00274 void CfgEdit::Cancel()
00275 {
00276 this->SendCloseMessage();
00277 }
00278
00279
00280
00281 void CfgEdit::Done()
00282 {
00283 this->Apply();
00284 this->SendCloseMessage();
00285 }
00286
00287
00288
00289 void CfgEdit::Apply()
00290 {
00291 this->Edit();
00292 IoModule::Instance()->Reload();
00293 }
00294