]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant3/AliGuiGeomDialog.cxx
New TTask based method to do Digits To clusters. Works with files of multiple
[u/mrichter/AliRoot.git] / TGeant3 / AliGuiGeomDialog.cxx
1 /* *************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.1  2000/07/13 16:19:10  fca
19 Mainly coding conventions + some small bug fixes
20
21 Revision 1.8  2000/07/12 08:56:32  fca
22 Coding convention correction and warning removal
23
24 Revision 1.7  2000/06/28 21:27:45  morsch
25 Most coding rule violations corrected.
26 Still to do: Split the file (on file per class) ? Avoid the global variables.
27 Copy constructors and assignment operators (dummy ?)
28
29 Revision 1.6  2000/04/14 11:07:46  morsch
30 Correct volume to medium assignment in case several media are asigned to the
31 same material.
32
33 Revision 1.5  2000/03/20 15:11:03  fca
34 Mods to make the code compile on HP
35
36 Revision 1.4  2000/01/18 16:12:08  morsch
37 Bug in calculation of number of volume divisions and number of positionings corrected
38 Browser for Material and Media properties added
39
40 Revision 1.3  1999/11/14 14:31:14  fca
41 Correct small error and remove compilation warnings on HP
42
43 Revision 1.2  1999/11/10 16:53:35  fca
44 The new geometry viewer from A.Morsch
45
46 */
47
48 #include "TGButton.h"
49 #include "TGTab.h"
50 #include "TGComboBox.h"
51 #include "TGDoubleSlider.h"
52
53 #include "AliGuiGeomDialog.h"
54 #include "AliGUISliders.h"
55 #include "AliG3Volume.h"
56
57 AliGuiGeomDialog::AliGuiGeomDialog(const TGWindow *p, const TGWindow *main, UInt_t w,
58                        UInt_t h, UInt_t options)
59     : TGTransientFrame(p, main, w, h, options)
60 {
61    // Create a dialog window. A dialog window pops up with respect to its
62    // "main" window.
63
64    fFrame1 = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
65
66    fOkButton = new TGTextButton(fFrame1, "&Ok", 1);
67    fOkButton->Associate(this);
68    fCancelButton = new TGTextButton(fFrame1, "&Cancel", 2);
69    fCancelButton->Associate(this);
70
71    fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
72                            2, 2, 2, 2);
73    fL2 = new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1);
74
75    fFrame1->AddFrame(fOkButton, fL1);
76    fFrame1->AddFrame(fCancelButton, fL1); 
77
78    fFrame1->Resize(150, fOkButton->GetDefaultHeight());
79    AddFrame(fFrame1, fL2);
80
81    //--------- create Tab widget and some composite frames for Tab testing
82
83    fTab = new TGTab(this, 300, 300);
84    fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
85 //
86 // Tab1: Sliders
87 //
88    TGCompositeFrame *tf = fTab->AddTab("Draw");
89    fF1 = new AliGUISliders(tf, this, 60, 20);
90    tf->AddFrame(fF1,fL3);
91    
92 // 
93 // Tab2: Drawing Options
94 //
95    tf = fTab->AddTab("Options");
96    fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
97                            200, 2, 2, 2);
98    fF2 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
99
100    fF2->AddFrame(fChk1 = new TGCheckButton(fF2, "Shadow", 86), fL3);
101    fF2->AddFrame(fChk2 = new TGCheckButton(fF2, "Hide  ", 87), fL3);
102    fF2->AddFrame(fChk3 = new TGCheckButton(fF2, "Clip  ", 88), fL3);
103
104    fF2->AddFrame(fLabel1 = new TGLabel(fF2, "Fill"),fL3);
105    
106    fCombo = new TGComboBox(fF2, 89);
107    fF2->AddFrame(fCombo, fL3);
108
109    tf->AddFrame(fF2, fL3);
110
111    int i;
112    for (i = 0; i < 8; i++) {
113       char tmp[20];
114
115       sprintf(tmp, "%i", i+1);
116       fCombo->AddEntry(tmp, i+1);
117    }
118    fCombo->Select(1);
119    fCombo->Resize(50, 20);
120    fCombo->Associate(this);
121
122    fChk1->Associate(this);
123    fChk2->Associate(this);
124    fChk3->Associate(this);
125 // 
126 // Tab3: Seen Option
127 //
128    tf = fTab->AddTab("Seen");
129    fF3 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
130    fF3->AddFrame(fLabel2 = new TGLabel(fF3, "Seen"),fL3);
131    fCombo2 = new TGComboBox(fF3, 90);
132    fF3->AddFrame(fCombo2, fL3);
133    tf->AddFrame(fF3, fL3);
134
135    for (i = 0; i < 4; i++) {
136       char tmp[20];
137
138       sprintf(tmp, "%i", i-2);
139       fCombo2->AddEntry(tmp, i+1);
140    }
141    fCombo2->Select(4);
142    fCombo2->Resize(50, 20);
143    fCombo2->Associate(this);
144 // 
145 // Tab4: Clip Box
146 //
147    tf = fTab->AddTab("ClipBox");
148    //--- layout for buttons: top align, equally expand horizontally
149    fBly = new TGLayoutHints(kLHintsTop | kLHintsExpandY, 5, 5, 5, 5);
150
151    //--- layout for the frame: place at bottom, right aligned
152    fBfly1 = new TGLayoutHints(kLHintsLeft | kLHintsExpandX );
153 //
154 //  Frames
155 //
156 //  Slider1
157    fF4 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
158        
159    fHSframe1 = new TGHorizontalFrame(fF4, 400, 100, kFixedWidth);
160
161    fTbh11 = new TGTextBuffer(10);
162    fTeh11 = new TGTextEntry(fHSframe1, fTbh11,1);
163    fTbh11->AddText(0, "   0");
164    fTeh11->Associate(this);
165
166    fTbh12 = new TGTextBuffer(10);
167    fTeh12 = new TGTextEntry(fHSframe1, fTbh12,1);
168    fTbh12->AddText(0, "2000");
169    fTeh12->Associate(this);
170     
171    fDslider1 = new TGDoubleHSlider(fHSframe1, 400, kSlider1 | kScaleBoth, 1);
172    fDslider1->Associate(this);
173    fDslider1->SetRange(-2000, 2000);
174    fDslider1->SetPosition(0, 2000);
175    
176    fSLabel1 = new TGLabel(fHSframe1, "xmin-xmax");
177
178    fHSframe1->AddFrame(fSLabel1, fBfly1);
179    fHSframe1->AddFrame(fTeh11, fBfly1);
180    fHSframe1->AddFrame(fTeh12, fBfly1);
181    fHSframe1->AddFrame(fDslider1, fBfly1);
182    
183    fF4->AddFrame(fHSframe1, fBly);
184
185 //
186    fHSframe2 = new TGHorizontalFrame(fF4, 400, 100, kFixedWidth);
187
188    fTbh21 = new TGTextBuffer(10);
189    fTeh21 = new TGTextEntry(fHSframe2, fTbh21,1);
190    fTbh21->AddText(0, "   0");
191    fTeh21->Associate(this);
192
193    fTbh22 = new TGTextBuffer(10);
194    fTeh22 = new TGTextEntry(fHSframe2, fTbh22,1);
195    fTbh22->AddText(0, "2000");
196    fTeh22->Associate(this);
197
198    fDslider2 = new TGDoubleHSlider(fHSframe2, 400, kSlider1 | kScaleBoth, 2);
199    fDslider2->Associate(this);
200    fDslider2->SetRange(-2000, 2000);
201    fDslider2->SetPosition(0, 2000);
202    
203    fSLabel2 = new TGLabel(fHSframe2, "ymin-ymax");
204
205    fHSframe2->AddFrame(fSLabel2, fBfly1);
206    fHSframe2->AddFrame(fTeh21, fBfly1);
207    fHSframe2->AddFrame(fTeh22, fBfly1);
208    fHSframe2->AddFrame(fDslider2, fBfly1);
209    
210    fF4->AddFrame(fHSframe2, fBly);
211
212 //
213    fHSframe3 = new TGHorizontalFrame(fF4, 400, 100, kFixedWidth);
214
215    fTbh31 = new TGTextBuffer(10);
216    fTeh31 = new TGTextEntry(fHSframe3, fTbh31,1);
217    fTbh31->AddText(0, "   0");
218    fTeh31->Associate(this);
219
220    fTbh32 = new TGTextBuffer(10);
221    fTeh32 = new TGTextEntry(fHSframe3, fTbh32,1);
222    fTbh32->AddText(0, "2000");
223    fTeh32->Associate(this);
224
225    fDslider3 = new TGDoubleHSlider(fHSframe3, 400, kSlider1 | kScaleBoth, 3);
226    fDslider3->Associate(this);
227    fDslider3->SetRange(-2000, 2000);
228    fDslider3->SetPosition(0, 2000);
229    
230    fSLabel3 = new TGLabel(fHSframe3, "zmin-zmax");
231
232    fHSframe3->AddFrame(fSLabel3, fBfly1);
233    fHSframe3->AddFrame(fTeh31, fBfly1);
234    fHSframe3->AddFrame(fTeh32, fBfly1);
235    fHSframe3->AddFrame(fDslider3, fBfly1);
236    
237    fF4->AddFrame(fHSframe3, fBly);
238    tf->AddFrame(fF4, fL3);
239 //
240 //
241    TGLayoutHints *fL5 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
242                                           kLHintsExpandY, 2, 2, 5, 1);
243    AddFrame(fTab, fL5);
244
245    MapSubwindows();
246    Resize(GetDefaultSize());
247
248    // position relative to the parent's window
249    Window_t wdum;
250    int ax, ay;
251    gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
252                           (((TGFrame *) main)->GetWidth() - fWidth) >> 1,
253                           (((TGFrame *) main)->GetHeight() - fHeight) >> 1,
254                           ax, ay, wdum);
255    Move(ax, ay);
256
257    SetWindowName("Dialog");
258
259    MapWindow();
260    //gClient->WaitFor(this);    // otherwise canvas contextmenu does not work
261 }
262
263 AliGuiGeomDialog::~AliGuiGeomDialog()
264 {
265    // Delete test dialog widgets.
266
267    delete fOkButton;
268    delete fCancelButton;
269    delete fFrame1;
270    delete fChk1; delete fChk2;
271    delete fF1; delete fF2; delete fF3; delete fF4;
272    delete fCombo;
273    delete fTab;
274    delete fL3; delete fL4;
275    delete fL1; delete fL2;
276    delete fBly; delete fBfly1;
277    delete fTbh11; delete fTbh12; delete fTbh21; delete fTbh22; 
278    delete fTbh31; delete fTbh32; delete fTeh11; delete fTeh12; 
279    delete fTeh21; delete fTeh22; delete fTeh31; delete fTeh32;
280    delete fDslider1; delete fDslider2; delete fDslider3;
281    delete fSLabel1;  delete fSLabel2;  delete fSLabel3;
282 }
283
284 void AliGuiGeomDialog::Update()
285 {
286 // Update widgets
287     
288     Float_t param;
289 //  Update Sliders
290     if (fF1) {
291         fF1->Update();
292     }
293 //  Seen
294     if (fCombo2) {
295         param=gCurrentVolume->GetParam(kSeen);
296         fCombo2->Select(Int_t(param)+3);
297     }
298 //  Hide, Shadow, Clip
299     if (fChk1) {
300         if (Int_t(gCurrentVolume->GetParam(kShadow))) {
301             fChk1->SetState(kButtonDown);
302         } else {
303             fChk1->SetState(kButtonUp);
304         }
305     }
306
307     if (fChk2) {
308         if (Int_t(gCurrentVolume->GetParam(kHide))) {
309             fChk2->SetState(kButtonDown);
310         } else {
311             fChk2->SetState(kButtonUp);
312         }
313     }
314
315     if (fChk3) {
316         if (Int_t(gCurrentVolume->GetParam(kClip))) {
317             fChk3->SetState(kButtonDown);
318         } else {
319             fChk3->SetState(kButtonUp);
320         }
321     }
322     
323 }
324
325 void AliGuiGeomDialog::CloseWindow()
326 {
327    // Called when window is closed via the window manager.
328    delete this;
329 }
330
331 Bool_t AliGuiGeomDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
332 {
333    // Process messages coming from widgets associated with the dialog.
334     char buf[10];
335     Float_t min,max;
336     switch (GET_MSG(msg)) {
337     case kC_HSLIDER:
338         switch (GET_SUBMSG(msg)) {
339         case kSL_POS:
340             switch (Int_t(parm1)) {
341             case 1:
342                 min=fDslider1->GetMinPosition();
343                 max=fDslider1->GetMaxPosition();
344                 sprintf(buf, "%6.2f", min);
345                 fTbh11->Clear();
346                 fTbh11->AddText(0, buf);
347                 sprintf(buf, "%6.2f", max);
348                 fTbh12->Clear();
349                 fTbh12->AddText(0, buf);
350                 gClient->NeedRedraw(fTeh11);
351                 gClient->NeedRedraw(fTeh12);
352                 gCurrentVolume->SetParam(kClipXmin,min);
353                 gCurrentVolume->SetParam(kClipXmax,max);
354                 break;
355             case 2:
356                 min=fDslider2->GetMinPosition();
357                 max=fDslider2->GetMaxPosition();
358                 sprintf(buf, "%6.2f", min);
359                 fTbh21->Clear();
360                 fTbh21->AddText(0, buf);
361                 sprintf(buf, "%6.2f", max);
362                 fTbh22->Clear();
363                 fTbh22->AddText(0, buf);
364                 gClient->NeedRedraw(fTeh21);
365                 gClient->NeedRedraw(fTeh22);
366                 gCurrentVolume->SetParam(kClipYmin,min);
367                 gCurrentVolume->SetParam(kClipYmax,max);
368                 break;
369             case 3:
370                 min=fDslider3->GetMinPosition();
371                 max=fDslider3->GetMaxPosition();
372                 sprintf(buf, "%6.2f", min);
373                 fTbh31->Clear();
374                 fTbh31->AddText(0, buf);
375                 sprintf(buf, "%6.2f", max);
376                 fTbh32->Clear();
377                 fTbh32->AddText(0, buf);
378                 gClient->NeedRedraw(fTeh31);
379                 gClient->NeedRedraw(fTeh32);
380                 gCurrentVolume->SetParam(kClipZmin,min);
381                 gCurrentVolume->SetParam(kClipZmax,max);
382                 break;
383             default:
384                 break;
385             }
386         }
387         break;
388     case kC_COMMAND:
389         switch (GET_SUBMSG(msg)) {
390         case kCM_BUTTON:
391             switch(parm1) {
392             case 1:
393             case 2:
394                 printf("\nTerminating dialog: %s pressed\n",
395                        (parm1 == 1) ? "OK" : "Cancel");
396                 CloseWindow();
397                 break;
398             }
399             break;
400         case kCM_COMBOBOX:
401             switch(parm1) {
402             case 89:
403                 gCurrentVolume->SetParam(kFill, Float_t(parm2));
404                 gCurrentVolume->Draw();
405                 break;
406             case 90:
407                 gCurrentVolume->SetParam(kSeen, Float_t(parm2-3));
408                 gCurrentVolume->Draw();
409                 break;
410             }
411             break;
412         case kCM_CHECKBUTTON:
413             switch (parm1) {
414             case 86:
415                 if (Int_t(gCurrentVolume->GetParam(kShadow))) {
416                     gCurrentVolume->SetParam(kShadow, 0.);
417                 } else {
418                     gCurrentVolume->SetParam(kShadow, 1.);
419                 }
420                 gCurrentVolume->Draw();
421                 break;
422             case 87:
423                 if (Int_t(gCurrentVolume->GetParam(kHide))) {
424                     gCurrentVolume->SetParam(kHide, 0.);
425                 } else {
426                     gCurrentVolume->SetParam(kHide, 1.);
427                 }
428                 gCurrentVolume->Draw();
429                 break;
430             case 88:
431                 if (Int_t(gCurrentVolume->GetParam(kClip))) {
432                     gCurrentVolume->SetParam(kClip, 0.);
433                 } else {
434                     gCurrentVolume->SetParam(kClip, 1.);
435                 }
436                 gCurrentVolume->Draw();
437                 break;
438
439             default:
440                 break;
441             }
442             break;
443         case kCM_TAB:
444             break;
445         default:
446             break;
447         }
448         break;
449     default:
450         break;
451     }
452     return kTRUE;
453 }
454