TStructNodeEditor.cxx

Go to the documentation of this file.
00001 // @(#)root/gviz3d:$Id: TStructNodeEditor.cxx 35362 2010-09-17 12:21:26Z brun $
00002 // Author: Tomasz Sosnicki   18/09/09
00003 
00004 /************************************************************************
00005 * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers.               *
00006 * All rights reserved.                                                  *
00007 *                                                                       *
00008 * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010 *************************************************************************/
00011 
00012 
00013 #include "TStructNodeEditor.h"
00014 #include "TStructNode.h"
00015 #include "TStructNodeProperty.h"
00016 
00017 #include <TGColorSelect.h>
00018 #include <TColor.h>
00019 #include <TGNumberEntry.h>
00020 #include <TGLabel.h>
00021 #include <TGTextEntry.h>
00022 #include <TClass.h>
00023 
00024 ClassImp(TStructNodeEditor)
00025 
00026 //________________________________________________________________________
00027 //////////////////////////////////////////////////////////////////////////
00028 // 
00029 // TStructNodeEditor is an editor for changing node attributes such as 
00030 // maximum numbers of level or maximum number of objects diplayed if this 
00031 // node is our top node. We can also change color associated with a class
00032 // or chagne color to default. 
00033 // 
00034 //////////////////////////////////////////////////////////////////////////
00035 
00036 //______________________________________________________________________________
00037 TStructNodeEditor::TStructNodeEditor(TList* colors, const TGWindow *p, Int_t width, Int_t height, UInt_t options, Pixel_t back)
00038    : TGedFrame(p, width, height, options | kVerticalFrame, back), fColors(colors)
00039 {
00040    // Constructor of node attributes GUI.
00041 
00042    MakeTitle("TStructNode");
00043    fInit = kFALSE;
00044 
00045    TGLayoutHints* expandX = new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,5,5);
00046    fNodeNameLabel = new TGLabel(this, "No node selected");
00047    this->AddFrame(fNodeNameLabel, expandX);
00048 
00049    fTypeName = new TGLabel(this);
00050    
00051    this->AddFrame(fTypeName, expandX);
00052 
00053    TGHorizontalFrame* maxObjectsFrame = new TGHorizontalFrame(this);
00054    TGLabel* fMaxObjectslabel = new TGLabel(maxObjectsFrame, "Max objects:");
00055    maxObjectsFrame->AddFrame(fMaxObjectslabel);
00056 
00057    fMaxObjectsNumberEntry = new TGNumberEntry(maxObjectsFrame, 0);
00058    fMaxObjectsNumberEntry->SetFormat(TGNumberEntry::kNESInteger);
00059    fMaxObjectsNumberEntry->SetLimits(TGNumberEntry::kNELLimitMin, 1);
00060    fMaxObjectsNumberEntry->SetState(kFALSE);
00061    fMaxObjectsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxObjectsValueSetSlot(Long_t)");
00062    maxObjectsFrame->AddFrame(fMaxObjectsNumberEntry);
00063    this->AddFrame(maxObjectsFrame, expandX);
00064 
00065    TGHorizontalFrame* maxLevelFrame = new TGHorizontalFrame(this);
00066    TGLabel* fMaxLevelsLabel = new TGLabel(maxLevelFrame, "Max levels:");
00067    maxLevelFrame->AddFrame(fMaxLevelsLabel);
00068    fMaxLevelsNumberEntry = new TGNumberEntry(maxLevelFrame, 0);
00069    fMaxLevelsNumberEntry->SetLimits(TGNumberEntry::kNELLimitMin, 1);
00070    fMaxLevelsNumberEntry->SetFormat(TGNumberEntry::kNESInteger);
00071    fMaxLevelsNumberEntry->SetState(kFALSE);
00072    fMaxLevelsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxLevelsValueSetSlot(Long_t)");
00073    maxLevelFrame->AddFrame(fMaxLevelsNumberEntry);
00074    this->AddFrame(maxLevelFrame, expandX);
00075 
00076    fNameEntry = new TGTextEntry(this, fName.Data());
00077    this->AddFrame(fNameEntry, expandX);
00078    fNameEntry->SetState(kFALSE);
00079 
00080    fColorSelect = new TGColorSelect(this);
00081    fColorSelect->Connect("ColorSelected(Pixel_t)", "TStructNodeEditor", this, "ColorSelectedSlot(Pixel_t)");
00082    this->AddFrame(fColorSelect, expandX);
00083    fColorSelect->SetEnabled(kFALSE);
00084 
00085    fAutoRefesh = new TGCheckButton(this, "Auto refesh");
00086    fAutoRefesh->SetOn();
00087    fAutoRefesh->Connect("Toggled(Bool_t)", "TStructNodeEditor", this, "AutoRefreshButtonSlot(Bool_t)");
00088    fAutoRefesh->SetEnabled(kFALSE);
00089    this->AddFrame(fAutoRefesh, expandX);
00090 
00091    fDefaultButton = new TGTextButton(this, "Default color");
00092    fDefaultButton->Connect("Clicked()", "TStructNodeEditor", this, "DefaultButtonSlot()");
00093    this->AddFrame(fDefaultButton, expandX);
00094    fDefaultButton->SetEnabled(kFALSE);
00095 
00096 
00097    fApplyButton = new TGTextButton(this, "Apply");
00098    fApplyButton->Connect("Clicked()", "TStructNodeEditor", this, "ApplyButtonSlot()");
00099    fApplyButton->SetEnabled(kFALSE);
00100    this->AddFrame(fApplyButton, expandX);
00101 }
00102 
00103 //______________________________________________________________________________
00104 TStructNodeEditor::~TStructNodeEditor()
00105 { 
00106    // Destructor of node editor.
00107 }
00108 
00109 //________________________________________________________________________
00110 void TStructNodeEditor::ApplyButtonSlot()
00111 {
00112    // ApplyButton Slot. Activated when user press Apply button. Sets properties of a node
00113 
00114    Bool_t needReset = false;
00115 
00116    if ((Int_t)(fNode->GetMaxLevel()) != fMaxLevelsNumberEntry->GetIntNumber()) {
00117       fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
00118       needReset = true;
00119    }
00120 
00121    if ((Int_t)(fNode->GetMaxObjects()) != fMaxObjectsNumberEntry->GetIntNumber()) {
00122       fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
00123       needReset = true;
00124    }
00125 
00126    if (fSelectedPropert) {
00127       fSelectedPropert->SetColor(fColorSelect->GetColor());
00128       fSelectedPropert->SetName(fNameEntry->GetText());
00129    }
00130 
00131    Update(needReset);
00132 }
00133 
00134 //________________________________________________________________________
00135 void TStructNodeEditor::AutoRefreshButtonSlot(Bool_t on)
00136 {
00137    // Activated when user chage condition
00138 
00139    if (on) {
00140       Update(kTRUE);
00141    }
00142 }
00143 
00144 //______________________________________________________________________________
00145 void TStructNodeEditor::ColorSelectedSlot(Pixel_t color)
00146 {
00147    // Slot connected to the fill area color.
00148 
00149    if (fAvoidSignal) {
00150       return;
00151    }
00152 
00153    TStructNodeProperty* prop = FindNodeProperty(fNode);
00154    if (prop) {
00155       prop->SetColor(color);
00156    } else {
00157       // add property
00158       prop = new TStructNodeProperty(fNode->GetTypeName(), color);
00159       fColors->Add(prop);
00160       fColors->Sort();
00161       fSelectedPropert = prop;
00162       fNameEntry->SetText(fNode->GetTypeName());
00163    }
00164    Update();
00165 }
00166 
00167 //________________________________________________________________________
00168 void TStructNodeEditor::DefaultButtonSlot()
00169 {
00170    // Slot for Defaulf button. Sets color of class to default
00171 
00172    if (TStructNodeProperty* prop = FindNodeProperty(fNode)) {
00173       fColors->Remove(prop);
00174       fSelectedPropert = GetDefaultProperty();
00175       fNameEntry->SetText(fSelectedPropert->GetName());
00176       fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
00177       Update();
00178    }
00179 }
00180 
00181 //________________________________________________________________________
00182 TStructNodeProperty* TStructNodeEditor::FindNodeProperty(TStructNode* node)
00183 {
00184    // Retruns property associated to the class of given node "node". If property isn't found
00185    // then returns NULL
00186 
00187    TIter it(fColors);
00188    TStructNodeProperty* prop;
00189    while ((prop = (TStructNodeProperty*) it() )) {
00190       TString propName(prop->GetName());
00191       if (propName.EndsWith("+")) {
00192 
00193          if (TClass* cl = TClass::GetClass(node->GetTypeName())) {
00194             propName.Remove(propName.Length()-1, 1);
00195             if (cl->InheritsFrom(propName.Data())) {
00196                return prop;
00197             }
00198          }
00199       } else {
00200          if (propName == TString(node->GetTypeName())) {
00201             return prop;
00202          }
00203       }
00204    }
00205 
00206    return NULL;
00207 }
00208 
00209 //________________________________________________________________________
00210 TStructNodeProperty* TStructNodeEditor::GetDefaultProperty()
00211 {
00212    // Returns property with default color 
00213 
00214    return (TStructNodeProperty*)fColors->Last();
00215 }
00216 
00217 //________________________________________________________________________
00218 void TStructNodeEditor::Init()
00219 {
00220    // Enables button and fields
00221 
00222    fMaxObjectsNumberEntry->SetState(kTRUE);
00223    fMaxLevelsNumberEntry->SetState(kTRUE);
00224    fNameEntry->SetState(kTRUE);
00225    fColorSelect->SetEnabled(kTRUE);
00226    fDefaultButton->SetEnabled(kTRUE);
00227    fApplyButton->SetEnabled(kTRUE);
00228    fAutoRefesh->SetEnabled(kTRUE);
00229    fInit = kTRUE;
00230 }
00231 
00232 //________________________________________________________________________
00233 void TStructNodeEditor::MaxLevelsValueSetSlot(Long_t)
00234 {
00235    // Emmited when user changes maximum number of levels
00236 
00237    fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
00238 
00239    if(fAutoRefesh->IsOn()) {
00240       Update(kTRUE);
00241    }
00242 }
00243 
00244 //________________________________________________________________________
00245 void TStructNodeEditor::MaxObjectsValueSetSlot(Long_t)
00246 {
00247    // Emmited when user changes maximum number of objects
00248 
00249    fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
00250 
00251    if(fAutoRefesh->IsOn()) {
00252       Update(kTRUE);
00253    }
00254 }
00255 
00256 //________________________________________________________________________
00257 void TStructNodeEditor::SetModel(TObject* obj)
00258 {
00259    // Pick up the used node attributes.
00260 
00261    fNode = dynamic_cast<TStructNode *>(obj);
00262    if (!fNode) return;
00263 
00264    // Add max level
00265    fMaxLevelsNumberEntry->SetIntNumber(fNode->GetMaxLevel());
00266 
00267    // Add max objects
00268    fMaxObjectsNumberEntry->SetIntNumber(fNode->GetMaxObjects());
00269 
00270    // Type label
00271    fTypeName->SetText(fNode->GetTypeName());
00272 
00273    // name label
00274    fNodeNameLabel->SetText(fNode->GetName());
00275 
00276    // Add color property
00277    fSelectedPropert = FindNodeProperty(fNode);
00278    if (!fSelectedPropert)
00279    {
00280       fSelectedPropert = GetDefaultProperty();
00281    }
00282    fNameEntry->SetText(fSelectedPropert->GetName());
00283    fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
00284 
00285    if (!fInit) {
00286       Init();
00287    }
00288 }
00289 
00290 //________________________________________________________________________
00291 void TStructNodeEditor::Update()
00292 {
00293    // Signal emmited when color or other property like number of level is changed
00294    // without camera reset
00295 
00296    Emit("Update(Bool_t)", false);
00297 }
00298 
00299 //________________________________________________________________________
00300 void TStructNodeEditor::Update(Bool_t resetCamera)
00301 {
00302    // Signal emmited when color or other property like number of level is changed.
00303    // If "resetCamera" is true, then current camera is reset.
00304 
00305    Emit("Update(Bool_t)", resetCamera);
00306 }

Generated on Tue Jul 5 14:19:17 2011 for ROOT_528-00b_version by  doxygen 1.5.1