00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <iostream>
00016 #include <sstream>
00017 #include <sigc++/sigc++.h>
00018 #include <boost/bind.hpp>
00019 #include "TClass.h"
00020 #include "TGFrame.h"
00021 #include "TGTab.h"
00022 #include "TGButton.h"
00023 #include "TGLabel.h"
00024 #include "TGString.h"
00025 #include "TColor.h"
00026 #include "TG3DLine.h"
00027 #include "TGNumberEntry.h"
00028 #include "TGTextEntry.h"
00029 #include "TGTextView.h"
00030 #include "TGLayout.h"
00031 #include "TGFont.h"
00032 #include "TEveManager.h"
00033 #include "TGSlider.h"
00034 #include "TGMsgBox.h"
00035 #include "TGComboBox.h"
00036
00037
00038 #include "Fireworks/Core/interface/CmsShowEDI.h"
00039 #include "Fireworks/Core/interface/FWSelectionManager.h"
00040 #include "Fireworks/Core/interface/FWDisplayProperties.h"
00041 #include "Fireworks/Core/interface/FWEventItem.h"
00042 #include "Fireworks/Core/src/FWColorSelect.h"
00043 #include "Fireworks/Core/interface/FWModelChangeSignal.h"
00044 #include "Fireworks/Core/interface/FWModelExpressionSelector.h"
00045 #include "Fireworks/Core/interface/FWModelChangeManager.h"
00046 #include "Fireworks/Core/interface/FWColorManager.h"
00047 #include "Fireworks/Core/interface/FWExpressionException.h"
00048 #include "Fireworks/Core/src/FWGUIValidatingTextEntry.h"
00049 #include "Fireworks/Core/src/FWExpressionValidator.h"
00050 #include "Fireworks/Core/src/FWDialogBuilder.h"
00051
00052
00053
00055
00056
00057
00058
00059
00060
00061
00062
00063 CmsShowEDI::CmsShowEDI(const TGWindow* p, UInt_t w, UInt_t h, FWSelectionManager* selMgr, FWColorManager* colorMgr) :
00064 TGTransientFrame(gClient->GetDefaultRoot(),p, w, h),
00065 m_item(0),
00066 m_validator( new FWExpressionValidator),
00067 m_colorManager(colorMgr)
00068 {
00069 m_selectionManager = selMgr;
00070 SetCleanup(kDeepCleanup);
00071
00072 m_selectionManager->itemSelectionChanged_.connect(boost::bind(&CmsShowEDI::fillEDIFrame,this));
00073
00074 TGVerticalFrame* vf = new TGVerticalFrame(this);
00075 AddFrame(vf, new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 0, 0, 0, 0));
00076 FWDialogBuilder builder(vf);
00077
00078 builder.indent(0)
00079 .addLabel(" ", 14, 2, &m_objectLabel)
00080 .vSpacer()
00081 .tabs(&m_tabs)
00082 .beginTab("Graphics")
00083 .indent(3)
00084 .addLabel("Color", 8)
00085 .addColorPicker(colorMgr, &m_colorSelectWidget).expand(false)
00086 .addHSeparator()
00087 .addLabel("Opacity", 8)
00088 .addHSlider(150, &m_opacitySlider)
00089 .addHSeparator()
00090 .addCheckbox("Visible", &m_isVisibleButton)
00091 .addHSeparator()
00092 .addLabel("Drawing order", 8)
00093 .addTextButton("To back", &m_backButton).floatLeft().expand(false)
00094 .addNumberEntry(0.0, 4, TGNumberFormat::kNESInteger,
00095 FWEventItem::minLayerValue(),
00096 FWEventItem::maxLayerValue(),
00097 &m_layerEntry).expand(false).floatLeft()
00098 .addTextButton("To front", &m_frontButton).expand(false)
00099 .vSpacer()
00100 .endTab()
00101 .beginTab("Filter")
00102 .indent(3)
00103 .addLabel("Expression", 8)
00104 .addValidatingTextEntry(0, &m_filterExpressionEntry).floatLeft()
00105 .addTextButton("Filter", &m_filterButton).expand(false)
00106 .addTextView("", &m_filterError)
00107 .vSpacer()
00108 .endTab()
00109 .beginTab("Select")
00110 .indent(3)
00111 .addLabel("Expression", 8)
00112 .addValidatingTextEntry(0, &m_selectExpressionEntry)
00113 .addTextButton("Select", &m_selectButton).floatLeft().expand(false)
00114 .addTextButton("Select all", &m_selectAllButton).expand(false)
00115 .addTextView("", &m_selectError)
00116 .vSpacer()
00117 .endTab()
00118 .beginTab("Data")
00119 .indent(3)
00120 .addLabel("Name:", 8)
00121 .addTextEntry("None", &m_nameEntry)
00122 .addLabel("Labels:", 8)
00123 .addLabel("Type:", 8)
00124 .addTextEntry("None", &m_typeEntry)
00125 .addLabel("Module:", 8)
00126 .addTextEntry("None", &m_moduleEntry)
00127 .addLabel("Instance:", 8)
00128 .addTextEntry("None", &m_instanceEntry)
00129 .addLabel("Process:", 8)
00130 .addTextEntry("None", &m_processEntry)
00131 .addHSeparator()
00132 .addTextButton("Remove collection", &m_removeButton).expand(false)
00133 .vSpacer()
00134 .endTab()
00135 .untabs();
00136
00137 m_filterError->SetForegroundColor(gVirtualX->GetPixel(kRed));
00138 m_filterError->SetBackgroundColor(TGFrame::GetDefaultFrameBackground());
00139 m_filterError->ChangeOptions(0);
00140
00141 m_selectError->SetForegroundColor(gVirtualX->GetPixel(kRed));
00142 m_selectError->SetBackgroundColor(TGFrame::GetDefaultFrameBackground());
00143 m_selectError->ChangeOptions(0);
00144
00145 m_filterExpressionEntry->setValidator(m_validator);
00146 m_selectExpressionEntry->setValidator(m_validator);
00147
00148 m_colorSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowEDI", this, "changeItemColor(Color_t)");
00149 m_opacitySlider->Connect("PositionChanged(Int_t)", "CmsShowEDI", this, "changeItemOpacity(Int_t)");
00150 m_isVisibleButton->Connect("Toggled(Bool_t)", "CmsShowEDI", this, "toggleItemVisible(Bool_t)");
00151 m_filterExpressionEntry->Connect("ReturnPressed()", "CmsShowEDI", this, "runFilter()");
00152 m_filterButton->Connect("Clicked()", "CmsShowEDI", this, "runFilter()");
00153 m_selectExpressionEntry->Connect("ReturnPressed()", "CmsShowEDI", this, "runSelection()");
00154 m_selectButton->Connect("Clicked()", "CmsShowEDI", this, "runSelection()");
00155 m_removeButton->Connect("Clicked()", "CmsShowEDI", this, "removeItem()");
00156 m_selectAllButton->Connect("Clicked()", "CmsShowEDI", this, "selectAll()");
00157 m_frontButton->Connect("Clicked()","CmsShowEDI",this,"moveToFront()");
00158 m_backButton->Connect("Clicked()","CmsShowEDI",this,"moveToBack()");
00159 m_layerEntry->Connect("ValueSet(Long_t)","CmsShowEDI",this,"moveToLayer(Long_t)");
00160
00161 SetWindowName("Collection Controller");
00162 MapSubwindows();
00163 Resize(GetDefaultSize());
00164 Layout();
00165
00166 fillEDIFrame();
00167 }
00168
00169
00170
00171
00172
00173
00174 CmsShowEDI::~CmsShowEDI()
00175 {
00176 disconnectAll();
00177 m_colorSelectWidget->Disconnect("ColorSelected(Pixel_t)", this, "changeItemColor(Pixel_t)");
00178 m_opacitySlider->Disconnect("PositionChanged(Int_t)", this, "changeItemColor");
00179 m_isVisibleButton->Disconnect("Toggled(Bool_t)", this, "toggleItemVisible(Bool_t)");
00180 m_filterExpressionEntry->Disconnect("ReturnPressed()", this, "runFilter()");
00181 m_selectExpressionEntry->Disconnect("ReturnPressed()", this, "runSelection()");
00182 m_filterButton->Disconnect("Clicked()", this, "runFilter()");
00183 m_selectButton->Disconnect("Clicked()", this, "runSelection()");
00184 m_selectAllButton->Disconnect("Clicked()", this, "selectAll()");
00185 m_removeButton->Disconnect("Clicked()", this, "removeItem()");
00186 m_frontButton->Disconnect("Clicked()",this,"moveToFront()");
00187 m_backButton->Disconnect("Clicked()",this,"moveToBack()");
00188 m_layerEntry->Disconnect("ValueSet(Long_t)",this,"moveToLayer(Long_t)");
00189
00190
00191
00192 delete m_validator;
00193 }
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 void
00211 CmsShowEDI::fillEDIFrame() {
00212 FWEventItem* iItem =0;
00213 bool multipleCollections = false;
00214 if(!m_selectionManager->selectedItems().empty()) {
00215 if(m_selectionManager->selectedItems().size()==1) {
00216 iItem=*(m_selectionManager->selectedItems().begin());
00217 } else {
00218 multipleCollections=true;
00219 }
00220 }
00221
00222 if (0 == m_item || iItem != m_item) {
00223 disconnectAll();
00224 m_item = iItem;
00225 if(0 != m_item) {
00226 const FWDisplayProperties &p = iItem->defaultDisplayProperties();
00227 m_objectLabel->SetText(iItem->name().c_str());
00228 m_colorSelectWidget->SetColorByIndex(p.color(),kFALSE);
00229 m_opacitySlider->SetPosition(100 - p.transparency());
00230 m_isVisibleButton->SetDisabledAndSelected(p.isVisible());
00231 m_validator->setType(ROOT::Reflex::Type::ByTypeInfo(*(iItem->modelType()->GetTypeInfo())));
00232 m_filterExpressionEntry->SetText(iItem->filterExpression().c_str());
00233 m_filterError->Clear();
00234 m_selectError->Clear();
00235 m_nameEntry->SetText(iItem->name().c_str());
00236 m_typeEntry->SetText(iItem->type()->GetName());
00237 m_moduleEntry->SetText(iItem->moduleLabel().c_str());
00238 m_instanceEntry->SetText(iItem->productInstanceLabel().c_str());
00239 m_processEntry->SetText(iItem->processName().c_str());
00240
00241 m_colorSelectWidget->SetEnabled(kTRUE);
00242 m_opacitySlider->SetEnabled(kTRUE);
00243 m_isVisibleButton->SetEnabled(kTRUE);
00244 m_filterExpressionEntry->SetEnabled(kTRUE);
00245 m_selectExpressionEntry->SetEnabled(kTRUE);
00246 m_filterButton->SetEnabled(kTRUE);
00247 m_selectButton->SetEnabled(kTRUE);
00248 m_selectAllButton->SetEnabled(kTRUE);
00249 m_removeButton->SetEnabled(kTRUE);
00250 updateLayerControls();
00251 m_layerEntry->SetState(kTRUE);
00252 m_displayChangedConn = m_item->defaultDisplayPropertiesChanged_.connect(boost::bind(&CmsShowEDI::updateDisplay, this));
00253 m_modelChangedConn = m_item->changed_.connect(boost::bind(&CmsShowEDI::updateFilter, this));
00254
00255 m_destroyedConn = m_item->goingToBeDestroyed_.connect(boost::bind(&CmsShowEDI::disconnectAll, this));
00256 } else if(multipleCollections) {
00257 std::ostringstream s;
00258 s<<m_selectionManager->selectedItems().size()<<" Collections Selected";
00259 m_objectLabel->SetText(s.str().c_str());
00260 }
00261
00262 Resize(GetDefaultSize());
00263 Layout();
00264 }
00265 }
00266
00267 void
00268 CmsShowEDI::removeItem() {
00269 Int_t chosen=0;
00270 std::string message("This action will remove the ");
00271 message += m_item->name();
00272 message +=" collection from the display."
00273 "\nIf you wish to return the collection you would have to use the 'Add Collection' window.";
00274 new TGMsgBox(gClient->GetDefaultRoot(),
00275 this,
00276 "Remove Collection Confirmation",
00277 message.c_str(),
00278 kMBIconExclamation,
00279 kMBCancel | kMBApply,
00280 &chosen);
00281 if(kMBApply == chosen) {
00282 m_item->destroy();
00283 m_item = 0;
00284
00285 gEve->EditElement(0);
00286 gEve->Redraw3D();
00287 }
00288 }
00289
00290 void
00291 CmsShowEDI::updateDisplay() {
00292
00293 const FWDisplayProperties &props = m_item->defaultDisplayProperties();
00294 m_colorSelectWidget->SetColorByIndex(props.color(),kFALSE);
00295 m_opacitySlider->SetPosition(100 - props.transparency());
00296 m_isVisibleButton->SetState(props.isVisible() ? kButtonDown : kButtonUp, kFALSE);
00297 }
00298
00299 void
00300 CmsShowEDI::updateLayerControls()
00301 {
00302 m_backButton->SetEnabled(!m_item->isInBack());
00303 m_frontButton->SetEnabled(!m_item->isInFront());
00304 m_layerEntry->SetIntNumber(m_item->layer());
00305 }
00306 void
00307 CmsShowEDI::moveToBack()
00308 {
00309 m_item->moveToBack();
00310 updateLayerControls();
00311 }
00312 void
00313 CmsShowEDI::moveToFront()
00314 {
00315 m_item->moveToFront();
00316 updateLayerControls();
00317 }
00318 void
00319 CmsShowEDI::moveToLayer(Long_t)
00320 {
00321 m_item->moveToLayer(static_cast<Int_t>(m_layerEntry->GetIntNumber()));
00322 updateLayerControls();
00323 }
00324
00325 void
00326 CmsShowEDI::updateFilter() {
00327 m_filterExpressionEntry->SetText(m_item->filterExpression().c_str());
00328 }
00329
00330 void
00331 CmsShowEDI::disconnectAll() {
00332 m_objectLabel->SetText("No Collection Selected");
00333 if(0 != m_item) {
00334 m_displayChangedConn.disconnect();
00335 m_modelChangedConn.disconnect();
00336 m_destroyedConn.disconnect();
00337 m_item = 0;
00338 m_colorSelectWidget->SetColorByIndex(0,kFALSE);
00339 m_opacitySlider->SetPosition(100);
00340 m_isVisibleButton->SetDisabledAndSelected(kTRUE);
00341 m_filterExpressionEntry->SetText(0);
00342 m_selectExpressionEntry->SetText(0);
00343 m_nameEntry->SetText(0);
00344 m_typeEntry->SetText(0);
00345 m_moduleEntry->SetText(0);
00346 m_instanceEntry->SetText(0);
00347 m_processEntry->SetText(0);
00348
00349 m_colorSelectWidget->SetEnabled(kFALSE);
00350 m_opacitySlider->SetEnabled(kFALSE);
00351
00352 m_isVisibleButton->SetEnabled(kFALSE);
00353 m_filterExpressionEntry->SetEnabled(kFALSE);
00354 m_filterButton->SetEnabled(kFALSE);
00355 m_selectExpressionEntry->SetEnabled(kFALSE);
00356 m_selectButton->SetEnabled(kFALSE);
00357 m_selectAllButton->SetEnabled(kFALSE);
00358 m_removeButton->SetEnabled(kFALSE);
00359 m_backButton->SetEnabled(kFALSE);
00360 m_frontButton->SetEnabled(kFALSE);
00361 m_layerEntry->SetIntNumber(0);
00362 m_layerEntry->SetState(kFALSE);
00363 m_layerEntry->GetNumberEntry()->SetEnabled(kFALSE);
00364 m_layerEntry->GetButtonUp()->SetEnabled(kFALSE);
00365 m_layerEntry->GetButtonDown()->SetEnabled(kFALSE);
00366 }
00367 }
00368
00375 void
00376 CmsShowEDI::changeItemColor(Color_t color) {
00377 FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
00378 changeProperties.setColor(color);
00379 m_item->setDefaultDisplayProperties(changeProperties);
00380 }
00381
00383 void
00384 CmsShowEDI::toggleItemVisible(Bool_t on) {
00385 FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
00386 changeProperties.setIsVisible(on);
00387 m_item->setDefaultDisplayProperties(changeProperties);
00388 }
00389
00397 void
00398 CmsShowEDI::changeItemOpacity(Int_t opacity) {
00399 FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
00400 changeProperties.setTransparency(100 - opacity);
00401 m_item->setDefaultDisplayProperties(changeProperties);
00402 }
00403
00404 void
00405 CmsShowEDI::runFilter() {
00406 const std::string filter(m_filterExpressionEntry->GetText());
00407 if (m_item != 0) {
00408 try {
00409 m_filterError->Clear();
00410 m_item->setFilterExpression(filter);
00411 } catch( const FWExpressionException& e) {
00412 m_filterError->AddLine(e.what().c_str());
00413 m_filterError->Update();
00414 if(e.column() > -1) {
00415 m_filterExpressionEntry->SetCursorPosition(e.column());
00416 }
00417 }
00418 }
00419 }
00420
00421
00422
00423 void
00424 CmsShowEDI::runSelection() {
00425 FWModelExpressionSelector selector;
00426 const std::string selection(m_selectExpressionEntry->GetText());
00427 if (m_item != 0){
00428 try {
00429 m_selectError->Clear();
00430
00431
00432 FWEventItem* item = m_item;
00433 item->selectionManager()-> clearModelSelectionLeaveItem();
00434
00435 selector.select(item, selection);
00436 } catch( const FWExpressionException& e) {
00437 m_selectError->AddLine(e.what().c_str());
00438 m_selectError->Update();
00439 if(e.column() > -1) {
00440 m_selectExpressionEntry->SetCursorPosition(e.column());
00441 }
00442 }
00443 }
00444 }
00445
00446 void
00447 CmsShowEDI::selectAll() {
00448 FWChangeSentry sentry(*(m_item->changeManager()));
00449 for (int i = 0; i < static_cast<int>(m_item->size()); i++) {
00450 m_item->select(i);
00451 }
00452 }
00453 void
00454 CmsShowEDI::show(FWDataCategories iToView)
00455 {
00456 m_tabs->SetTab(iToView);
00457 }
00458
00459
00460 void
00461 CmsShowEDI::colorSetChanged()
00462 {
00463 if (m_item)
00464 {
00465 const FWDisplayProperties &p = m_item->defaultDisplayProperties();
00466 m_colorSelectWidget->SetColorByIndex(p.color(),kFALSE);
00467 }
00468 }