forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TStructNodeProperty.cxx
155 lines (123 loc) · 3.93 KB
/
TStructNodeProperty.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// @(#)root/gviz3d:$Id$
// 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 "TStructNodeProperty.h"
#include <TROOT.h>
#include <TClass.h>
ClassImp(TStructNodeProperty);
//________________________________________________________________________
//////////////////////////////////////////////////////////////////////////
//
// TStructNodeProperty class keeps a color for type
//
//
//
//
//
//////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// Contructs a TStructNodeProperty with p as parent window for class "name" with color "color".
TStructNodeProperty::TStructNodeProperty(const char * name, Int_t color)
{
SetName(name);
SetColor(color);
}
////////////////////////////////////////////////////////////////////////////////
/// Contructs a TStructNodeProperty with p as parent window for class "name" with color "pixel".
TStructNodeProperty::TStructNodeProperty(const char * name, Pixel_t pixel)
{
SetName(name);
SetColor(pixel);
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor
TStructNodeProperty::~TStructNodeProperty()
{
}
////////////////////////////////////////////////////////////////////////////////
/// Overrided method. Compare two objects of TStructNodeProperty class
Int_t TStructNodeProperty::Compare(const TObject* obj) const
{
// Default color "+" should be at the end.
if (fName == "+") {
return 1;
}
TStructNodeProperty* prop = (TStructNodeProperty*)obj;
TString propName(prop->GetName());
if (propName == "+") {
return -1;
}
TClass* cl1;
if (fName.EndsWith("+")) {
cl1 = TClass::GetClass(TString(fName.Data(), fName.Length()-1).Data());
} else {
cl1 = TClass::GetClass(fName.Data());
}
TClass* cl2;
if (propName.EndsWith("+")) {
cl2 = TClass::GetClass(TString(propName.Data(), propName.Length()-1).Data());
} else {
cl2 = TClass::GetClass(prop->GetName());
}
if(!cl1) {
return -1;
}
if(!cl2) {
return -1;
}
if(cl1->InheritsFrom(cl2)) {
return -1;
}
if(cl2->InheritsFrom(cl1)) {
return 1;
}
if(this > prop) {
return 1;
}
if(this < prop) {
return -1;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Returns color of class
TColor TStructNodeProperty::GetColor() const
{
return fColor;
}
////////////////////////////////////////////////////////////////////////////////
/// Return color in Pixel_t format
Pixel_t TStructNodeProperty::GetPixel() const
{
return fColor.GetPixel();
}
////////////////////////////////////////////////////////////////////////////////
/// Retruns true, because we have overrided method Compare
Bool_t TStructNodeProperty::IsSortable() const
{
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// Sets the color to "color"
void TStructNodeProperty::SetColor(const TColor & color)
{
fColor = color;
}
////////////////////////////////////////////////////////////////////////////////
/// Sets the color to "color"
void TStructNodeProperty::SetColor(Int_t color)
{
fColor = *(gROOT->GetColor(color));
}
////////////////////////////////////////////////////////////////////////////////
/// Sets the color to "pixel"
void TStructNodeProperty::SetColor(Pixel_t pixel)
{
SetColor(TColor::GetColor(pixel));
}