ROOT logo
// @(#)root/gviz3d:$Id: TStructNodeEditor.cxx 30023 2009-09-02 17:57:16Z brun $
// Author: Tomasz Sosnicki   18/09/09

/************************************************************************
* Copyright (C) 1995-2009, Rene Brun and Fons Rademakers.               *
* All rights reserved.                                                  *
*                                                                       *
* For the licensing terms see $ROOTSYS/LICENSE.                         *
* For the list of contributors see $ROOTSYS/README/CREDITS.             *
*************************************************************************/


#include "TStructNodeEditor.h"
#include "TStructNode.h"
#include "TStructNodeProperty.h"

#include <TGColorSelect.h>
#include <TColor.h>
#include <TGNumberEntry.h>
#include <TGLabel.h>
#include <TGTextEntry.h>
#include <TClass.h>

ClassImp(TStructNodeEditor)

//________________________________________________________________________
//////////////////////////////////////////////////////////////////////////
// 
// TStructNodeEditor is an editor for changing node attributes such as 
// maximum numbers of level or maximum number of objects diplayed if this 
// node is our top node. We can also change color associated with a class
// or chagne color to default. 
// 
//////////////////////////////////////////////////////////////////////////

//______________________________________________________________________________
TStructNodeEditor::TStructNodeEditor(TList* colors, const TGWindow *p, Int_t width, Int_t height, UInt_t options, Pixel_t back)
   : TGedFrame(p, width, height, options | kVerticalFrame, back), fColors(colors)
{
   // Constructor of node attributes GUI.

   MakeTitle("TStructNode");
   fInit = kFALSE;

   TGLayoutHints* expandX = new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,5,5);
   fNodeNameLabel = new TGLabel(this, "No node selected");
   this->AddFrame(fNodeNameLabel, expandX);

   fTypeName = new TGLabel(this);
   
   this->AddFrame(fTypeName, expandX);

   TGHorizontalFrame* maxObjectsFrame = new TGHorizontalFrame(this);
   TGLabel* fMaxObjectslabel = new TGLabel(maxObjectsFrame, "Max objects:");
   maxObjectsFrame->AddFrame(fMaxObjectslabel);

   fMaxObjectsNumberEntry = new TGNumberEntry(maxObjectsFrame, 0);
   fMaxObjectsNumberEntry->SetFormat(TGNumberEntry::kNESInteger);
   fMaxObjectsNumberEntry->SetLimits(TGNumberEntry::kNELLimitMin, 1);
   fMaxObjectsNumberEntry->SetState(kFALSE);
   fMaxObjectsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxObjectsValueSetSlot(Long_t)");
   maxObjectsFrame->AddFrame(fMaxObjectsNumberEntry);
   this->AddFrame(maxObjectsFrame, expandX);

   TGHorizontalFrame* maxLevelFrame = new TGHorizontalFrame(this);
   TGLabel* fMaxLevelsLabel = new TGLabel(maxLevelFrame, "Max levels:");
   maxLevelFrame->AddFrame(fMaxLevelsLabel);
   fMaxLevelsNumberEntry = new TGNumberEntry(maxLevelFrame, 0);
   fMaxLevelsNumberEntry->SetLimits(TGNumberEntry::kNELLimitMin, 1);
   fMaxLevelsNumberEntry->SetFormat(TGNumberEntry::kNESInteger);
   fMaxLevelsNumberEntry->SetState(kFALSE);
   fMaxLevelsNumberEntry->Connect("ValueSet(Long_t)", "TStructNodeEditor", this, "MaxLevelsValueSetSlot(Long_t)");
   maxLevelFrame->AddFrame(fMaxLevelsNumberEntry);
   this->AddFrame(maxLevelFrame, expandX);

   fNameEntry = new TGTextEntry(this, fName.Data());
   this->AddFrame(fNameEntry, expandX);
   fNameEntry->SetState(kFALSE);

   fColorSelect = new TGColorSelect(this);
   fColorSelect->Connect("ColorSelected(Pixel_t)", "TStructNodeEditor", this, "ColorSelectedSlot(Pixel_t)");
   this->AddFrame(fColorSelect, expandX);
   fColorSelect->SetEnabled(kFALSE);

   fAutoRefesh = new TGCheckButton(this, "Auto refesh");
   fAutoRefesh->SetOn();
   fAutoRefesh->Connect("Toggled(Bool_t)", "TStructNodeEditor", this, "AutoRefreshButtonSlot(Bool_t)");
   fAutoRefesh->SetEnabled(kFALSE);
   this->AddFrame(fAutoRefesh, expandX);

   fDefaultButton = new TGTextButton(this, "Default color");
   fDefaultButton->Connect("Clicked()", "TStructNodeEditor", this, "DefaultButtonSlot()");
   this->AddFrame(fDefaultButton, expandX);
   fDefaultButton->SetEnabled(kFALSE);


   fApplyButton = new TGTextButton(this, "Apply");
   fApplyButton->Connect("Clicked()", "TStructNodeEditor", this, "ApplyButtonSlot()");
   fApplyButton->SetEnabled(kFALSE);
   this->AddFrame(fApplyButton, expandX);
}

