Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLPShapeObjEditor.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Matevz Tadel 25/09/2006
3
4#include <cstring>
5
7#include "TGLPShapeObj.h"
8#include "TGedEditor.h"
9
10#include "TG3DLine.h"
11#include "TGButton.h"
12#include "TGButtonGroup.h"
13#include "TString.h"
14#include "TGLabel.h"
15#include "TGSlider.h"
16#include "TGNumberEntry.h"
17#include "TROOT.h"
18#include "TVirtualMutex.h"
19
20#include "TVirtualX.h"
21#include "TGLViewer.h"
22#include "TGLUtil.h"
23#include "TGLPhysicalShape.h"
24#include "TGLWidget.h"
25#include "TGLIncludes.h"
26
27#include "Buttons.h"
28
29/** \class TGLPShapeObjEditor
30\ingroup opengl
31GUI editor for TGLPShapeObj.
32*/
33
34
44
53
64
65////////////////////////////////////////////////////////////////////////////////
66/// Constructor of TGLPhysicalShape editor GUI.
67
69 : TGedFrame(p, width, height, options | kVerticalFrame, back),
70 fLb(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 2, 3, 3), //button
71 fLe(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 0, 0, 3, 3), //entries
72 fLl(kLHintsLeft, 0, 8, 6, 0), // labels
73 fLs(kLHintsTop | kLHintsCenterX, 2, 2, 0, 0), ///sliders
74 fGeoFrame(nullptr),fGeoApplyButton(nullptr),
75 fColorFrame(nullptr),
76 fRedSlider(nullptr), fGreenSlider(nullptr), fBlueSlider(nullptr), fAlphaSlider(nullptr), fShineSlider(nullptr),
77 fColorApplyButton(nullptr), fColorApplyFamily(nullptr),
78 fRGBA(),
79 fPShapeObj(nullptr)
80{
81 fRGBA[12] = fRGBA[13] = fRGBA[14] = 0.0f;
82 fRGBA[15] = 1.0f;
83 fRGBA[16] = 60.0f;
84
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Destroy color editor GUI component.
91/// Done automatically.
92
96
97////////////////////////////////////////////////////////////////////////////////
98/// Shape has changed.
99/// Check if set to zero and make sure we're no longer in editor.
100
107
108////////////////////////////////////////////////////////////////////////////////
109/// Shape has been modified.
110/// Update editor if we're still shown. Otherwise unref.
111
119
120////////////////////////////////////////////////////////////////////////////////
121/// Sets model or disables/hides viewer.
122
135
136////////////////////////////////////////////////////////////////////////////////
137/// Set internal center data from 3 component 'c'.
138
145
146////////////////////////////////////////////////////////////////////////////////
147/// Set internal scale data from 3 component 'c'.
148
155
156////////////////////////////////////////////////////////////////////////////////
157/// Process 'Apply' - update the viewer object from GUI.
158
171
172////////////////////////////////////////////////////////////////////////////////
173/// Extract the GUI object data, return center in 3 component 'center'
174/// scale in 3 component 'scale'.
175
177{
178 center[0] = fGeomData[kCenterX]->GetNumber();
179 center[1] = fGeomData[kCenterY]->GetNumber();
180 center[2] = fGeomData[kCenterZ]->GetNumber();
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Process setting of value in edit box - activate 'Apply' button.
188
194
195////////////////////////////////////////////////////////////////////////////////
196/// Create GUI for setting scale and position.
197
199{
201
202 TGLabel *label=nullptr;
203
204 // Postion container
205 TGGroupFrame* container = new TGGroupFrame(fGeoFrame, "Object position:");
206 container->SetTitlePos(TGGroupFrame::kLeft);
209
211
213 label = new TGLabel(hf, "X:");
214 hf->AddFrame(label, new TGLayoutHints(fLl));
215 fGeomData[kCenterX] = new TGNumberEntry(hf, 0.0, 8, kNExc);
216 hf->AddFrame(fGeomData[kCenterX], new TGLayoutHints(fLe));
217 fGeomData[kCenterX]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
218 this, "GeoValueSet(Long_t)");
219 container->AddFrame(hf, new TGLayoutHints(lh));
220
222 label = new TGLabel(hf, "Y:");
223 hf->AddFrame(label, new TGLayoutHints(fLl));
224 fGeomData[kCenterY] = new TGNumberEntry(hf, 0.0, 8, kNEyc);
225 hf->AddFrame(fGeomData[kCenterY], new TGLayoutHints(fLe));
226 fGeomData[kCenterY]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
227 this, "GeoValueSet(Long_t)");
228 container->AddFrame(hf, new TGLayoutHints(lh));
229
231 hf->AddFrame(new TGLabel(hf, "Z:"), new TGLayoutHints(fLl));
232 fGeomData[kCenterZ] = new TGNumberEntry(hf, 1.0, 8, kNEzc);
233 hf->AddFrame(fGeomData[kCenterZ], new TGLayoutHints(fLe));
234 fGeomData[kCenterZ]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
235 this, "GeoValueSet(Long_t)");
236 container->AddFrame(hf, new TGLayoutHints(lh));
237
238 // Scale container
240 osf->SetTitlePos(TGGroupFrame::kLeft);
242
243 hf = new TGHorizontalFrame(osf);
244 hf->AddFrame(new TGLabel(hf, "X:"),new TGLayoutHints(fLl));
245 fGeomData[kScaleX] = new TGNumberEntry(hf, 1.0, 5, kNExs);
246 hf->AddFrame(fGeomData[kScaleX], new TGLayoutHints(fLe));
247 fGeomData[kScaleX]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
248 this, "GeoValueSet(Long_t)");
249 osf->AddFrame(hf, new TGLayoutHints(lh));
250
251 hf = new TGHorizontalFrame(osf);
252 hf->AddFrame(new TGLabel(hf, "Y:"),new TGLayoutHints(fLl));
253 fGeomData[kScaleY] = new TGNumberEntry(hf, 1.0, 5, kNEys);
254 hf->AddFrame(fGeomData[kScaleY], new TGLayoutHints(fLe));
255 fGeomData[kScaleY]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
256 this, "GeoValueSet(Long_t)");
257 osf->AddFrame(hf, new TGLayoutHints(lh));
258
259 hf = new TGHorizontalFrame(osf);
260 hf->AddFrame(new TGLabel(hf, "Z:"),new TGLayoutHints(fLl));
261 fGeomData[kScaleZ] = new TGNumberEntry(hf, 1.0, 5, kNEzs);
262 hf->AddFrame(fGeomData[kScaleZ], new TGLayoutHints(fLe));
263 fGeomData[kScaleZ]->Connect("ValueSet(Long_t)", "TGLPShapeObjEditor",
264 this, "GeoValueSet(Long_t)");
265 osf->AddFrame(hf, new TGLayoutHints(lh));
266
267 hf = new TGHorizontalFrame(osf);
271 osf->AddFrame(hf, new TGLayoutHints(lh));
272
273 // Modify button
274 fGeoApplyButton = new TGTextButton(fGeoFrame, "Modify object");
277 fGeoApplyButton->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoGeoButton()");
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Set color sliders from 17 component 'rgba'.
282
284{
287
288 for (Int_t i = 0; i < 17; ++i) fRGBA[i] = rgba[i];
289
291 fGreenSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 1] * 100));
292 fBlueSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 2] * 100));
294
295 DrawSphere();
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Process slider movement.
300
302{
304
305 if (frm) {
306 Int_t wid = frm->WidgetId();
307
308 switch (wid) {
309 case kHSr:
310 fRGBA[fLMode * 4] = val / 100.f;
311 break;
312 case kHSg:
313 fRGBA[fLMode * 4 + 1] = val / 100.f;
314 break;
315 case kHSb:
316 fRGBA[fLMode * 4 + 2] = val / 100.f;
317 break;
318 case kHSa:
319 fRGBA[fLMode * 4 + 3] = val / 100.f;
320 break;
321 case kHSs:
322 fRGBA[16] = val;
323 break;
324 }
325
328 DrawSphere();
329 }
330}
331
332////////////////////////////////////////////////////////////////////////////////
333/// Process button action.
334
336{
338 Int_t id = btn->WidgetId();
339
340 switch (id) {
341 case kCPd:
345 break;
346 case kCPa:
350 break;
351 case kCPs:
355 break;
356 case kCPe:
360 break;
361 case kTBa:
364 if (fPShape) {
366 }
368 break;
369 case kTBaf:
372 if (fPShape) {
374 }
376 break;
377 }
378}
379
380////////////////////////////////////////////////////////////////////////////////
381/// Create Diffuse/Ambient/Specular/Emissive radio buttons and sub-frames.
382
384{
387
388 partFrame->SetTitlePos(TGGroupFrame::kLeft);
389 TGMatrixLayout *ml = new TGMatrixLayout(partFrame, 0, 1, 10);
390 partFrame->SetLayoutManager(ml);
391
392 // partFrame will delete the layout manager ml for us so don't add to fTrash
393 fLightTypes[kDiffuse] = new TGRadioButton(partFrame, "Diffuse", kCPd);
394 fLightTypes[kDiffuse]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
395 fLightTypes[kDiffuse]->SetToolTipText("Diffuse component of color");
396 partFrame->AddFrame(fLightTypes[kDiffuse]);
397
398 fLightTypes[kAmbient] = new TGRadioButton(partFrame, "Ambient", kCPa);
399 fLightTypes[kAmbient]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
400 fLightTypes[kAmbient]->SetToolTipText("Ambient component of color");
401 partFrame->AddFrame(fLightTypes[kAmbient]);
402
403 fLightTypes[kSpecular] = new TGRadioButton(partFrame, "Specular", kCPs);
404 fLightTypes[kSpecular]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
405 fLightTypes[kSpecular]->SetToolTipText("Specular component of color");
406 partFrame->AddFrame(fLightTypes[kSpecular]);
407
408 fLightTypes[kEmission] = new TGRadioButton(partFrame, "Emissive", kCPe);
409 fLightTypes[kEmission]->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
410 fLightTypes[kEmission]->SetToolTipText("Emissive component of color");
411 partFrame->AddFrame(fLightTypes[kEmission]);
412
415}
416
417////////////////////////////////////////////////////////////////////////////////
418/// Create GUI for setting light color.
419
421{
422 UInt_t sw = 120; //fColorFrame->GetDefalutWidth();,
423
424 // Create Red/Green/BlueAlpha/Shine sliders
425 fColorFrame->AddFrame(new TGLabel(fColorFrame, "Red :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
427 fRedSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
428 fRedSlider->SetRange(0, 100);
429 fRedSlider->SetPosition(Int_t(fRGBA[0] * 100));
431
432
433 fColorFrame->AddFrame(new TGLabel(fColorFrame, "Green :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
435 fGreenSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
436 fGreenSlider->SetRange(0, 100);
439
440
441 fColorFrame->AddFrame(new TGLabel(fColorFrame, "Blue :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
443 fBlueSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
444 fBlueSlider->SetRange(0, 100);
447
448 fColorFrame->AddFrame(new TGLabel(fColorFrame, "Shine :"), new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 0, 0));
450 fShineSlider->Connect("PositionChanged(Int_t)", "TGLPShapeObjEditor", this, "DoColorSlider(Int_t)");
451 fShineSlider->SetRange(0, 128);
453}
454
455////////////////////////////////////////////////////////////////////////////////
456/// Update GUI sliders from internal data.
457
459{
461 fGreenSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 1] * 100));
462 fBlueSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 2] * 100));
463 // fAlphaSlider->SetPosition(Int_t(fRGBA[fLMode * 4 + 3] * 100));
464
465 if (fRGBA[16] >= 0.f)
467}
468
469////////////////////////////////////////////////////////////////////////////////
470/// Redraw widget. Render sphere and pass to base-class.
471
477
478////////////////////////////////////////////////////////////////////////////////
479
480namespace {
482 {
483 // GLU quadric.
484
485 static struct Init {
486 Init()
487 {
488 fQuad = gluNewQuadric();
489 if (!fQuad) {
490 Error("GetQuadric::Init", "could not create quadric object");
491 } else {
495 }
496 }
497 ~Init()
498 {
499 if(fQuad)
500 gluDeleteQuadric(fQuad);
501 }
502 GLUquadric *fQuad;
503 }singleton;
504
505 return singleton.fQuad;
506 }
507
508}
509
510////////////////////////////////////////////////////////////////////////////////
511/// Draw local sphere reflecting current color options.
512
514{
515 if (!gVirtualX->IsCmdThread()) {
516 gROOT->ProcessLineFast(Form("((TGLPShapeObjEditor *)0x%zx)->DrawSphere()", (size_t)this));
517 return;
518 }
519
521
525
533 glFrustum(-0.5, 0.5, -0.5, 0.5, 1., 10.);
536 Float_t ligPos[] = {0.f, 0.f, 0.f, 1.f};
538 glTranslated(0., 0., -3.);
539
540 const Float_t whiteColor[] = {1.f, 1.f, 1.f, 1.f};
541 const Float_t nullColor[] = {0.f, 0.f, 0.f, 1.f};
542
543 if (fRGBA[16] < 0.f) {
552 } else {
561 }
562
566 if (quad) {
567 glRotated(-90., 1., 0., 0.);
568 gluSphere(quad, 1., 100, 100);
569 }
571
573}
574
575////////////////////////////////////////////////////////////////////////////////
576/// Create widgets to chose colors component and its RGBA values on fGedEditor
577/// model or family it belongs to.
578
580{
581 fColorFrame = this;
582
583 fMatView = TGLWidget::Create(fColorFrame, kFALSE, kTRUE, nullptr, 120, 120);
585
587
589
590 //apply button creation
594 fColorApplyButton->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
595 //apply to family button creation
596 fColorApplyFamily = new TGTextButton(fColorFrame, "Apply to family", kTBaf);
599 fColorApplyFamily->Connect("Pressed()", "TGLPShapeObjEditor", this, "DoColorButton()");
600}
@ kButton1Down
Definition Buttons.h:17
@ kVerticalFrame
Definition GuiTypes.h:381
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define c(i)
Definition RSha256.hxx:101
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
@ kTBEndOfList
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
@ kScaleBoth
Definition TGSlider.h:36
@ kSlider1
Definition TGSlider.h:30
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize wid
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
R__EXTERN void * gTQSender
Definition TQObject.h:46
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:411
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2495
#define R__LOCKGUARD(mutex)
#define gVirtualX
Definition TVirtualX.h:337
A button abstract base class.
Definition TGButton.h:68
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition TGButton.cxx:439
virtual EButtonState GetState() const
Definition TGButton.h:112
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition TGButton.cxx:229
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
void DoRedraw() override
Redraw the frame.
Definition TGFrame.cxx:422
UInt_t GetHeight() const
Definition TGFrame.h:227
UInt_t GetWidth() const
Definition TGFrame.h:226
A composite frame with a border and a title.
Definition TGFrame.h:524
Concrete class for horizontal slider.
Definition TGSlider.h:119
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
void SetColorSlidersPos()
Update GUI sliders from internal data.
void PShapeModified() override
Shape has been modified.
void CreateColorSliders()
Create GUI for setting light color.
TGCompositeFrame * fColorFrame
TGButton * fLightTypes[4]
void CreateGeoControls()
Create GUI for setting scale and position.
TGNumberEntry * fGeomData[6]
void GeoValueSet(Long_t unusedVal)
Process setting of value in edit box - activate 'Apply' button.
void SetModel(TObject *obj) override
Sets model or disables/hides viewer.
void SetScale(const Double_t *scale)
Set internal scale data from 3 component 'c'.
void DoRedraw() override
Redraw widget. Render sphere and pass to base-class.
TGLPShapeObj * fPShapeObj
TGLPShapeObjEditor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor of TGLPhysicalShape editor GUI.
void DoColorButton()
Process button action.
~TGLPShapeObjEditor() override
Destroy color editor GUI component.
void DrawSphere() const
Draw local sphere reflecting current color options.
void CreateColorControls()
Create widgets to chose colors component and its RGBA values on fGedEditor model or family it belongs...
TGCompositeFrame * fGeoFrame
const Float_t * GetRGBA() const
void SetRGBA(const Float_t *rgba)
Set color sliders from 17 component 'rgba'.
void SetPShape(TGLPhysicalShape *shape) override
Shape has changed.
void CreateColorRadioButtons()
Create Diffuse/Ambient/Specular/Emissive radio buttons and sub-frames.
void SetCenter(const Double_t *center)
Set internal center data from 3 component 'c'.
void DoGeoButton()
Process 'Apply' - update the viewer object from GUI.
void GetObjectData(Double_t *shift, Double_t *scale)
Extract the GUI object data, return center in 3 component 'center' scale in 3 component 'scale'.
void DoColorSlider(Int_t val)
Process slider movement.
Wrap TGLPysicalShape into TObject so that it can be edited using GED.
TGLViewer * fViewer
TGLPhysicalShape * fPShape
virtual void SetPShape(TGLPhysicalShape *shape)
Set the shape.
TGLPhysicalShape * fPShape
Concrete physical shape - a GL drawable.
void Scale(const TGLVector3 &scale)
const Float_t * Color() const
TGLVector3 GetScale() const
void SetColor(const Float_t rgba[17])
Set full color attributes - see OpenGL material documentation for full description.
TGLVertex3 GetTranslation() const
void SetColorOnFamily(const Float_t rgba[17])
Set full color attributes to all physicals sharing the same logical with this object.
void SetTranslation(const TGLVertex3 &translation)
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
3 component (x/y/z) vertex class.
Definition TGLUtil.h:84
Double_t * Arr()
Definition TGLUtil.h:127
const Double_t * CArr() const
Definition TGLUtil.h:126
void RequestDraw(Short_t LOD=TGLRnrCtx::kLODMed)
Post request for redraw of viewer at level of detail 'LOD' Request is directed via cross thread gVirt...
static TGLWidget * Create(const TGWindow *parent, Bool_t selectInput, Bool_t shareDefault, const TGLPaintDevice *shareDevice, UInt_t width, UInt_t height)
Static constructor for creating widget with default pixel format.
Definition TGLWidget.cxx:82
Bool_t MakeCurrent() override
Make the gl-context current.
void SwapBuffers() override
Swap buffers.
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
This layout managers does not make use of TGLayoutHints.
Definition TGLayout.h:269
TGNumberEntry is a number entry input widget with up/down buttons.
virtual void SetLimits(ELimit limits=TGNumberFormat::kNELNoLimits, Double_t min=0, Double_t max=1)
virtual Double_t GetNumber() const
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
@ kNELLimitMin
Lower limit only.
Selects different options.
Definition TGButton.h:321
Slider widgets allow easy selection of a range.
Definition TGSlider.h:40
virtual void SetPosition(Int_t pos)
Set slider position.
Definition TGSlider.cxx:107
virtual void SetRange(Int_t min, Int_t max)
Set slider range.
Definition TGSlider.cxx:96
Yield an action as soon as it is clicked.
Definition TGButton.h:142
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void SetModel(TVirtualPad *pad, TObject *obj, Int_t event, Bool_t force=kFALSE)
Activate object editors according to the selected object.
virtual TVirtualPad * GetPad() const
Definition TGedEditor.h:78
virtual TObject * GetModel() const
Definition TGedEditor.h:79
Base frame for implementing GUI - a service class.
Definition TGedFrame.h:27
TGedEditor * fGedEditor
manager of this frame
Definition TGedFrame.h:48
virtual TGVerticalFrame * CreateEditorTabSubFrame(const char *name)
Create a vertical frame to be used by 'owner' in extra tab 'name'.
Mother of all ROOT objects.
Definition TObject.h:41
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition TQObject.cxx:865