24 ClassImp(TStructNodeEditor);
39 TStructNodeEditor::TStructNodeEditor(TList* colors,
const TGWindow *p, Int_t width, Int_t height, UInt_t options, Pixel_t back)
40 : TGedFrame(p, width, height, options | kVerticalFrame, back), fColors(colors)
42 MakeTitle(
"TStructNode");
45 TGLayoutHints* expandX =
new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5,5,5,5);
46 fNodeNameLabel =
new TGLabel(
this,
"No node selected");
47 this->AddFrame(fNodeNameLabel, expandX);
49 fTypeName =
new TGLabel(
this);
51 this->AddFrame(fTypeName, expandX);
53 TGHorizontalFrame* maxObjectsFrame =
new TGHorizontalFrame(
this);
54 TGLabel* fMaxObjectslabel =
new TGLabel(maxObjectsFrame,
"Max objects:");
55 maxObjectsFrame->AddFrame(fMaxObjectslabel);
57 fMaxObjectsNumberEntry =
new TGNumberEntry(maxObjectsFrame, 0);
58 fMaxObjectsNumberEntry->SetFormat(TGNumberEntry::kNESInteger);
59 fMaxObjectsNumberEntry->SetLimits(TGNumberEntry::kNELLimitMin, 1);
60 fMaxObjectsNumberEntry->SetState(kFALSE);
61 fMaxObjectsNumberEntry->Connect(
"ValueSet(Long_t)",
"TStructNodeEditor",
this,
"MaxObjectsValueSetSlot(Long_t)");
62 maxObjectsFrame->AddFrame(fMaxObjectsNumberEntry);
63 this->AddFrame(maxObjectsFrame, expandX);
65 TGHorizontalFrame* maxLevelFrame =
new TGHorizontalFrame(
this);
66 TGLabel* fMaxLevelsLabel =
new TGLabel(maxLevelFrame,
"Max levels:");
67 maxLevelFrame->AddFrame(fMaxLevelsLabel);
68 fMaxLevelsNumberEntry =
new TGNumberEntry(maxLevelFrame, 0);
69 fMaxLevelsNumberEntry->SetLimits(TGNumberEntry::kNELLimitMin, 1);
70 fMaxLevelsNumberEntry->SetFormat(TGNumberEntry::kNESInteger);
71 fMaxLevelsNumberEntry->SetState(kFALSE);
72 fMaxLevelsNumberEntry->Connect(
"ValueSet(Long_t)",
"TStructNodeEditor",
this,
"MaxLevelsValueSetSlot(Long_t)");
73 maxLevelFrame->AddFrame(fMaxLevelsNumberEntry);
74 this->AddFrame(maxLevelFrame, expandX);
76 fNameEntry =
new TGTextEntry(
this, fName.Data());
77 this->AddFrame(fNameEntry, expandX);
78 fNameEntry->SetState(kFALSE);
80 fColorSelect =
new TGColorSelect(
this);
81 fColorSelect->Connect(
"ColorSelected(Pixel_t)",
"TStructNodeEditor",
this,
"ColorSelectedSlot(Pixel_t)");
82 this->AddFrame(fColorSelect, expandX);
83 fColorSelect->SetEnabled(kFALSE);
85 fAutoRefesh =
new TGCheckButton(
this,
"Auto refesh");
87 fAutoRefesh->Connect(
"Toggled(Bool_t)",
"TStructNodeEditor",
this,
"AutoRefreshButtonSlot(Bool_t)");
88 fAutoRefesh->SetEnabled(kFALSE);
89 this->AddFrame(fAutoRefesh, expandX);
91 fDefaultButton =
new TGTextButton(
this,
"Default color");
92 fDefaultButton->Connect(
"Clicked()",
"TStructNodeEditor",
this,
"DefaultButtonSlot()");
93 this->AddFrame(fDefaultButton, expandX);
94 fDefaultButton->SetEnabled(kFALSE);
97 fApplyButton =
new TGTextButton(
this,
"Apply");
98 fApplyButton->Connect(
"Clicked()",
"TStructNodeEditor",
this,
"ApplyButtonSlot()");
99 fApplyButton->SetEnabled(kFALSE);
100 this->AddFrame(fApplyButton, expandX);
106 TStructNodeEditor::~TStructNodeEditor()
113 void TStructNodeEditor::ApplyButtonSlot()
115 Bool_t needReset =
false;
117 if ((Int_t)(fNode->GetMaxLevel()) != fMaxLevelsNumberEntry->GetIntNumber()) {
118 fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
122 if ((Int_t)(fNode->GetMaxObjects()) != fMaxObjectsNumberEntry->GetIntNumber()) {
123 fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
127 if (fSelectedPropert) {
128 fSelectedPropert->SetColor(fColorSelect->GetColor());
129 fSelectedPropert->SetName(fNameEntry->GetText());
138 void TStructNodeEditor::AutoRefreshButtonSlot(Bool_t on)
148 void TStructNodeEditor::ColorSelectedSlot(Pixel_t color)
154 TStructNodeProperty* prop = FindNodeProperty(fNode);
156 prop->SetColor(color);
159 prop =
new TStructNodeProperty(fNode->GetTypeName(), color);
162 fSelectedPropert = prop;
163 fNameEntry->SetText(fNode->GetTypeName());
171 void TStructNodeEditor::DefaultButtonSlot()
173 if (TStructNodeProperty* prop = FindNodeProperty(fNode)) {
174 fColors->Remove(prop);
175 fSelectedPropert = GetDefaultProperty();
176 fNameEntry->SetText(fSelectedPropert->GetName());
177 fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
186 TStructNodeProperty* TStructNodeEditor::FindNodeProperty(TStructNode* node)
189 TStructNodeProperty* prop;
190 while ((prop = (TStructNodeProperty*) it() )) {
191 TString propName(prop->GetName());
192 if (propName.EndsWith(
"+")) {
194 if (TClass* cl = TClass::GetClass(node->GetTypeName())) {
195 propName.Remove(propName.Length()-1, 1);
196 if (cl->InheritsFrom(propName.Data())) {
201 if (propName == TString(node->GetTypeName())) {
213 TStructNodeProperty* TStructNodeEditor::GetDefaultProperty()
215 return (TStructNodeProperty*)fColors->Last();
221 void TStructNodeEditor::Init()
223 fMaxObjectsNumberEntry->SetState(kTRUE);
224 fMaxLevelsNumberEntry->SetState(kTRUE);
225 fNameEntry->SetState(kTRUE);
226 fColorSelect->SetEnabled(kTRUE);
227 fDefaultButton->SetEnabled(kTRUE);
228 fApplyButton->SetEnabled(kTRUE);
229 fAutoRefesh->SetEnabled(kTRUE);
236 void TStructNodeEditor::MaxLevelsValueSetSlot(Long_t)
238 fNode->SetMaxLevel(fMaxLevelsNumberEntry->GetIntNumber());
240 if(fAutoRefesh->IsOn()) {
248 void TStructNodeEditor::MaxObjectsValueSetSlot(Long_t)
250 fNode->SetMaxObjects(fMaxObjectsNumberEntry->GetIntNumber());
252 if(fAutoRefesh->IsOn()) {
260 void TStructNodeEditor::SetModel(TObject* obj)
262 fNode =
dynamic_cast<TStructNode *
>(obj);
266 fMaxLevelsNumberEntry->SetIntNumber(fNode->GetMaxLevel());
269 fMaxObjectsNumberEntry->SetIntNumber(fNode->GetMaxObjects());
272 fTypeName->SetText(fNode->GetTypeName());
275 fNodeNameLabel->SetText(fNode->GetName());
278 fSelectedPropert = FindNodeProperty(fNode);
279 if (!fSelectedPropert)
281 fSelectedPropert = GetDefaultProperty();
283 fNameEntry->SetText(fSelectedPropert->GetName());
284 fColorSelect->SetColor(fSelectedPropert->GetPixel(), kFALSE);
295 void TStructNodeEditor::Update()
297 Emit(
"Update(Bool_t)",
false);
304 void TStructNodeEditor::Update(Bool_t resetCamera)
306 Emit(
"Update(Bool_t)", resetCamera);