//______________________________________________________________________________
TStructNodeEditor::~TStructNodeEditor()
{ 
   // Destructor of node editor.
}

//________________________________________________________________________
void TStructNodeEditor::ApplyButtonSlot()
{
   // ApplyButton Slot. Activated when user press Apply button. Sets properties of a node

   Bool_t needReset = false;

   if ((Int_t)(fNode->GetMaxLevel()) != fMaxLevelsNumberEntry->GetIntNumber()) {
      fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
      needReset = true;
   }

   if ((Int_t)(fNode->GetMaxObjects()) != fMaxObjectsNumberEntry->GetIntNumber()) {
      fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
      needReset = true;
   }

   if (fSelectedPropert) {
      fSelectedPropert->SetColor(fColorSelect->GetColor());
      fSelectedPropert->SetName(fNameEntry->GetText());
   }

   Update(needReset);
}

//________________________________________________________________________
void TStructNodeEditor::AutoRefreshButtonSlot(Bool_t on)
{
   // Activated when user chage condition

   if (on) {
      Update(kTRUE);
   }
}

//______________________________________________________________________________
void TStructNodeEditor::ColorSelectedSlot(Pixel_t color)
{
   // Slot connected to the fill area color.

   if (fAvoidSignal) {
      return;
   }

   TStructNodeProperty* prop = FindNodeProperty(fNode);
   if (prop) {
      prop->SetColor(color);
   } else {
      // add property
      prop = new TStructNodeProperty(fNode->GetTypeName(), color);
      fColors->Add(prop);
      fColors->Sort();
      fSelectedPropert = prop;
      fNameEntry->SetText(fNode->GetTypeName());
   }
   Update();
}

//________________________________________________________________________
void TStructNodeEditor::DefaultButtonSlot()
{
   // Slot for Defaulf button. Sets color of class to default

   if (TStructNodeProperty* prop = FindNodeProperty(fNode)) {
      fColors->Remove(prop);
      fSelectedPropert = GetDefaultProperty();
      fNameEntry->SetText(fSelectedPropert->GetName());
      fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
      Update();
   }
}

//________________________________________________________________________
TStructNodeProperty* TStructNodeEditor::FindNodeProperty(TStructNode* node)
{
   // Retruns property associated to the class of given node "node". If property isn't found
   // then returns NULL

   TIter it(fColors);
   TStructNodeProperty* prop;
   while ((prop = (TStructNodeProperty*) it() )) {
      TString propName(prop->GetName());
      if (propName.EndsWith("+")) {

         if (TClass* cl = TClass::GetClass(node->GetTypeName())) {
            propName.Remove(propName.Length()-1, 1);
            if (cl->InheritsFrom(propName.Data())) {
               return prop;
            }
         }
      } else {
         if (propName == TString(node->GetTypeName())) {
            return prop;
         }
      }
   }

   return NULL;
}

