]>
Commit | Line | Data |
---|---|---|
5a5a1232 | 1 | // $Header$ |
2 | ||
3 | #include "RenderElement.h" | |
4 | #include "RGTopFrame.h" | |
5 | ||
6 | #include <TColor.h> | |
7 | #include <TCanvas.h> | |
8 | #include <TGListTree.h> | |
9 | #include <THashList.h> | |
10 | ||
11 | using namespace Reve; | |
12 | using namespace Reve; | |
13 | ||
14 | //______________________________________________________________________ | |
15 | // Reve | |
16 | // | |
17 | ||
18 | ClassImp(RenderElement) | |
19 | ||
20 | RenderElement::RenderElement() | |
21 | { | |
22 | fRnrElement = true; | |
23 | fMainColorPtr = 0; | |
24 | } | |
25 | ||
26 | RenderElement::RenderElement(Color_t& main_color) : fMainColorPtr(&main_color) | |
27 | { | |
28 | fRnrElement = true; | |
29 | } | |
30 | ||
31 | /**************************************************************************/ | |
32 | ||
33 | TObject* RenderElement::GetObject(Exc_t eh) | |
34 | { | |
35 | TObject* obj = dynamic_cast<TObject*>(this); | |
36 | if(obj == 0) | |
37 | throw(eh + "not a TObject."); | |
38 | return obj; | |
39 | } | |
40 | ||
41 | /**************************************************************************/ | |
42 | ||
43 | TGListTreeItem* RenderElement::AddIntoListTree(TGListTree* ltree, | |
44 | TGListTreeItem* parent) | |
45 | { | |
46 | static const Exc_t eH("RenderElement::AddIntoListTree "); | |
47 | ||
48 | TObject* tobj = GetObject(eH); | |
092578a7 | 49 | Bool_t colorp = fMainColorPtr != 0; |
50 | TGListTreeItem* item = ltree->AddItem(parent, tobj->GetName(), this, | |
51 | 0, 0, colorp); | |
5a5a1232 | 52 | item->CheckItem(GetRnrElement()); |
092578a7 | 53 | if(colorp) item->SetColor(GetMainColor()); |
5a5a1232 | 54 | item->SetTipText(tobj->GetTitle()); |
55 | ||
56 | fItems.insert(ListTreeInfo(ltree, item)); | |
57 | ||
58 | return item; | |
59 | } | |
60 | ||
61 | /**************************************************************************/ | |
62 | ||
63 | void RenderElement::FullUpdate() | |
64 | { | |
65 | for(sLTI_i i=fItems.begin(); i!=fItems.end(); ++i) { | |
66 | // Setup name and title/tooltip? Need update calls from setname/title as well. | |
67 | i->fItem->CheckItem(fRnrElement); | |
68 | i->fItem->SetColor(GetMainColor()); | |
69 | } | |
70 | gReve->Redraw3D(); | |
71 | gReve->NotifyBrowser(); | |
72 | } | |
73 | ||
74 | /**************************************************************************/ | |
75 | ||
76 | void RenderElement::SpawnEditor() | |
77 | { | |
78 | // Here spawn a sub-class of TGedFrame with special UpdateMethod. | |
79 | gReve->EditRenderElement(this); | |
80 | } | |
81 | ||
82 | void RenderElement::ExportToCINT(Text_t* var_name) | |
83 | { | |
84 | static const Exc_t eH("RenderElement::ExportToCINT "); | |
85 | ||
86 | TObject* obj = GetObject(eH); | |
87 | const char* cname = obj->IsA()->GetName(); | |
88 | gROOT->ProcessLine(Form("%s* %s = (%s*) %p;", cname, var_name, cname, obj)); | |
89 | } | |
90 | ||
91 | /**************************************************************************/ | |
92 | /* | |
93 | void RenderElement::DumpSourceObject() | |
94 | { | |
95 | TObject* o = GetSourceObject(); | |
96 | if(o == 0) { | |
97 | printf("Source object not set.\n"); | |
98 | } else { | |
99 | o->Dump(); | |
100 | } | |
101 | } | |
102 | ||
103 | void RenderElement::InspectSourceObject() | |
104 | { | |
105 | TObject* o = GetSourceObject(); | |
106 | if(o == 0) { | |
107 | printf("Source object not set.\n"); | |
108 | } else { | |
109 | o->Inspect(); | |
110 | } | |
111 | } | |
112 | */ | |
113 | /**************************************************************************/ | |
114 | ||
115 | void RenderElement::SetRnrElement(Bool_t rnr) | |
116 | { | |
117 | if(rnr != fRnrElement) { | |
118 | fRnrElement = rnr; | |
119 | FullUpdate(); | |
120 | } | |
121 | } | |
092578a7 | 122 | |
5a5a1232 | 123 | /**************************************************************************/ |
124 | ||
125 | void RenderElement::SetMainColor(Color_t color) | |
126 | { | |
127 | if (fMainColorPtr) { | |
128 | *fMainColorPtr = color; | |
129 | FullUpdate(); | |
130 | } | |
131 | } | |
132 | ||
133 | void RenderElement::SetMainColorByPixel(Pixel_t pixel) | |
134 | { | |
135 | SetMainColor(Color_t(TColor::GetColor(pixel))); | |
136 | } | |
137 | ||
138 | /**************************************************************************/ | |
139 | /**************************************************************************/ | |
140 | ||
092578a7 | 141 | ClassImp(RenderElementObjPtr) |
142 | ||
143 | RenderElementObjPtr::RenderElementObjPtr(TObject* obj) : | |
144 | RenderElement(), | |
145 | fObject(obj) | |
146 | {} | |
147 | ||
148 | RenderElementObjPtr::RenderElementObjPtr(TObject* obj, Color_t& mainColor) : | |
149 | RenderElement(mainColor), | |
150 | fObject(obj) | |
151 | {} | |
152 | ||
153 | RenderElementObjPtr::~RenderElementObjPtr() | |
154 | { | |
155 | delete fObject; | |
156 | } | |
157 | ||
158 | /**************************************************************************/ | |
159 | ||
160 | TObject* RenderElementObjPtr::GetObject(Reve::Exc_t eh) | |
161 | { | |
162 | if(fObject == 0) | |
163 | throw(eh + "fObject not set."); | |
164 | return fObject; | |
165 | } | |
166 | ||
167 | void RenderElementObjPtr::SetRnrElement(Bool_t rnr) | |
168 | { | |
169 | if(rnr != fRnrElement) { | |
170 | fRnrElement = rnr; | |
171 | if(rnr) { | |
172 | gReve->GetCC()->GetListOfPrimitives()->Add(fObject); | |
173 | } else { | |
174 | gReve->GetCC()->GetListOfPrimitives()->Remove(fObject); | |
175 | } | |
176 | FullUpdate(); | |
177 | } | |
178 | } | |
179 | ||
180 | /**************************************************************************/ | |
181 | /**************************************************************************/ | |
182 | ||
5a5a1232 | 183 | ClassImp(RenderElementListBase) |
184 | ||
185 | Int_t RenderElementListBase::ExpandIntoListTree(TGListTree* ltree, | |
186 | TGListTreeItem* parent) | |
187 | { | |
188 | // Populates parent with elements. | |
189 | // parent must be an already existing representation of *this*. | |
190 | // Returns number of inserted elements. | |
191 | // If parent already has children, it does nothing. | |
192 | // | |
193 | // RnrEl can be inserted in a list-tree several times, thus we can not | |
194 | // search through fItems to get parent here. | |
195 | // Anyhow, it is probably known as it must have been selected by the user. | |
196 | ||
197 | if(parent->GetFirstChild() != 0) | |
198 | return 0; | |
199 | Int_t n = 0; | |
200 | for(lpRE_i i=fList.begin(); i!=fList.end(); ++i) { | |
201 | (*i)->AddIntoListTree(ltree, parent); | |
202 | ++n; | |
203 | } | |
204 | return n; | |
205 | } | |
206 | ||
207 | /**************************************************************************/ | |
208 | ||
209 | void RenderElementListBase::EnableListElements() | |
210 | { | |
211 | for(lpRE_i i=fList.begin(); i!=fList.end(); ++i) | |
212 | (*i)->SetRnrElement(true); | |
213 | } | |
214 | ||
215 | void RenderElementListBase::DisableListElements() | |
216 | { | |
217 | for(lpRE_i i=fList.begin(); i!=fList.end(); ++i) | |
218 | (*i)->SetRnrElement(false); | |
219 | } | |
220 | ||
221 | /**************************************************************************/ | |
222 | ||
223 | void RenderElementListBase::SetMainColor(Color_t col) | |
224 | { | |
225 | Color_t oldcol = GetMainColor(); | |
226 | for(lpRE_i i=fList.begin(); i!=fList.end(); ++i) { | |
227 | if((*i)->GetMainColor() == oldcol) (*i)->SetMainColor(col); | |
228 | } | |
229 | RenderElement::SetMainColor(col); | |
230 | } | |
231 | ||
232 | void RenderElementListBase::SetMainColor(Pixel_t pixel) | |
233 | { | |
234 | // This one needed for proper calling via CINT (signals). | |
235 | ||
236 | SetMainColor(Color_t(TColor::GetColor(pixel))); | |
237 | } | |
238 | ||
239 | /**************************************************************************/ | |
240 | ||
241 | void RenderElementListBase::PaintElements(Option_t* option) | |
242 | { | |
243 | if(fRnrElement) { | |
244 | for(lpRE_i i=fList.begin(); i!=fList.end(); ++i) { | |
245 | if((*i)->GetRnrElement()) | |
246 | (*i)->GetObject()->Paint(option); | |
247 | } | |
248 | } | |
249 | } | |
250 | ||
251 | /**************************************************************************/ | |
252 | /**************************************************************************/ | |
253 | ||
254 | ClassImp(RenderElementList) |