Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveTransEditor.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TEveTransEditor.h"
13 #include "TEveTrans.h"
14 #include "TEveGValuators.h"
15 
16 #include "TVirtualPad.h"
17 #include "TMath.h"
18 
19 #include "TGButton.h"
20 #include "TGLabel.h"
21 
22 /** \class TEveTransSubEditor
23 \ingroup TEve
24 Sub-editor for TEveTrans class.
25 */
26 
27 ClassImp(TEveTransSubEditor);
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// Constructor.
31 
32 TEveTransSubEditor::TEveTransSubEditor(TGWindow* p) :
33  TGVerticalFrame (p),
34  fTrans (0),
35  fTopHorFrame (0),
36  fUseTrans (0),
37  fEditTrans (0),
38  fEditTransFrame (0),
39  fPos (0),
40  fRot (0),
41  fScale (0),
42  fAutoUpdate (0),
43  fUpdate (0)
44 {
45  // --- Top controls
46 
47  fTopHorFrame = new TGHorizontalFrame(this);
48 
49  fUseTrans = new TGCheckButton(fTopHorFrame, "UseTrans");
50  fTopHorFrame->AddFrame(fUseTrans, new TGLayoutHints(kLHintsLeft, 1,2,0,0));
51  fUseTrans->Connect("Toggled(Bool_t)", "TEveTransSubEditor", this, "DoUseTrans()");
52  fEditTrans = new TGCheckButton(fTopHorFrame, "EditTrans");
53  fTopHorFrame->AddFrame(fEditTrans, new TGLayoutHints(kLHintsLeft, 2,1,0,0));
54  fEditTrans->Connect("Toggled(Bool_t)", "TEveTransSubEditor", this, "DoEditTrans()");
55 
56  AddFrame(fTopHorFrame, new TGLayoutHints(kLHintsTop, 0,0,2,1));
57 
58  // --- Trans edit part
59 
60  fEditTransFrame = new TGVerticalFrame(this);
61 
62  TGFont *font = gClient->GetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
63 
64  TGHorizontalFrame* hfp = new TGHorizontalFrame(fEditTransFrame);
65  TGLabel* labp = new TGLabel(hfp, "Location");
66  labp->SetTextFont(font);
67  hfp->AddFrame(labp);
68  fEditTransFrame->AddFrame(hfp, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,0,2,0));
69  fPos = new TEveGTriVecValuator(fEditTransFrame, "Pos", 160, 20);
70  fPos->SetNELength(6);
71  fPos->Build(kFALSE, "", "", "");
72  fPos->SetLimits(-1e5, 1e5, TGNumberFormat::kNESRealThree);
73  fPos->GetValuator(0)->SetToolTip("X coordinate");
74  fPos->GetValuator(1)->SetToolTip("Y coordinate");
75  fPos->GetValuator(2)->SetToolTip("Z coordinate");
76  fEditTransFrame->AddFrame(fPos, new TGLayoutHints(kLHintsTop , 0,0,0,0));
77 
78  TGHorizontalFrame* hfr = new TGHorizontalFrame(fEditTransFrame);
79  TGLabel* labr = new TGLabel(hfr, "Rotation");
80  labr->SetTextFont(font);
81  hfr->AddFrame(labr);
82  fEditTransFrame->AddFrame(hfr, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,0,2,0));
83  fRot = new TEveGTriVecValuator(fEditTransFrame, "Rot", 160, 20);
84  fRot->SetNELength(6);
85  fRot->Build(kFALSE, "", "", "");
86  fRot->SetLimits(-360, 360, TGNumberFormat::kNESRealOne);
87  fRot->GetValuator(0)->SetToolTip("X coordinate");
88  fRot->GetValuator(1)->SetToolTip("Y coordinate");
89  fRot->GetValuator(2)->SetToolTip("Z coordinate");
90  fEditTransFrame->AddFrame(fRot, new TGLayoutHints(kLHintsTop , 0,0, 0, 0));
91 
92  TGHorizontalFrame* hfs = new TGHorizontalFrame(fEditTransFrame);
93  TGLabel* labs = new TGLabel(hfs, "Scale");
94  labs->SetTextFont(font);
95  hfs->AddFrame(labs);
96  fEditTransFrame->AddFrame(hfs, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,0,2,0));
97  fScale = new TEveGTriVecValuator(fEditTransFrame, "Scale", 160, 20);
98  fScale->SetNELength(6);
99  fScale->Build(kFALSE, "", "", "");
100  fScale->SetLimits(1e-2, 1e2, TGNumberFormat::kNESRealTwo);
101  fScale->GetValuator(0)->SetToolTip("X coordinate");
102  fScale->GetValuator(1)->SetToolTip("Y coordinate");
103  fScale->GetValuator(2)->SetToolTip("Z coordinate");
104  fEditTransFrame->AddFrame(fScale, new TGLayoutHints(kLHintsTop , 0,0,0, 2));
105 
106  fPos ->Connect("ValueSet()", "TEveTransSubEditor", this, "DoTransChanged()");
107  fRot ->Connect("ValueSet()", "TEveTransSubEditor", this, "DoTransChanged()");
108  fScale->Connect("ValueSet()", "TEveTransSubEditor", this, "DoTransChanged()");
109 
110  {
111  TGHorizontalFrame* hframe = new TGHorizontalFrame(fEditTransFrame);
112  fAutoUpdate = new TGCheckButton(hframe, "AutoUpdate");
113  hframe->AddFrame(fAutoUpdate, new TGLayoutHints(kLHintsLeft, 1,1,1,1));
114  fUpdate = new TGTextButton(hframe, "Update");
115  hframe->AddFrame(fUpdate, new TGLayoutHints(kLHintsLeft, 0,0,1,1));
116  fUpdate->Connect("Clicked()", "TEveTransSubEditor", this, "TransChanged()");
117 
118  fEditTransFrame->AddFrame(hframe, new TGLayoutHints(kLHintsTop , 0,0,4,0));
119  }
120 
121  AddFrame(fEditTransFrame, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,0,1,2));
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Set model object.
126 
127 void TEveTransSubEditor::SetModel(TEveTrans* t)
128 {
129  fTrans = t;
130 
131  fUseTrans ->SetState(fTrans->fUseTrans ? kButtonDown : kButtonUp);
132  fEditTrans->SetState(fTrans->fEditTrans ? kButtonDown : kButtonUp);
133  if (fTrans->fEditTrans)
134  {
135  for (Int_t i=0; i<3; ++i)
136  {
137  fRot ->GetValuator(i)->GetEntry()->SetState(fTrans->GetEditRotation());
138  fScale->GetValuator(i)->GetEntry()->SetState(fTrans->GetEditScale());
139  }
140  fEditTransFrame->MapWindow();
141  }
142  else
143  {
144  fEditTransFrame->UnmapWindow();
145  }
146 
147  ((TGMainFrame*)fEditTransFrame->GetMainFrame())->Layout();
148 
149  fPos->SetValues(fTrans->ArrT());
150  Float_t a[3];
151  fTrans->GetRotAngles(a);
152  a[0] *= TMath::RadToDeg();
153  a[1] *= TMath::RadToDeg();
154  a[2] *= TMath::RadToDeg();
155  fRot->SetValues(a);
156  Double_t x, y, z;
157  fTrans->GetScale(x, y, z);
158  fScale->SetValues(x, y, z);
159 }
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 /// Set model object from widget data.
163 
164 void TEveTransSubEditor::SetTransFromData()
165 {
166  Double_t v[3];
167  fTrans->UnitTrans();
168  fRot->GetValues(v);
169  fTrans->SetRotByAngles(v[0]*TMath::DegToRad(), v[1]*TMath::DegToRad(), v[2]*TMath::DegToRad());
170  fPos->GetValues(v);
171  fTrans->SetPos(v);
172  fScale->GetValues(v);
173  fTrans->Scale(v[0], v[1], v[2]);
174 }
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Emit "UseTrans()" signal.
178 
179 void TEveTransSubEditor::UseTrans()
180 {
181  Emit("UseTrans()");
182 }
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// Set transformation values from widget and emit "TransChanged()" signal.
186 
187 void TEveTransSubEditor::TransChanged()
188 {
189  SetTransFromData();
190  Emit("TransChanged()");
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// Slot for UseTrans.
195 
196 void TEveTransSubEditor::DoUseTrans()
197 {
198  fTrans->SetUseTrans(fUseTrans->IsOn());
199  UseTrans();
200 }
201 
202 ////////////////////////////////////////////////////////////////////////////////
203 /// Slot for EditTrans.
204 
205 void TEveTransSubEditor::DoEditTrans()
206 {
207  fTrans->SetEditTrans(fEditTrans->IsOn());
208  TransChanged();
209 }
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 /// Slot for TransChanged.
213 
214 void TEveTransSubEditor::DoTransChanged()
215 {
216  if (fAutoUpdate->IsOn())
217  TransChanged();
218 }
219 
220 /** \class TEveTransEditor
221 \ingroup TEve
222 Editor for TEveTrans class.
223 */
224 
225 ClassImp(TEveTransEditor);
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Constructor.
229 
230 TEveTransEditor::TEveTransEditor(const TGWindow *p, Int_t width, Int_t height,
231  UInt_t options, Pixel_t back) :
232  TGedFrame(p, width, height, options | kVerticalFrame, back),
233  fM (0),
234  fSE(0)
235 {
236  MakeTitle("TEveTrans");
237 
238  fSE = new TEveTransSubEditor(this);
239  AddFrame(fSE, new TGLayoutHints(kLHintsTop, 2, 0, 2, 2));
240  fSE->Connect("UseTrans()", "TEveTransEditor", this, "Update()");
241  fSE->Connect("TransChanged()", "TEveTransEditor", this, "Update()");
242 }
243 
244 ////////////////////////////////////////////////////////////////////////////////
245 /// Set model object.
246 
247 void TEveTransEditor::SetModel(TObject* obj)
248 {
249  fM = dynamic_cast<TEveTrans*>(obj);
250  fSE->SetModel(fM);
251 }