//________________________________________________________________________
TStructNodeProperty* TStructNodeEditor::GetDefaultProperty()
{
   // Returns property with default color 

   return (TStructNodeProperty*)fColors->Last();
}

//________________________________________________________________________
void TStructNodeEditor::Init()
{
   // Enables button and fields

   fMaxObjectsNumberEntry->SetState(kTRUE);
   fMaxLevelsNumberEntry->SetState(kTRUE);
   fNameEntry->SetState(kTRUE);
   fColorSelect->SetEnabled(kTRUE);
   fDefaultButton->SetEnabled(kTRUE);
   fApplyButton->SetEnabled(kTRUE);
   fAutoRefesh->SetEnabled(kTRUE);
   fInit = kTRUE;
}

//________________________________________________________________________
void TStructNodeEditor::MaxLevelsValueSetSlot(Long_t)
{
   // Emmited when user changes maximum number of levels

   fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());

   if(fAutoRefesh->IsOn()) {
      Update(kTRUE);
   }
}

//________________________________________________________________________
void TStructNodeEditor::MaxObjectsValueSetSlot(Long_t)
{
   // Emmited when user changes maximum number of objects

   fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());

   if(fAutoRefesh->IsOn()) {
      Update(kTRUE);
   }
}

//________________________________________________________________________
void TStructNodeEditor::SetModel(TObject* obj)
{
   // Pick up the used node attributes.

   fNode = dynamic_cast<TStructNode *>(obj);

   // Add max level
   fMaxLevelsNumberEntry->SetIntNumber(fNode->GetMaxLevel());

   // Add max objects
   fMaxObjectsNumberEntry->SetIntNumber(fNode->GetMaxObjects());

   // Type label
   fTypeName->SetText(fNode->GetTypeName());

   // name label
   fNodeNameLabel->SetText(fNode->GetName());

   // Add color property
   fSelectedPropert = FindNodeProperty(fNode);
   if (!fSelectedPropert)
   {
      fSelectedPropert = GetDefaultProperty();
   }
   fNameEntry->SetText(fSelectedPropert->GetName());
   fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);

   if (!fInit) {
      Init();
   }
}

//________________________________________________________________________
void TStructNodeEditor::Update()
{
   // Signal emmited when color or other property like number of level is changed
   // without camera reset

   Emit("Update(Bool_t)", false);
}

