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