Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLClipSetEditor.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel, Jun 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, 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 "TGLClipSetEditor.h"
13 #include "TGLClip.h"
14 #include "TVirtualPad.h"
15 #include "TColor.h"
16 #include "TGLabel.h"
17 #include "TGButton.h"
18 #include "TGButtonGroup.h"
19 #include "TGNumberEntry.h"
20 
21 #include "TGLViewerEditor.h"
22 
23 /** \class TGLClipSetSubEditor
24 \ingroup opengl
25 GUI sub-editor for TGLClipSet.
26 */
27 
28 ClassImp(TGLClipSetSubEditor);
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 /// Constructor.
32 
33 TGLClipSetSubEditor::TGLClipSetSubEditor(const TGWindow *p) :
34  TGVerticalFrame(p),
35  fM(0),
36  fCurrentClip(TGLClip::kClipNone),
37  fTypeButtons(0),
38  fPlanePropFrame(0),
39  fPlaneProp(),
40  fBoxPropFrame(0),
41  fBoxProp(),
42  fClipInside(0),
43  fAutoUpdate(0),
44  fClipEdit(0),
45  fClipShow(0),
46  fApplyButton(0),
47  fResetButton(0)
48 {
49  fTypeButtons = new TGButtonGroup(this, "Clip Type", kChildFrame|kHorizontalFrame);
50  new TGRadioButton(fTypeButtons, "None ");
51  new TGRadioButton(fTypeButtons, "Plane ");
52  new TGRadioButton(fTypeButtons, "Box");
53  fTypeButtons->SetLayoutHints(new TGLayoutHints(kLHintsLeft|kLHintsBottom, 0, 0, 2, -10));
54  AddFrame(fTypeButtons, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
55  // Clip inside / edit
56  fClipInside = new TGCheckButton(this, "Clip away inside");
57  AddFrame(fClipInside, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
58  fAutoUpdate = new TGCheckButton(this, "Auto update clip");
59  AddFrame(fAutoUpdate, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
60  fClipEdit = new TGCheckButton(this, "Edit In Viewer");
61  AddFrame(fClipEdit, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
62  fClipShow = new TGCheckButton(this, "Show In Viewer");
63  AddFrame(fClipShow, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
64 
65  // Plane properties
66  fPlanePropFrame = new TGCompositeFrame(this);
67  AddFrame(fPlanePropFrame, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
68 
69  static const char * const planeStr[] = { "aX + ", "bY +", "cZ + ", "d = 0" };
70 
71  for (Int_t i = 0; i < 4; ++i)
72  fPlaneProp[i] = TGLViewerEditor::MakeLabeledNEntry(fPlanePropFrame, planeStr[i] , 40);
73 
74  // Box properties
75  fBoxPropFrame = new TGCompositeFrame(this);
76  AddFrame(fBoxPropFrame, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
77 
78  static const char * const boxStr[] = {"Center X", "Center Y", "Center Z", "Length X", "Length Y", "Length Z" };
79 
80  for (Int_t i = 0; i < 6; ++i)
81  fBoxProp[i] = TGLViewerEditor::MakeLabeledNEntry(fBoxPropFrame, boxStr[i] , 60);
82 
83  // Apply button
84  fApplyButton = new TGTextButton(this, "Apply");
85  AddFrame(fApplyButton, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
86 
87  fResetButton = new TGTextButton(this, "Reset");
88  AddFrame(fResetButton, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
89 
90  fTypeButtons->Connect("Clicked(Int_t)", "TGLClipSetSubEditor", this, "ClipTypeChanged(Int_t)");
91  fClipInside->Connect("Clicked()", "TGLClipSetSubEditor", this, "UpdateViewerClip()");
92  fAutoUpdate->Connect("Clicked()", "TGLClipSetSubEditor", this, "UpdateViewerClip()");
93  fClipEdit->Connect("Clicked()", "TGLClipSetSubEditor", this, "UpdateViewerClip()");
94  fClipShow->Connect("Clicked()", "TGLClipSetSubEditor", this, "UpdateViewerClip()");
95 
96  for (Int_t i = 0; i < 4; ++i)
97  fPlaneProp[i]->Connect("ValueSet(Long_t)", "TGLClipSetSubEditor", this, "ClipValueChanged()");
98 
99  for (Int_t i = 0; i < 6; ++i)
100  fBoxProp[i]->Connect("ValueSet(Long_t)", "TGLClipSetSubEditor", this, "ClipValueChanged()");
101 
102  fApplyButton->Connect("Pressed()", "TGLClipSetSubEditor", this, "UpdateViewerClip()");
103  fResetButton->Connect("Pressed()", "TGLClipSetSubEditor", this, "ResetViewerClip()");
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Set model object.
108 
109 void TGLClipSetSubEditor::SetModel(TGLClipSet* m)
110 {
111  fM = m;
112 
113  fTypeButtons->GetButton(fCurrentClip+1)->SetDown(kFALSE);
114  fCurrentClip = fM->GetClipType();
115 
116  Double_t clip[6] = {0.};
117  fM->GetClipState(fCurrentClip, clip);
118 
119  fApplyButton->SetState(kButtonDisabled);
120 
121  // Button ids run from 1
122  if (TGButton *btn = fTypeButtons->GetButton(fCurrentClip+1)) {
123  btn->SetDown();
124  fTypeButtons->SetButton(fCurrentClip+1);
125  }
126  Bool_t active = (fCurrentClip != TGLClip::kClipNone);
127  fClipInside->SetEnabled(active);
128  fAutoUpdate->SetEnabled(active);
129  fClipEdit ->SetEnabled(active);
130  fClipShow ->SetEnabled(active);
131  if (active) {
132  fClipEdit->SetDown(fM->GetShowManip());
133  fClipShow->SetDown(fM->GetShowClip());
134  fClipInside->SetDown(fM->GetCurrentClip()->GetMode() == TGLClip::kInside);
135  fAutoUpdate->SetDown(fM->GetAutoUpdate());
136 
137  if (fCurrentClip == TGLClip::kClipPlane) {
138  HideFrame(fBoxPropFrame);
139  ShowFrame(fPlanePropFrame);
140  for (Int_t i = 0; i < 4; ++i)
141  fPlaneProp[i]->SetNumber(clip[i]);
142  } else if (fCurrentClip == TGLClip::kClipBox) {
143  HideFrame(fPlanePropFrame);
144  ShowFrame(fBoxPropFrame);
145  for (Int_t i = 0; i < 6; ++i)
146  fBoxProp[i]->SetNumber(clip[i]);
147  }
148 
149  fResetButton->SetState(kButtonUp);
150  } else {
151  HideFrame(fPlanePropFrame);
152  HideFrame(fBoxPropFrame);
153 
154  fResetButton->SetState(kButtonDisabled);
155  }
156 }
157 
158 ////////////////////////////////////////////////////////////////////////////////
159 /// Emit Changed signal.
160 
161 void TGLClipSetSubEditor::Changed()
162 {
163  Emit("Changed()");
164 }
165 
166 ////////////////////////////////////////////////////////////////////////////////
167 /// One of number entries was changed.
168 
169 void TGLClipSetSubEditor::ClipValueChanged()
170 {
171  fApplyButton->SetState(kButtonUp);
172 }
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 /// Clip type radio button changed - update viewer.
176 
177 void TGLClipSetSubEditor::ClipTypeChanged(Int_t id)
178 {
179  switch (id)
180  {
181  case 2: fCurrentClip = TGLClip::kClipPlane; break;
182  case 3: fCurrentClip = TGLClip::kClipBox; break;
183  default: fCurrentClip = TGLClip::kClipNone; break;
184  }
185  fM->SetClipType(fCurrentClip);
186  SetModel(fM);
187  ((TGMainFrame*)GetMainFrame())->Layout();
188  Changed();
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Change clipping volume.
193 
194 void TGLClipSetSubEditor::UpdateViewerClip()
195 {
196  Double_t data[6] = {0.};
197  // Fetch GUI state for clip if 'type' into 'data' vector
198  if (fCurrentClip == TGLClip::kClipPlane)
199  for (Int_t i = 0; i < 4; ++i)
200  data[i] = fPlaneProp[i]->GetNumber();
201  else if (fCurrentClip == TGLClip::kClipBox)
202  for (Int_t i = 0; i < 6; ++i)
203  data[i] = fBoxProp[i]->GetNumber();
204 
205  fApplyButton->SetState(kButtonDisabled);
206 
207  fM->SetClipState(fCurrentClip, data);
208  fM->SetShowManip(fClipEdit->IsDown());
209  fM->SetShowClip (fClipShow->IsDown());
210  if (fCurrentClip != TGLClip::kClipNone)
211  fM->GetCurrentClip()->SetMode(fClipInside->IsDown() ? TGLClip::kInside : TGLClip::kOutside);
212  fM->SetAutoUpdate(fAutoUpdate->IsDown());
213 
214  Changed();
215 }
216 
217 ////////////////////////////////////////////////////////////////////////////////
218 /// Reset transformation of the current clip.
219 
220 void TGLClipSetSubEditor::ResetViewerClip()
221 {
222  if (fCurrentClip != TGLClip::kClipNone) {
223  if (fM->GetClipType() == TGLClip::kClipPlane) {
224  TGLPlane plane(0.0, -1.0, 0.0, 0.0);
225  dynamic_cast<TGLClipPlane*>(fM->GetCurrentClip())->Set(plane);
226  } else if (fM->GetClipType() == TGLClip::kClipBox) {
227  fM->GetCurrentClip()->SetTransform(TGLMatrix());
228  }
229  Changed();
230  }
231 }
232 
233 
234 /** \class TGLClipSetEditor
235 \ingroup opengl
236 GUI editor for TGLClipSet.
237 */
238 
239 ClassImp(TGLClipSetEditor);
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Constructor.
243 
244 TGLClipSetEditor::TGLClipSetEditor(const TGWindow *p, Int_t width, Int_t height,
245  UInt_t options, Pixel_t back) :
246  TGedFrame(p, width, height, options | kVerticalFrame, back),
247  fM (0),
248  fSE (0)
249 {
250  MakeTitle("TGLClipSet");
251 
252  fSE = new TGLClipSetSubEditor(this);
253  AddFrame(fSE, new TGLayoutHints(kLHintsTop, 2, 0, 2, 2));
254  fSE->Connect("Changed()", "TGLClipSetEditor", this, "Update()");
255 }
256 
257 
258 ////////////////////////////////////////////////////////////////////////////////
259 /// Set model object.
260 
261 void TGLClipSetEditor::SetModel(TObject* obj)
262 {
263  fM = dynamic_cast<TGLClipSet*>(obj);
264  fSE->SetModel(fM);
265 }