//________________________________________________________________________
void TStructNodeEditor::Update(Bool_t resetCamera)
{
   // Signal emmited when color or other property like number of level is changed.
   // If "resetCamera" is true, then current camera is reset.

   Emit("Update(Bool_t)", resetCamera);
}
 TStructNodeEditor.cxx:1
 TStructNodeEditor.cxx:2
 TStructNodeEditor.cxx:3
 TStructNodeEditor.cxx:4
 TStructNodeEditor.cxx:5
 TStructNodeEditor.cxx:6
 TStructNodeEditor.cxx:7
 TStructNodeEditor.cxx:8
 TStructNodeEditor.cxx:9
 TStructNodeEditor.cxx:10
 TStructNodeEditor.cxx:11
 TStructNodeEditor.cxx:12
 TStructNodeEditor.cxx:13
 TStructNodeEditor.cxx:14
 TStructNodeEditor.cxx:15
 TStructNodeEditor.cxx:16
 TStructNodeEditor.cxx:17
 TStructNodeEditor.cxx:18
 TStructNodeEditor.cxx:19
 TStructNodeEditor.cxx:20
 TStructNodeEditor.cxx:21
 TStructNodeEditor.cxx:22
 TStructNodeEditor.cxx:23
 TStructNodeEditor.cxx:24
 TStructNodeEditor.cxx:25
 TStructNodeEditor.cxx:26
 TStructNodeEditor.cxx:27
 TStructNodeEditor.cxx:28
 TStructNodeEditor.cxx:29
 TStructNodeEditor.cxx:30
 TStructNodeEditor.cxx:31
 TStructNodeEditor.cxx:32
 TStructNodeEditor.cxx:33
 TStructNodeEditor.cxx:34
 TStructNodeEditor.cxx:35
 TStructNodeEditor.cxx:36
 TStructNodeEditor.cxx:37
 TStructNodeEditor.cxx:38
 TStructNodeEditor.cxx:39
 TStructNodeEditor.cxx:40
 TStructNodeEditor.cxx:41
 TStructNodeEditor.cxx:42
 TStructNodeEditor.cxx:43
 TStructNodeEditor.cxx:44
 TStructNodeEditor.cxx:45
 TStructNodeEditor.cxx:46
 TStructNodeEditor.cxx:47
 TStructNodeEditor.cxx:48
 TStructNodeEditor.cxx:49
 TStructNodeEditor.cxx:50
 TStructNodeEditor.cxx:51
 TStructNodeEditor.cxx:52
 TStructNodeEditor.cxx:53
 TStructNodeEditor.cxx:54
 TStructNodeEditor.cxx:55
 TStructNodeEditor.cxx:56
 TStructNodeEditor.cxx:57
 TStructNodeEditor.cxx:58
 TStructNodeEditor.cxx:59
 TStructNodeEditor.cxx:60
 TStructNodeEditor.cxx:61
 TStructNodeEditor.cxx:62
 TStructNodeEditor.cxx:63
 TStructNodeEditor.cxx:64
 TStructNodeEditor.cxx:65
 TStructNodeEditor.cxx:66
 TStructNodeEditor.cxx:67
 TStructNodeEditor.cxx:68
 TStructNodeEditor.cxx:69
 TStructNodeEditor.cxx:70
 TStructNodeEditor.cxx:71
 TStructNodeEditor.cxx:72
 TStructNodeEditor.cxx:73
 TStructNodeEditor.cxx:74
 TStructNodeEditor.cxx:75
 TStructNodeEditor.cxx:76
 TStructNodeEditor.cxx:77
 TStructNodeEditor.cxx:78
 TStructNodeEditor.cxx:79
 TStructNodeEditor.cxx:80
 TStructNodeEditor.cxx:81
 TStructNodeEditor.cxx:82
 TStructNodeEditor.cxx:83
 TStructNodeEditor.cxx:84
 TStructNodeEditor.cxx:85
 TStructNodeEditor.cxx:86
 TStructNodeEditor.cxx:87
 TStructNodeEditor.cxx:88
 TStructNodeEditor.cxx:89
 TStructNodeEditor.cxx:90
 TStructNodeEditor.cxx:91
 TStructNodeEditor.cxx:92
 TStructNodeEditor.cxx:93
 TStructNodeEditor.cxx:94
 TStructNodeEditor.cxx:95
 TStructNodeEditor.cxx:96
 TStructNodeEditor.cxx:97
 TStructNodeEditor.cxx:98
 TStructNodeEditor.cxx:99
 TStructNodeEditor.cxx:100
 TStructNodeEditor.cxx:101
 TStructNodeEditor.cxx:102
 TStructNodeEditor.cxx:103
 TStructNodeEditor.cxx:104
 TStructNodeEditor.cxx:105
 TStructNodeEditor.cxx:106
 TStructNodeEditor.cxx:107
 TStructNodeEditor.cxx:108
 TStructNodeEditor.cxx:109
 TStructNodeEditor.cxx:110
 TStructNodeEditor.cxx:111
 TStructNodeEditor.cxx:112
 TStructNodeEditor.cxx:113
 TStructNodeEditor.cxx:114
 TStructNodeEditor.cxx:115
 TStructNodeEditor.cxx:116
 TStructNodeEditor.cxx:117
 TStructNodeEditor.cxx:118
 TStructNodeEditor.cxx:119
 TStructNodeEditor.cxx:120
 TStructNodeEditor.cxx:121
 TStructNodeEditor.cxx:122
 TStructNodeEditor.cxx:123
 TStructNodeEditor.cxx:124
 TStructNodeEditor.cxx:125
 TStructNodeEditor.cxx:126
 TStructNodeEditor.cxx:127
 TStructNodeEditor.cxx:128
 TStructNodeEditor.cxx:129
 TStructNodeEditor.cxx:130
 TStructNodeEditor.cxx:131
 TStructNodeEditor.cxx:132
 TStructNodeEditor.cxx:133
 TStructNodeEditor.cxx:134
 TStructNodeEditor.cxx:135
 TStructNodeEditor.cxx:136
 TStructNodeEditor.cxx:137
 TStructNodeEditor.cxx:138
 TStructNodeEditor.cxx:139
 TStructNodeEditor.cxx:140
 TStructNodeEditor.cxx:141
 TStructNodeEditor.cxx:142
 TStructNodeEditor.cxx:143
 TStructNodeEditor.cxx:144
 TStructNodeEditor.cxx:145
 TStructNodeEditor.cxx:146
 TStructNodeEditor.cxx:147
 TStructNodeEditor.cxx:148
 TStructNodeEditor.cxx:149
 TStructNodeEditor.cxx:150
 TStructNodeEditor.cxx:151
 TStructNodeEditor.cxx:152
 TStructNodeEditor.cxx:153
 TStructNodeEditor.cxx:154
 TStructNodeEditor.cxx:155
 TStructNodeEditor.cxx:156
 TStructNodeEditor.cxx:157
 TStructNodeEditor.cxx:158
 TStructNodeEditor.cxx:159
 TStructNodeEditor.cxx:160
 TStructNodeEditor.cxx:161
 TStructNodeEditor.cxx:162
 TStructNodeEditor.cxx:163
 TStructNodeEditor.cxx:164
 TStructNodeEditor.cxx:165
 TStructNodeEditor.cxx:166
 TStructNodeEditor.cxx:167
 TStructNodeEditor.cxx:168
 TStructNodeEditor.cxx:169
 TStructNodeEditor.cxx:170
 TStructNodeEditor.cxx:171
 TStructNodeEditor.cxx:172
 TStructNodeEditor.cxx:173
 TStructNodeEditor.cxx:174
 TStructNodeEditor.cxx:175
 TStructNodeEditor.cxx:176
 TStructNodeEditor.cxx:177
 TStructNodeEditor.cxx:178
 TStructNodeEditor.cxx:179
 TStructNodeEditor.cxx:180
 TStructNodeEditor.cxx:181
 TStructNodeEditor.cxx:182
 TStructNodeEditor.cxx:183
 TStructNodeEditor.cxx:184
 TStructNodeEditor.cxx:185
 TStructNodeEditor.cxx:186
 TStructNodeEditor.cxx:187
 TStructNodeEditor.cxx:188
 TStructNodeEditor.cxx:189
 TStructNodeEditor.cxx:190
 TStructNodeEditor.cxx:191
 TStructNodeEditor.cxx:192
 TStructNodeEditor.cxx:193
 TStructNodeEditor.cxx:194
 TStructNodeEditor.cxx:195
 TStructNodeEditor.cxx:196
 TStructNodeEditor.cxx:197
 TStructNodeEditor.cxx:198
 TStructNodeEditor.cxx:199
 TStructNodeEditor.cxx:200
 TStructNodeEditor.cxx:201
 TStructNodeEditor.cxx:202
 TStructNodeEditor.cxx:203
 TStructNodeEditor.cxx:204
 TStructNodeEditor.cxx:205
 TStructNodeEditor.cxx:206
 TStructNodeEditor.cxx:207
 TStructNodeEditor.cxx:208
 TStructNodeEditor.cxx:209
 TStructNodeEditor.cxx:210
 TStructNodeEditor.cxx:211
 TStructNodeEditor.cxx:212
 TStructNodeEditor.cxx:213
 TStructNodeEditor.cxx:214
 TStructNodeEditor.cxx:215
 TStructNodeEditor.cxx:216
 TStructNodeEditor.cxx:217
 TStructNodeEditor.cxx:218
 TStructNodeEditor.cxx:219
 TStructNodeEditor.cxx:220
 TStructNodeEditor.cxx:221
 TStructNodeEditor.cxx:222
 TStructNodeEditor.cxx:223
 TStructNodeEditor.cxx:224
 TStructNodeEditor.cxx:225
 TStructNodeEditor.cxx:226
 TStructNodeEditor.cxx:227
 TStructNodeEditor.cxx:228
 TStructNodeEditor.cxx:229
 TStructNodeEditor.cxx:230
 TStructNodeEditor.cxx:231
 TStructNodeEditor.cxx:232
 TStructNodeEditor.cxx:233
 TStructNodeEditor.cxx:234
 TStructNodeEditor.cxx:235
 TStructNodeEditor.cxx:236
 TStructNodeEditor.cxx:237
 TStructNodeEditor.cxx:238
 TStructNodeEditor.cxx:239
 TStructNodeEditor.cxx:240
 TStructNodeEditor.cxx:241
 TStructNodeEditor.cxx:242
 TStructNodeEditor.cxx:243
 TStructNodeEditor.cxx:244
 TStructNodeEditor.cxx:245
 TStructNodeEditor.cxx:246
 TStructNodeEditor.cxx:247
 TStructNodeEditor.cxx:248
 TStructNodeEditor.cxx:249
 TStructNodeEditor.cxx:250
 TStructNodeEditor.cxx:251
 TStructNodeEditor.cxx:252
 TStructNodeEditor.cxx:253
 TStructNodeEditor.cxx:254
 TStructNodeEditor.cxx:255
 TStructNodeEditor.cxx:256
 TStructNodeEditor.cxx:257
 TStructNodeEditor.cxx:258
 TStructNodeEditor.cxx:259
 TStructNodeEditor.cxx:260
 TStructNodeEditor.cxx:261
 TStructNodeEditor.cxx:262
 TStructNodeEditor.cxx:263
 TStructNodeEditor.cxx:264
 TStructNodeEditor.cxx:265
 TStructNodeEditor.cxx:266
 TStructNodeEditor.cxx:267
 TStructNodeEditor.cxx:268
 TStructNodeEditor.cxx:269
 TStructNodeEditor.cxx:270
 TStructNodeEditor.cxx:271
 TStructNodeEditor.cxx:272
 TStructNodeEditor.cxx:273
 TStructNodeEditor.cxx:274
 TStructNodeEditor.cxx:275
 TStructNodeEditor.cxx:276
 TStructNodeEditor.cxx:277
 TStructNodeEditor.cxx:278
 TStructNodeEditor.cxx:279
 TStructNodeEditor.cxx:280
 TStructNodeEditor.cxx:281
 TStructNodeEditor.cxx:282
 TStructNodeEditor.cxx:283
 TStructNodeEditor.cxx:284
 TStructNodeEditor.cxx:285
 TStructNodeEditor.cxx:286
 TStructNodeEditor.cxx:287
 TStructNodeEditor.cxx:288
 TStructNodeEditor.cxx:289
 TStructNodeEditor.cxx:290
 TStructNodeEditor.cxx:291
 TStructNodeEditor.cxx:292
 TStructNodeEditor.cxx:293
 TStructNodeEditor.cxx:294
 TStructNodeEditor.cxx:295
 TStructNodeEditor.cxx:296
 TStructNodeEditor.cxx:297
 TStructNodeEditor.cxx:298
 TStructNodeEditor.cxx:299
 TStructNodeEditor.cxx:300
 TStructNodeEditor.cxx:301
 TStructNodeEditor.cxx:302
 TStructNodeEditor.cxx:303
 TStructNodeEditor.cxx:304
 TStructNodeEditor.cxx:305