From 9569e324769a7d83ec86aca4090e6666e8ebbe25 Mon Sep 17 00:00:00 2001 From: Matevz Tadel <matevz.tadel@cern.ch> Date: Mon, 28 Jan 2008 16:24:14 +0000 Subject: [PATCH] From Alja: Move rendering of axes from TEveProjectionManager to new class TEveProjectionAxes. Use TEveText functionality for rendering of tick-mark labels. Add new members for FTFont configuration in TEveText. New demo: tutorials/eve/projection_test.C. git-svn-id: http://root.cern.ch/svn/root/trunk@21881 27541ba8-7e3a-0410-8455-c3a389f83636 --- eve/Module.mk | 5 + eve/inc/LinkDef.h | 4 +- eve/inc/TEveProjectionAxes.h | 62 +++++ eve/inc/TEveProjectionAxesEditor.h | 56 ++++ eve/inc/TEveProjectionAxesGL.h | 68 +++++ eve/inc/TEveProjectionManager.h | 40 +-- eve/inc/TEveProjectionManagerEditor.h | 19 +- eve/inc/TEveProjectionManagerGL.h | 69 ----- eve/inc/TEveText.h | 18 +- eve/inc/TEveTextEditor.h | 9 +- eve/inc/TEveTextGL.h | 3 +- eve/src/TEveProjectionAxes.cxx | 86 ++++++ eve/src/TEveProjectionAxesEditor.cxx | 160 +++++++++++ eve/src/TEveProjectionAxesGL.cxx | 347 ++++++++++++++++++++++++ eve/src/TEveProjectionManager.cxx | 97 +++---- eve/src/TEveProjectionManagerEditor.cxx | 162 +---------- eve/src/TEveProjectionManagerGL.cxx | 322 ---------------------- eve/src/TEveText.cxx | 79 ++++-- eve/src/TEveTextEditor.cxx | 99 +++++-- eve/src/TEveTextGL.cxx | 83 ++---- eve/src/TEveTransEditor.cxx | 9 +- eve/src/TEveUtil.cxx | 3 + gl/inc/TFTGLManager.h | 25 +- gl/src/TFTGLManager.cxx | 98 ++++++- tutorials/eve/projection_test.C | 40 +++ tutorials/eve/text_test.C | 5 +- 26 files changed, 1190 insertions(+), 778 deletions(-) create mode 100644 eve/inc/TEveProjectionAxes.h create mode 100644 eve/inc/TEveProjectionAxesEditor.h create mode 100644 eve/inc/TEveProjectionAxesGL.h delete mode 100644 eve/inc/TEveProjectionManagerGL.h create mode 100644 eve/src/TEveProjectionAxes.cxx create mode 100644 eve/src/TEveProjectionAxesEditor.cxx create mode 100644 eve/src/TEveProjectionAxesGL.cxx delete mode 100644 eve/src/TEveProjectionManagerGL.cxx create mode 100644 tutorials/eve/projection_test.C diff --git a/eve/Module.mk b/eve/Module.mk index 524b69760ee..b7302b8c94e 100644 --- a/eve/Module.mk +++ b/eve/Module.mk @@ -79,3 +79,8 @@ eve/src/TEveText.o: \ $(FREETYPEDEP) eve/src/TEveText.o: \ CXXFLAGS += $(FREETYPEINC) $(FTGLINCDIR:%=-I%) + +eve/src/TEveProjectionAxesGL.o: \ + $(FREETYPEDEP) +eve/src/TEveProjectionAxesGL.o: \ + CXXFLAGS += $(FREETYPEINC) $(FTGLINCDIR:%=-I%) diff --git a/eve/inc/LinkDef.h b/eve/inc/LinkDef.h index e4d362da0ab..7ea41fb02c2 100644 --- a/eve/inc/LinkDef.h +++ b/eve/inc/LinkDef.h @@ -180,7 +180,9 @@ #pragma link C++ class TEveProjectionManager+; #pragma link C++ class TEveProjectionManagerEditor+; -#pragma link C++ class TEveProjectionManagerGL+; +#pragma link C++ class TEveProjectionAxes+; +#pragma link C++ class TEveProjectionAxesEditor+; +#pragma link C++ class TEveProjectionAxesGL+; #pragma link C++ class TEveTrackProjected+; #pragma link C++ class TEveTrackProjectedGL+; diff --git a/eve/inc/TEveProjectionAxes.h b/eve/inc/TEveProjectionAxes.h new file mode 100644 index 00000000000..72397a58b7b --- /dev/null +++ b/eve/inc/TEveProjectionAxes.h @@ -0,0 +1,62 @@ +// @(#)root/eve:$Id$ +// Author: Matevz Tadel 2007 + +/************************************************************************* + * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +#ifndef ROOT_TEveProjectionAxes +#define ROOT_TEveProjectionAxes + +#include "TEveText.h" + +class TEveProjectionManager; + +class TEveProjectionAxes : public TEveText +{ +public: + enum EMode { kPosition, kValue }; + +private: + TEveProjectionAxes(const TEveProjectionAxes&); // Not implemented + TEveProjectionAxes& operator=(const TEveProjectionAxes&); // Not implemented + +protected: + TEveProjectionManager* fManager; // model object + + Bool_t fDrawCenter; // draw center of distortion + Bool_t fDrawOrigin; // draw origin + + EMode fSplitMode; // bbox split mode + Int_t fSplitLevel; // num tick-mark = 2*(2^fSplitLevel) +1 + +public: + TEveProjectionAxes(TEveProjectionManager* m); + virtual ~TEveProjectionAxes(); + + TEveProjectionManager* GetManager(){ return fManager; } + + void SetSplitMode(EMode mode); + EMode GetSplitMode() const { return fSplitMode; } + void SetSplitLevel(Int_t x) { fSplitLevel = x; } + Int_t GetSplitLevel() const { return fSplitLevel; } + + void SetDrawCenter(Bool_t x){ fDrawCenter = x; } + Bool_t GetDrawCenter() const { return fDrawCenter; } + void SetDrawOrigin(Bool_t x){ fDrawOrigin = x; } + Bool_t GetDrawOrigin() const { return fDrawOrigin; } + + virtual void ComputeBBox(); + + virtual const TGPicture* GetListTreeIcon(); + + virtual Bool_t CanEditMainHMTrans() { return kFALSE;} + + ClassDef(TEveProjectionAxes, 1); // Short description. +}; + +#endif diff --git a/eve/inc/TEveProjectionAxesEditor.h b/eve/inc/TEveProjectionAxesEditor.h new file mode 100644 index 00000000000..a8ca83f0517 --- /dev/null +++ b/eve/inc/TEveProjectionAxesEditor.h @@ -0,0 +1,56 @@ +// @(#)root/eve:$Id$ +// Author: Matevz Tadel 2007 + +/************************************************************************* + * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +#ifndef ROOT_TEveProjectionAxesEditor +#define ROOT_TEveProjectionAxesEditor + +#include "TGedFrame.h" + +class TGCheckButton; +class TGComboBox; +class TGNumberEntry; + +class TEveProjectionAxes; + +class TEveProjectionAxesEditor : public TGedFrame +{ +private: + TEveProjectionAxesEditor(const TEveProjectionAxesEditor&); // Not implemented + TEveProjectionAxesEditor& operator=(const TEveProjectionAxesEditor&); // Not implemented + +protected: + TEveProjectionAxes *fM; // Model object. + + TGComboBox *fSplitMode; // tick-mark positioning widget + TGNumberEntry *fSplitLevel; // tick-mark density widget + + TGVerticalFrame *fCenterFrame; // Parent frame for Center tab. + TGCheckButton *fDrawCenter; // draw center widget + TGCheckButton *fDrawOrigin; // draw origin widget + +public: + TEveProjectionAxesEditor(const TGWindow* p=0, Int_t width=170, Int_t height=30, + UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground()); + virtual ~TEveProjectionAxesEditor() {} + + virtual void SetModel(TObject* obj); + + // Declare callback/slot methods + + void DoSplitMode(Int_t type); + void DoSplitLevel(); + void DoDrawCenter(); + void DoDrawOrigin(); + + ClassDef(TEveProjectionAxesEditor, 0); // GUI editor for TEveProjectionAxes. +}; + +#endif diff --git a/eve/inc/TEveProjectionAxesGL.h b/eve/inc/TEveProjectionAxesGL.h new file mode 100644 index 00000000000..358f497597d --- /dev/null +++ b/eve/inc/TEveProjectionAxesGL.h @@ -0,0 +1,68 @@ +// @(#)root/eve:$Id$ +// Author: Matevz Tadel 2007 + +/************************************************************************* + * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +#ifndef ROOT_TEveProjectionAxesGL +#define ROOT_TEveProjectionAxesGL + +#include "TEveTextGL.h" +#include <list> + +class FTFont; +class TEveProjectionAxes; +class TEveProjection; + +class TEveProjectionAxesGL : public TEveTextGL +{ +private: + TEveProjectionAxesGL(const TEveProjectionAxesGL&); // Not implemented + TEveProjectionAxesGL& operator=(const TEveProjectionAxesGL&); // Not implemented + + mutable Float_t fRange; // bounding box size in the current axis + const Float_t fLabelSize; // size of labels + const Float_t fLabelOff; // distance between labels and tick-marks + const Float_t fTMSize; // tick-mark size + + typedef std::pair<Float_t, Float_t> TM_t; + typedef std::list<TM_t> TMList_t; + + mutable TMList_t fTMList; // list of tick-mark position-value pairs + + void DrawTickMarks(Float_t tms) const; + void DrawHInfo() const; + void DrawVInfo() const; + const char* GetText(Float_t) const; + + void SplitInterval(Int_t axis) const; + void SplitIntervalByPos(Float_t min, Float_t max, Int_t axis, Int_t level)const; + void SplitIntervalByVal(Float_t min, Float_t max, Int_t axis, Int_t level)const; + + void SetRange(Float_t val, Int_t axis) const; + void RenderText(const char* txt, Float_t x, Float_t y) const; + +protected: + TEveProjectionAxes *fAxesModel; // model object. + mutable TEveProjection *fProjection; // cached model projection + +public: + TEveProjectionAxesGL(); + virtual ~TEveProjectionAxesGL() {} + + virtual Bool_t SetModel(TObject* obj, const Option_t* opt=0); + virtual void SetBBox(); + virtual void DirectDraw(TGLRnrCtx & rnrCtx) const; + + Bool_t IgnoreSizeForOfInterest() const { return kTRUE;} + + + ClassDef(TEveProjectionAxesGL, 0); // GL renderer class for TEveProjectionAxes. +}; + +#endif diff --git a/eve/inc/TEveProjectionManager.h b/eve/inc/TEveProjectionManager.h index 2abcf4d5e0f..d5059edd225 100644 --- a/eve/inc/TEveProjectionManager.h +++ b/eve/inc/TEveProjectionManager.h @@ -12,32 +12,24 @@ #ifndef ROOT_TEveProjectionManager #define ROOT_TEveProjectionManager -#include "TAtt3D.h" -#include "TAttBBox.h" - #include "TEveElement.h" #include "TEveProjections.h" #include "TEveVSDStructs.h" -class TEveProjectionManager : public TEveElementList, - public TAttBBox, - public TAtt3D +class TEveProjectionManager : public TEveElementList { private: TEveProjectionManager(const TEveProjectionManager&); // Not implemented TEveProjectionManager& operator=(const TEveProjectionManager&); // Not implemented - TEveProjection* fProjection; // projection - - Bool_t fDrawCenter; // draw center of distortion - Bool_t fDrawOrigin; // draw origin - TEveVector fCenter; // center of distortion +protected: + TEveProjection* fProjection; // projection + TEveVector fCenter; // center of distortion + Float_t fCurrentDepth; // z depth of object being projected - Int_t fSplitInfoMode; // tick-mark position - Int_t fSplitInfoLevel; // tick-mark density - Color_t fAxisColor; // color of axis + Float_t fBBox[6]; // projected children bounding box - Float_t fCurrentDepth; // z depth of object being projected + List_t fDependentEls; // elements that depend on manager and need to be destroyed with it virtual Bool_t ShouldImport(TEveElement* rnr_el); @@ -45,23 +37,14 @@ public: TEveProjectionManager(); virtual ~TEveProjectionManager(); + void AddDependent(TEveElement* el); + void RemoveDependent(TEveElement* el); + void SetProjection(TEveProjection::EPType_e type, Float_t distort=0); TEveProjection* GetProjection() { return fProjection; } virtual void UpdateName(); - void SetAxisColor(Color_t col) { fAxisColor = col; } - Color_t GetAxisColor() const { return fAxisColor; } - void SetSplitInfoMode(Int_t x) { fSplitInfoMode = x; } - Int_t GetSplitInfoMode() const { return fSplitInfoMode; } - void SetSplitInfoLevel(Int_t x) { fSplitInfoLevel = x; } - Int_t GetSplitInfoLevel() const { return fSplitInfoLevel; } - - void SetDrawCenter(Bool_t x){ fDrawCenter = x; } - Bool_t GetDrawCenter(){ return fDrawCenter; } - void SetDrawOrigin(Bool_t x){ fDrawOrigin = x; } - Bool_t GetDrawOrigin(){ return fDrawOrigin; } - void SetCenter(Float_t x, Float_t y, Float_t z); TEveVector& GetCenter(){return fCenter;} @@ -74,8 +57,7 @@ public: virtual void ProjectChildren(); virtual void ProjectChildrenRecurse(TEveElement* rnr_el); - virtual void ComputeBBox(); - virtual void Paint(Option_t* option = ""); + Float_t* GetBBox() { return &fBBox[0]; } ClassDef(TEveProjectionManager, 0); // Manager class for steering of projections and managing projected objects. }; diff --git a/eve/inc/TEveProjectionManagerEditor.h b/eve/inc/TEveProjectionManagerEditor.h index d9c8f2aa6e6..0d34d4bc8af 100644 --- a/eve/inc/TEveProjectionManagerEditor.h +++ b/eve/inc/TEveProjectionManagerEditor.h @@ -29,27 +29,18 @@ private: TEveProjectionManagerEditor& operator=(const TEveProjectionManagerEditor&); // Not implemented protected: - TEveProjectionManager *fM; // Model object. + TEveProjectionManager *fM; // Model object. - // projection TGComboBox *fType; // TEveProjection type widget TEveGValuator *fDistortion; // TEveProjection distortion widget TEveGValuator *fFixedRadius; // TEveProjection fixed-radius widget TEveGValuator *fCurrentDepth; // TEveProjection z-coordinate widget - // center - TGVerticalFrame *fCenterFrame; // Parent frame for Center tab. - TGCheckButton *fDrawCenter; // draw center widget - TGCheckButton *fDrawOrigin; // draw origin widget + TGVerticalFrame *fCenterFrame; // parent frame for distortion center TEveGValuator *fCenterX; // center x value widget TEveGValuator *fCenterY; // center y value widget TEveGValuator *fCenterZ; // center z value widget - // axis - TGColorSelect *fAxisColor; // color of axis widget - TGComboBox *fSIMode; // tick-mark positioning widget - TGNumberEntry *fSILevel; // tick-mark density widget - public: TEveProjectionManagerEditor(const TGWindow* p=0, Int_t width=170, Int_t height=30, UInt_t options = kChildFrame, Pixel_t back=GetDefaultFrameBackground()); virtual ~TEveProjectionManagerEditor(){} @@ -58,16 +49,10 @@ public: // Declare callback/slot methods - void DoSplitInfoMode(Int_t type); - void DoSplitInfoLevel(); - void DoAxisColor(Pixel_t pixel); - void DoType(Int_t type); void DoDistortion(); void DoFixedRadius(); void DoCurrentDepth(); - void DoDrawCenter(); - void DoDrawOrigin(); void DoCenter(); ClassDef(TEveProjectionManagerEditor, 0); // Editor for TEveProjectionManager class. diff --git a/eve/inc/TEveProjectionManagerGL.h b/eve/inc/TEveProjectionManagerGL.h deleted file mode 100644 index 0fc22ceb661..00000000000 --- a/eve/inc/TEveProjectionManagerGL.h +++ /dev/null @@ -1,69 +0,0 @@ -// @(#)root/eve:$Id$ -// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 - -/************************************************************************* - * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TEveProjectionManagerGL -#define ROOT_TEveProjectionManagerGL - -#include "TGLObject.h" -#include "TEveElement.h" - -class TGLViewer; -class TGLScene; -class TGLText; - -class TEveProjectionManager; - -class TEveProjectionManagerGL : public TGLObject -{ -public: - typedef std::list<Float_t> TMList_t; - -private: - TEveProjectionManagerGL(const TEveProjectionManagerGL&); // Not implemented - TEveProjectionManagerGL& operator=(const TEveProjectionManagerGL&); // Not implemented - - mutable TMList_t fPos; // current tick-mark position - mutable TMList_t fVals; // current tick-mark value - - mutable Float_t fRange; // bounding box size in the current axis - Float_t fLabelSize; // size of labels - Float_t fLabelOff; // distance between labels and tick-marks - Float_t fTMSize; // tick-mark size - - void DrawTickMarks(Float_t tms) const; - void DrawHInfo() const; - void DrawVInfo() const; - const char* GetText(Float_t) const; - - void SplitInterval(Int_t axis) const; - void SplitIntervalByPos(Float_t min, Float_t max, Int_t axis, Int_t level)const; - void SplitIntervalByVal(Float_t min, Float_t max, Int_t axis, Int_t level)const; - - void SetRange(Float_t val, Int_t axis) const; - -protected: - TEveProjectionManager *fM; // Model object. - TGLText *fText; // Text renderer for axis labels. - -public: - TEveProjectionManagerGL(); - virtual ~TEveProjectionManagerGL() {} - - virtual Bool_t SetModel(TObject* obj, const Option_t* opt=0); - virtual void SetBBox(); - virtual void DirectDraw(TGLRnrCtx & rnrCtx) const; - - Bool_t IgnoreSizeForOfInterest() const { return kTRUE;} - - ClassDef(TEveProjectionManagerGL, 0); // GL-renderer for TEveProjectionManager. -}; - -#endif diff --git a/eve/inc/TEveText.h b/eve/inc/TEveText.h index 0d2df96a746..1bbf7766678 100644 --- a/eve/inc/TEveText.h +++ b/eve/inc/TEveText.h @@ -35,13 +35,15 @@ protected: Int_t fSize; // face size Int_t fFile; // font file name Int_t fMode; // FTGL class + Float_t fExtrude; // extrude depth + Bool_t fAutoBehave; // use defaults Bool_t fLighting; // enable GL lighting - Float_t fExtrude; // extrude depth + TEveTrans fHMTrans; // overall transformation public: - TEveText(const Text_t* txt); + TEveText(const Text_t* txt=""); virtual ~TEveText() {} virtual Bool_t CanEditMainColor() { return kTRUE; } @@ -51,7 +53,12 @@ public: Int_t GetSize() const { return fSize; } Int_t GetFile() const { return fFile; } Int_t GetMode() const { return fMode; } - void SetFont(Int_t size, Int_t file, Int_t mode); + void SetFontSize(Int_t size, Bool_t validate = kTRUE); + void SetFontFile(Int_t file){ fFile = file; } + void SetFontFile(const char* name); + void SetFontMode(Int_t mode); + + Int_t GetValidFontSize(Float_t val); const Text_t* GetText() const { return fText.Data(); } void SetText(const Text_t* t) { fText = t; } @@ -59,12 +66,17 @@ public: Bool_t GetLighting() const { return fLighting; } void SetLighting(Bool_t isOn) { fLighting = isOn; } + Bool_t GetAutoBehave() const { return fAutoBehave; } + void SetAutoBehave(Bool_t isOn) { fAutoBehave = isOn; } + Float_t GetExtrude() const { return fExtrude; } void SetExtrude(Float_t x) { fExtrude = x; } virtual Bool_t CanEditMainHMTrans() { return kTRUE; } virtual TEveTrans* PtrMainHMTrans() { return &fHMTrans; } + virtual const TGPicture* GetListTreeIcon(); + ClassDef(TEveText, 0); // Class for visualisation of text with FTGL font. }; diff --git a/eve/inc/TEveTextEditor.h b/eve/inc/TEveTextEditor.h index 70833dd3879..b646af854cf 100644 --- a/eve/inc/TEveTextEditor.h +++ b/eve/inc/TEveTextEditor.h @@ -36,9 +36,10 @@ protected: TGComboBox *fSize; TGComboBox *fFile; TGComboBox *fMode; + TEveGValuator *fExtrude; TGCheckButton *fLighting; - TEveGValuator *fExtrude; + TGCheckButton *fAutoBehave; public: TEveTextEditor(const TGWindow* p=0, Int_t width=170, Int_t height=30, @@ -48,9 +49,13 @@ public: virtual void SetModel(TObject* obj); void DoText(const Text_t*); - void DoFont(); + + void DoFontSize(); + void DoFontFile(); + void DoFontMode(); void DoLighting(); + void DoAutoBehave(); void DoExtrude(); ClassDef(TEveTextEditor, 0); // GUI editor for TEveText. diff --git a/eve/inc/TEveTextGL.h b/eve/inc/TEveTextGL.h index b7ebcf5129a..3b18221bac0 100644 --- a/eve/inc/TEveTextGL.h +++ b/eve/inc/TEveTextGL.h @@ -23,16 +23,17 @@ private: TEveTextGL(const TEveTextGL&); // Not implemented TEveTextGL& operator=(const TEveTextGL&); // Not implemented +protected: mutable Int_t fSize; // current font size mutable Int_t fFile; // current font file mutable Int_t fMode; // current FTGL class mutable FTFont *fFont; // FTGL font object -protected: TEveText *fM; // model object. mutable Double_t fX[4][3]; // 3D position of font + void SetModelFont( TEveText* model, TGLRnrCtx & rnrCtx) const; public: TEveTextGL(); virtual ~TEveTextGL() {} diff --git a/eve/src/TEveProjectionAxes.cxx b/eve/src/TEveProjectionAxes.cxx new file mode 100644 index 00000000000..3971127e2e4 --- /dev/null +++ b/eve/src/TEveProjectionAxes.cxx @@ -0,0 +1,86 @@ +// @(#)root/eve:$Id$ +// Author: Matevz Tadel 2007 + +/************************************************************************* + * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +#include "TEveProjectionAxes.h" +#include "TEveProjectionManager.h" +#include "TMath.h" + + +// Axes for non-linear projections. Show scale of TEveProjectionManager +// children. With different step mode tick-marks can positioned +// equidistant or placed with value monotonically increasing from lower left corner +// of bounding box. + +ClassImp(TEveProjectionAxes); + +//______________________________________________________________________________ +TEveProjectionAxes::TEveProjectionAxes(TEveProjectionManager* m) : + TEveText("ProjectionAxes"), + fManager(m), + + fDrawCenter(kFALSE), + fDrawOrigin(kFALSE), + + fSplitMode(kPosition), + fSplitLevel(1) +{ + // Constructor. + + SetName("ProjectionAxes"); + fText = "Axes Title"; + + fManager->AddDependent(this); +} + +//______________________________________________________________________________ +TEveProjectionAxes::~TEveProjectionAxes() +{ + // Destructor. + + fManager->RemoveDependent(this); +} + +//______________________________________________________________________________ +void TEveProjectionAxes::ComputeBBox() +{ + // Virtual from TAttBBox; fill bounding-box information. + + static const TEveException eH("TEveProjectionManager::ComputeBBox "); + + BBoxZero(); + if(fManager == 0) + return; + + for (Int_t i=0; i<6; ++i) + fBBox[i] = fManager->GetBBox()[i]; + + AssertBBoxExtents(0.1); + { + using namespace TMath; + fBBox[0] = 10.0f * Floor(fBBox[0]/10.0f); + fBBox[1] = 10.0f * Ceil (fBBox[1]/10.0f); + fBBox[2] = 10.0f * Floor(fBBox[2]/10.0f); + fBBox[3] = 10.0f * Ceil (fBBox[3]/10.0f); + } +} + +//______________________________________________________________________________ +void TEveProjectionAxes::SetSplitMode( EMode mode) +{ + fSplitMode = mode; +} + +//______________________________________________________________________________ +const TGPicture* TEveProjectionAxes::GetListTreeIcon() +{ + //return pointset icon + return TEveElement::fgListTreeIcons[6]; +} diff --git a/eve/src/TEveProjectionAxesEditor.cxx b/eve/src/TEveProjectionAxesEditor.cxx new file mode 100644 index 00000000000..eba01b1e908 --- /dev/null +++ b/eve/src/TEveProjectionAxesEditor.cxx @@ -0,0 +1,160 @@ +// @(#)root/eve:$Id$ +// Author: Matevz Tadel 2007 + +/************************************************************************* + * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +#include "TEveProjectionAxesEditor.h" +#include "TEveProjectionAxes.h" + +#include "TGNumberEntry.h" +#include "TGComboBox.h" +#include "TGButton.h" +#include "TGLabel.h" +#include "TG3DLine.h" +#include "TGNumberEntry.h" + +//______________________________________________________________________________ +// GUI editor for TEveProjectionAxes. +// + +ClassImp(TEveProjectionAxesEditor); + +//______________________________________________________________________________ +TEveProjectionAxesEditor::TEveProjectionAxesEditor(const TGWindow *p, Int_t width, Int_t height, + UInt_t options, Pixel_t back) : + TGedFrame(p, width, height, options | kVerticalFrame, back), + fM(0), + + fSplitMode(0), + fSplitLevel(0), + + fCenterFrame(0), + fDrawCenter(0), + fDrawOrigin(0) +{ + // Constructor. + + MakeTitle("TEveProjectionAxis"); + { + TGHorizontalFrame* f = new TGHorizontalFrame(this); + TGLabel* lab = new TGLabel(f, "StepMode"); + f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 6, 1, 2)); + fSplitMode = new TGComboBox(f, "Position"); + fSplitMode->AddEntry("Value", 1); + fSplitMode->AddEntry("Position", 0); + fSplitMode->GetTextEntry()->SetToolTipText("Set tick-marks on equidistant values/screen position."); + TGListBox* lb = fSplitMode->GetListBox(); + lb->Resize(lb->GetWidth(), 2*18); + fSplitMode->Resize(80, 20); + fSplitMode->Connect("Selected(Int_t)", "TEveProjectionAxesEditor", + this, "DoSplitMode(Int_t)"); + f->AddFrame(fSplitMode, new TGLayoutHints(kLHintsTop, 1, 1, 1, 1)); + AddFrame(f); + } + { + TGHorizontalFrame* f = new TGHorizontalFrame(this); + TGLabel* lab = new TGLabel(f, "SplitLevel"); + f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 8, 1, 2)); + + fSplitLevel = new TGNumberEntry(f, 0, 3, -1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, + TGNumberFormat::kNELLimitMinMax, 0, 7); + fSplitLevel->GetNumberEntry()->SetToolTipText("Number of tick-marks TMath::Power(2, level)."); + fSplitLevel->Connect("ValueSet(Long_t)", "TEveProjectionAxesEditor", this, "DoSplitLevel()"); + f->AddFrame(fSplitLevel, new TGLayoutHints(kLHintsTop, 1, 1, 1, 2)); + AddFrame(f, new TGLayoutHints(kLHintsTop, 0, 0, 0, 3) ); + } + + /**************************************************************************/ + // center tab + fCenterFrame = CreateEditorTabSubFrame("Center"); + + TGCompositeFrame *title1 = new TGCompositeFrame(fCenterFrame, 180, 10, + kHorizontalFrame | + kLHintsExpandX | + kFixedWidth | + kOwnBackground); + title1->AddFrame(new TGLabel(title1, "Distortion Center"), + new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0)); + title1->AddFrame(new TGHorizontal3DLine(title1), + new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7)); + fCenterFrame->AddFrame(title1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0)); + + + { + + TGHorizontalFrame* hf1 = new TGHorizontalFrame(fCenterFrame); + + fDrawOrigin = new TGCheckButton(hf1, "DrawOrigin"); + hf1->AddFrame(fDrawOrigin, new TGLayoutHints(kLHintsLeft, 2,1,0,4)); + fDrawOrigin->Connect("Toggled(Bool_t)"," TEveProjectionAxesEditor", this, "DoDrawOrigin()"); + + + fDrawCenter = new TGCheckButton(hf1, "DrawCenter"); + hf1->AddFrame(fDrawCenter, new TGLayoutHints(kLHintsLeft, 2,1,0,4)); + fDrawCenter->Connect("Toggled(Bool_t)"," TEveProjectionAxesEditor", this, "DoDrawCenter()"); + + fCenterFrame->AddFrame(hf1, new TGLayoutHints(kLHintsTop, 0,0,0,0)); + + } +} + +/******************************************************************************/ + +//______________________________________________________________________________ +void TEveProjectionAxesEditor::SetModel(TObject* obj) +{ + // Set model object. + + fM = dynamic_cast<TEveProjectionAxes*>(obj); + + fSplitMode->Select(fM->GetSplitMode(), kFALSE); + fSplitLevel->SetNumber(fM->GetSplitLevel()); + + fDrawCenter->SetState(fM->GetDrawCenter() ? kButtonDown : kButtonUp); + fDrawOrigin->SetState(fM->GetDrawOrigin() ? kButtonDown : kButtonUp); + +} + +//______________________________________________________________________________ +void TEveProjectionAxesEditor::DoDrawOrigin() +{ + // Slot for setting draw of origin. + + fM->SetDrawOrigin(fDrawOrigin->IsOn()); + Update(); +} + +//______________________________________________________________________________ +void TEveProjectionAxesEditor::DoDrawCenter() +{ + // Slot for setting draw of center. + + fM->SetDrawCenter(fDrawCenter->IsOn()); + Update(); +} + +//______________________________________________________________________________ +void TEveProjectionAxesEditor::DoSplitMode(Int_t mode) +{ + // Slot for setting split info mode. + + TEveProjectionAxes::EMode em = (TEveProjectionAxes::EMode ) mode; + fM->SetSplitMode(em); + Update(); +} + +//______________________________________________________________________________ +void TEveProjectionAxesEditor::DoSplitLevel() +{ + // Slot for setting tick-mark density. + + fM->SetSplitLevel((Int_t)fSplitLevel->GetNumber()); + Update(); +} + diff --git a/eve/src/TEveProjectionAxesGL.cxx b/eve/src/TEveProjectionAxesGL.cxx new file mode 100644 index 00000000000..f1799e8c35c --- /dev/null +++ b/eve/src/TEveProjectionAxesGL.cxx @@ -0,0 +1,347 @@ +// @(#)root/eve:$Id$ +// Author: Matevz Tadel 2007 + +/************************************************************************* + * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +#include "TEveProjectionAxesGL.h" +#include "TEveProjectionAxes.h" +#include "TEveProjectionManager.h" + +#include "TGLRnrCtx.h" +#include "TGLIncludes.h" +#include "TFTGLManager.h" +#include "FTFont.h" +#include "TMath.h" + +//______________________________________________________________________________ +// OpenGL renderer class for TEveProjectionAxes. +// + +ClassImp(TEveProjectionAxesGL); + +//______________________________________________________________________________ +// TEveProjectionAxesGL +// +// GL-renderer for TEveProjectionAxes. + + +//______________________________________________________________________________ +TEveProjectionAxesGL::TEveProjectionAxesGL() : + TEveTextGL(), + + fRange(300), + fLabelSize(0.02), + fLabelOff(0.5), + fTMSize(0.02), + + fAxesModel(0), + fProjection(0) +{ + // Constructor. + + fDLCache = kFALSE; // Disable display list. +} + +/******************************************************************************/ + +//______________________________________________________________________________ +Bool_t TEveProjectionAxesGL::SetModel(TObject* obj, const Option_t* /*opt*/) +{ + // Set model object. + // Virtual from TGLObject. + + if (SetModelCheckClass(obj, TEveProjectionAxes::Class())) { + fAxesModel = dynamic_cast<TEveProjectionAxes*>(obj); + if( fAxesModel->GetManager() == 0) + return kFALSE; + return kTRUE; + } + return kFALSE; +} + +//______________________________________________________________________________ +void TEveProjectionAxesGL::SetBBox() +{ + // Fill the bounding-box data of the logical-shape. + // Virtual from TGLObject. + + // !! This ok if master sub-classed from TAttBBox + SetAxisAlignedBBox(((TEveProjectionAxes*)fExternalObj)->AssertBBox()); +} +/******************************************************************************/ + +//______________________________________________________________________________ +const char* TEveProjectionAxesGL::GetText(Float_t x) const +{ + // Get formatted text. + + using namespace TMath; + if (Abs(x) > 1000) { + Float_t v = 10*TMath::Nint(x/10.0f); + return Form("%.0f", v); + } else if(Abs(x) > 100) { + Float_t v = TMath::Nint(x); + return Form("%.0f", v); + } else if (Abs(x) > 10) + return Form("%.1f", x); + else if ( Abs(x) > 1 ) + return Form("%.2f", x); + else // zero + return Form("%.1f", x); +} + +//______________________________________________________________________________ +void TEveProjectionAxesGL::RenderText(const char* txt, Float_t x, Float_t y) const +{ + // Render FTFont at given location. + + if (fMode < TFTGLManager::kTexture) { + glRasterPos3f(0, 0, 0); + glBitmap(0, 0, 0, 0, x, y, 0); + fFont->Render(txt); + } else { + glPushMatrix(); + glTranslatef(x, y, 0); + fFont->Render(txt); + glPopMatrix(); + } +} + +/******************************************************************************/ + +//______________________________________________________________________________ +void TEveProjectionAxesGL::SetRange(Float_t pos, Int_t ax) const +{ + // Set range from bounding box. + + using namespace TMath; + + Float_t limit = fProjection->GetLimit(ax, pos > 0 ? kTRUE: kFALSE); + if (fProjection->GetDistortion() > 0.001 && Abs(pos) > Abs(limit *0.97)) + { + pos = limit*0.95; + } + + fTMList.push_back(TM_t(pos, fProjection->GetValForScreenPos(ax, pos))); +} + +/******************************************************************************/ + +//______________________________________________________________________________ +void TEveProjectionAxesGL::DrawTickMarks(Float_t y) const +{ + // Draw tick-marks on the current axis. + + glBegin(GL_LINES); + for (std::list<TM_t>::iterator it = fTMList.begin(); it!= fTMList.end(); ++it) + { + glVertex2f((*it).first, 0); + glVertex2f((*it).first, y); + } + glEnd(); +} + +//______________________________________________________________________________ +void TEveProjectionAxesGL::DrawHInfo() const +{ + // Draw labels on horizontal axis. + + Float_t tmH = fTMSize*fRange; + DrawTickMarks(-tmH); + + Float_t off = tmH + fLabelOff*tmH; + Float_t llx, lly, llz, urx, ury, urz; + const char* txt; + for (std::list<TM_t>::iterator it = fTMList.begin(); it!= fTMList.end(); ++it) + { + glPushMatrix(); + glTranslatef((*it).first, -off, 0); + txt = GetText((*it).second); + fFont->BBox(txt, llx, lly, llz, urx, ury, urz); + Float_t xd = -0.5f*(urx+llx); + if (txt[0] == '-') + xd -= 0.5f * (urx-llx) / strlen(txt); + RenderText(txt, xd, -ury); + glPopMatrix(); + } + + fTMList.clear(); +} + +//______________________________________________________________________________ +void TEveProjectionAxesGL::DrawVInfo() const +{ + // Draw labels on vertical axis. + + Float_t tmH = fTMSize*fRange; + + glPushMatrix(); + glRotatef(90, 0, 0, 1); + DrawTickMarks(tmH); + glPopMatrix(); + + Float_t off = fLabelOff*tmH + tmH; + Float_t llx, lly, llz, urx, ury, urz; + const char* txt; + for (std::list<TM_t>::iterator it = fTMList.begin(); it!= fTMList.end(); ++it) + { + glPushMatrix(); + glTranslatef(-off, (*it).first, 0); + txt = GetText((*it).second); + fFont->BBox(txt, llx, lly, llz, urx, ury, urz); + RenderText(txt, -urx, -0.38f*(ury+lly)); + glPopMatrix(); + } + + fTMList.clear(); +} + +/******************************************************************************/ + +//______________________________________________________________________________ +void TEveProjectionAxesGL::SplitInterval(Int_t ax) const +{ + // Build a list of labels and their positions. + + if (fAxesModel->GetSplitLevel()) + { + if (fAxesModel->GetSplitMode() == TEveProjectionAxes::kValue) + { + SplitIntervalByVal(fTMList.front().second, fTMList.back().second, ax, 0); + } + else if (fAxesModel->GetSplitMode() == TEveProjectionAxes::kPosition) + { + SplitIntervalByPos(fTMList.front().first, fTMList.back().first, ax, 0); + } + } +} + +//______________________________________________________________________________ +void TEveProjectionAxesGL::SplitIntervalByPos(Float_t minp, Float_t maxp, Int_t ax, Int_t level) const +{ + // Add tick-mark and label with position in the middle of given interval. + + Float_t p = (minp+maxp)*0.5; + Float_t v = fProjection->GetValForScreenPos(ax, p); + fTMList.push_back(TM_t(p, v)); + + level++; + if (level<fAxesModel->GetSplitLevel()) + { + SplitIntervalByPos(minp, p , ax, level); + SplitIntervalByPos(p, maxp, ax, level); + } +} + +//______________________________________________________________________________ +void TEveProjectionAxesGL::SplitIntervalByVal(Float_t minv, Float_t maxv, Int_t ax, Int_t level) const +{ + // Add tick-mark and label with value in the middle of given interval. + + Float_t v = (minv+maxv)*0.5; + Float_t p = fProjection->GetScreenVal(ax, v); + fTMList.push_back(TM_t(p, v)); + + level++; + if (level<fAxesModel->GetSplitLevel()) + { + SplitIntervalByVal(minv, v , ax, level); + SplitIntervalByVal(v, maxv, ax, level); + } +} + +/******************************************************************************/ + +//______________________________________________________________________________ +void TEveProjectionAxesGL::DirectDraw(TGLRnrCtx& rnrCtx) const +{ + // Actual rendering code. + // Virtual from TGLLogicalShape. + + fProjection = fAxesModel->GetManager()->GetProjection(); + + Float_t* bbox = fAxesModel->GetBBox(); + fRange = bbox[1] - bbox[0]; + TEveVector zeroPos; + fProjection->ProjectVector(zeroPos); + + SetModelFont(fAxesModel, rnrCtx); + TFTGLManager::PreRender(fMode); + { + glPushMatrix(); + glTranslatef(0, bbox[2], 0); + // left + fTMList.push_back(TM_t(zeroPos.fX, 0)); + SetRange(bbox[0], 0); SplitInterval(0); + DrawHInfo(); + // right, skip middle + fTMList.push_back(TM_t(zeroPos.fX, 0)); + SetRange(bbox[1], 0); SplitInterval(0); fTMList.pop_front(); + DrawHInfo(); + glPopMatrix(); + } + { + glPushMatrix(); + glTranslatef(bbox[0], 0, 0); + // labels bottom + fTMList.push_back(TM_t(zeroPos.fY, 0)); + SetRange(bbox[2], 1); SplitInterval(1); + DrawVInfo(); + // labels top, skip middle + fTMList.push_back(TM_t(zeroPos.fY, 0)); + SetRange(bbox[3], 1); SplitInterval(1); fTMList.pop_front(); + DrawVInfo(); + glPopMatrix(); + } + + // axes title + glPushMatrix(); + glTranslatef(zeroPos.fX, bbox[3]*1.1, 0); + Float_t llx, lly, llz, urx, ury, urz; + fFont->BBox(fAxesModel->GetText(), llx, lly, llz, urx, ury, urz); + RenderText(fAxesModel->GetText(), -llx, 0); + glPopMatrix(); + + TFTGLManager::PostRender(fMode); + + // axes lines + glBegin(GL_LINES); + glVertex3f(bbox[0], bbox[2], 0.); + glVertex3f(bbox[1], bbox[2], 0.); + glVertex3f(bbox[0], bbox[2], 0.); + glVertex3f(bbox[0], bbox[3], 0.); + glEnd(); + + // projection center + Float_t d = 10; + if (fAxesModel->GetDrawCenter()) { + Float_t* c = fProjection->GetProjectedCenter(); + TGLUtil::Color3f(1., 0., 0.); + glBegin(GL_LINES); + glVertex3f(c[0] +d, c[1], c[2]); glVertex3f(c[0] - d, c[1] , c[2]); + glVertex3f(c[0] , c[1] +d, c[2]); glVertex3f(c[0] , c[1] -d, c[2]); + glVertex3f(c[0] , c[1], c[2] + d); glVertex3f(c[0] , c[1] , c[2] - d); + glEnd(); + } + + if (fAxesModel->GetDrawOrigin()) { + TEveVector zero; + fProjection->ProjectVector(zero); + TGLUtil::Color3f(1., 1., 1.); + glBegin(GL_LINES); + glVertex3f(zero[0] +d, zero[1], zero[2]); glVertex3f(zero[0] - d, zero[1] , zero[2]); + glVertex3f(zero[0] , zero[1] +d, zero[2]); glVertex3f(zero[0] , zero[1] -d, zero[2]); + glVertex3f(zero[0] , zero[1], zero[2] + d); glVertex3f(zero[0] , zero[1] , zero[2] - d); + glEnd(); + } + + fProjection = 0; +} + + diff --git a/eve/src/TEveProjectionManager.cxx b/eve/src/TEveProjectionManager.cxx index e02e445e77d..d7801a447d6 100644 --- a/eve/src/TEveProjectionManager.cxx +++ b/eve/src/TEveProjectionManager.cxx @@ -13,6 +13,7 @@ #include "TEveManager.h" #include "TEveProjectionBases.h" +#include "TAttBBox.h" #include "TBuffer3D.h" #include "TBuffer3DTypes.h" #include "TVirtualPad.h" @@ -37,16 +38,7 @@ ClassImp(TEveProjectionManager) //______________________________________________________________________________ TEveProjectionManager::TEveProjectionManager(): TEveElementList("TEveProjectionManager",""), - fProjection (0), - - fDrawCenter(kFALSE), - fDrawOrigin(kFALSE), - - fSplitInfoMode(0), - fSplitInfoLevel(1), - fAxisColor(0), - fCurrentDepth(0) { // Constructor. @@ -59,8 +51,29 @@ TEveProjectionManager::TEveProjectionManager(): TEveProjectionManager::~TEveProjectionManager() { // Destructor. + // Destroys also dependent elements. + + if (fProjection) delete fProjection; + while ( ! fDependentEls.empty()) + { + fDependentEls.front()->Destroy(); + } +} + +//______________________________________________________________________________ +void TEveProjectionManager::AddDependent(TEveElement* el) +{ + // Add el as dependent element. - if(fProjection) delete fProjection; + fDependentEls.push_back(el); +} + +//______________________________________________________________________________ +void TEveProjectionManager::RemoveDependent(TEveElement* el) +{ + // Remove el as dependent element. + + fDependentEls.remove(el); } //______________________________________________________________________________ @@ -191,11 +204,20 @@ void TEveProjectionManager::ProjectChildrenRecurse(TEveElement* rnr_el) { pted->UpdateProjection(); TAttBBox* bb = dynamic_cast<TAttBBox*>(pted); - if(bb) + if (bb) { - Float_t* b = bb->AssertBBox(); - BBoxCheckPoint(b[0], b[2], b[4]); - BBoxCheckPoint(b[1], b[3], b[5]); + Float_t x, y, z, *b = bb->AssertBBox(); + // Float_t x, y, z; + x = b[0]; y = b[2]; z = b[4]; + if (x < fBBox[0]) fBBox[0] = x; if (x > fBBox[1]) fBBox[1] = x; + if (y < fBBox[2]) fBBox[2] = y; if (y > fBBox[3]) fBBox[3] = y; + if (z < fBBox[4]) fBBox[4] = z; if (z > fBBox[5]) fBBox[5] = z; + + x = b[1]; y = b[3]; z = b[5]; + if (x < fBBox[0]) fBBox[0] = x; if (x > fBBox[1]) fBBox[1] = x; + if (y < fBBox[2]) fBBox[2] = y; if (y > fBBox[3]) fBBox[3] = y; + if (z < fBBox[4]) fBBox[4] = z; if (z > fBBox[5]) fBBox[5] = z; + } rnr_el->ElementChanged(kFALSE); } @@ -210,52 +232,13 @@ void TEveProjectionManager::ProjectChildren() // Project children recursevly, update BBox and notify ReveManger // the scenes have chenged. - BBoxZero(); - ProjectChildrenRecurse(this); - AssertBBoxExtents(0.1); - { - using namespace TMath; - fBBox[0] = 10.0f * Floor(fBBox[0]/10.0f); - fBBox[1] = 10.0f * Ceil (fBBox[1]/10.0f); - fBBox[2] = 10.0f * Floor(fBBox[2]/10.0f); - fBBox[3] = 10.0f * Ceil (fBBox[3]/10.0f); + for (Int_t i = 0; i<6; i++) { + fBBox[i] = 0.f; } + ProjectChildrenRecurse(this); + List_t scenes; CollectSceneParentsFromChildren(scenes, 0); gEve->ScenesChanged(scenes); } - -//______________________________________________________________________________ -void TEveProjectionManager::Paint(Option_t* /*option*/) -{ - // Paint this object. Only direct rendering is supported. - - static const TEveException eH("TEveProjectionManager::Paint "); - TBuffer3D buff(TBuffer3DTypes::kGeneric); - - // Section kCore - buff.fID = this; - buff.fColor = fAxisColor; - buff.fTransparency = 0; - buff.SetSectionsValid(TBuffer3D::kCore); - - Int_t reqSections = gPad->GetViewer3D()->AddObject(buff); - if (reqSections != TBuffer3D::kNone) - Error(eH, "only direct GL rendering supported."); -} - -//______________________________________________________________________________ -void TEveProjectionManager::ComputeBBox() -{ - // Virtual from TAttBBox; fill bounding-box information. - - static const TEveException eH("TEveProjectionManager::ComputeBBox "); - - if(GetNChildren() == 0) { - BBoxZero(); - return; - } - - BBoxInit(); -} diff --git a/eve/src/TEveProjectionManagerEditor.cxx b/eve/src/TEveProjectionManagerEditor.cxx index 76065e84639..9454ad2df8b 100644 --- a/eve/src/TEveProjectionManagerEditor.cxx +++ b/eve/src/TEveProjectionManagerEditor.cxx @@ -11,15 +11,11 @@ #include "TEveProjectionManagerEditor.h" #include "TEveProjectionManager.h" - #include "TEveGValuators.h" -#include "TColor.h" #include "TGNumberEntry.h" -#include "TGColorSelect.h" #include "TGComboBox.h" #include "TGLabel.h" -#include "TG3DLine.h" //______________________________________________________________________________ // TEveProjectionManagerEditor @@ -41,15 +37,9 @@ TEveProjectionManagerEditor::TEveProjectionManagerEditor(const TGWindow *p, fFixedRadius(0), fCurrentDepth(0), - fCenterFrame(0), - fDrawCenter(0), fCenterX(0), fCenterY(0), - fCenterZ(0), - - fAxisColor(0), - fSIMode(0), - fSILevel(0) + fCenterZ(0) { // Constructor. @@ -70,9 +60,10 @@ TEveProjectionManagerEditor::TEveProjectionManagerEditor(const TGWindow *p, AddFrame(f); } + Int_t nel = 6; Int_t labelW = 60; fDistortion = new TEveGValuator(this, "Distortion:", 90, 0); - fDistortion->SetNELength(5); + fDistortion->SetNELength(nel); fDistortion->SetLabelWidth(labelW); fDistortion->Build(); fDistortion->SetLimits(0, 50, 101, TGNumberFormat::kNESRealTwo); @@ -82,7 +73,7 @@ TEveProjectionManagerEditor::TEveProjectionManagerEditor(const TGWindow *p, fFixedRadius = new TEveGValuator(this, "FixedR:", 90, 0); - fFixedRadius->SetNELength(5); + fFixedRadius->SetNELength(nel); fFixedRadius->SetLabelWidth(labelW); fFixedRadius->Build(); fFixedRadius->SetLimits(0, 1000, 101, TGNumberFormat::kNESRealOne); @@ -93,98 +84,19 @@ TEveProjectionManagerEditor::TEveProjectionManagerEditor(const TGWindow *p, fCurrentDepth = new TEveGValuator(this, "CurrentZ:", 90, 0); - fCurrentDepth->SetNELength(5); + fCurrentDepth->SetNELength(nel); fCurrentDepth->SetLabelWidth(labelW); fCurrentDepth->Build(); - fCurrentDepth->SetLimits(-300, 300, 601, TGNumberFormat::kNESRealOne); + fCurrentDepth->SetLimits(-300, 300, 601, TGNumberFormat::kNESRealTwo); fCurrentDepth->SetToolTip("Z coordinate of incoming projected object."); fCurrentDepth->Connect("ValueSet(Double_t)", "TEveProjectionManagerEditor", this, "DoCurrentDepth()"); - AddFrame(fCurrentDepth, new TGLayoutHints(kLHintsTop, 1, 1, 1, 0)); - - /**************************************************************************/ - MakeTitle("Axis"); - { - TGHorizontalFrame* hf1 = new TGHorizontalFrame(this); - - TGCompositeFrame *labfr = - new TGHorizontalFrame(hf1, 60, 15, kFixedSize); - TGLabel* l = new TGLabel(labfr, "Color"); - labfr->AddFrame(l, new TGLayoutHints(kLHintsLeft|kLHintsBottom)); - hf1->AddFrame(labfr, new TGLayoutHints(kLHintsLeft|kLHintsBottom)); - - - fAxisColor = new TGColorSelect(hf1, 0, -1); - hf1->AddFrame(fAxisColor, new TGLayoutHints(kLHintsLeft, 2, 0, 1, 1)); - fAxisColor->Connect - ("ColorSelected(Pixel_t)", - "TEveProjectionManagerEditor", this, "DoAxisColor(Pixel_t)"); - - AddFrame(hf1); - } - { - TGHorizontalFrame* f = new TGHorizontalFrame(this); - TGLabel* lab = new TGLabel(f, "StepMode"); - f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 6, 1, 2)); - fSIMode = new TGComboBox(f, "Position"); - fSIMode->AddEntry("Value", 1); - fSIMode->AddEntry("Position", 0); - fSIMode->GetTextEntry()->SetToolTipText("Set tick-marks on equidistant values/screen position."); - TGListBox* lb = fSIMode->GetListBox(); - lb->Resize(lb->GetWidth(), 2*18); - fSIMode->Resize(80, 20); - fSIMode->Connect("Selected(Int_t)", "TEveProjectionManagerEditor", - this, "DoSplitInfoMode(Int_t)"); - f->AddFrame(fSIMode, new TGLayoutHints(kLHintsTop, 1, 1, 1, 1)); - AddFrame(f); - } - { - TGHorizontalFrame* f = new TGHorizontalFrame(this); - TGLabel* lab = new TGLabel(f, "SplitLevel"); - f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 8, 1, 2)); - - fSILevel = new TGNumberEntry(f, 0, 3, -1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, - TGNumberFormat::kNELLimitMinMax, 0, 7); - fSILevel->GetNumberEntry()->SetToolTipText("Number of tick-marks TMath::Power(2, level)."); - fSILevel->Connect("ValueSet(Long_t)", "TEveProjectionManagerEditor", this, "DoSplitInfoLevel()"); - f->AddFrame(fSILevel, new TGLayoutHints(kLHintsTop, 1, 1, 1, 2)); - AddFrame(f, new TGLayoutHints(kLHintsTop, 0, 0, 0, 3) ); - } - - /**************************************************************************/ - // center tab - fCenterFrame = CreateEditorTabSubFrame("Center"); - - TGCompositeFrame *title1 = new TGCompositeFrame(fCenterFrame, 180, 10, - kHorizontalFrame | - kLHintsExpandX | - kFixedWidth | - kOwnBackground); - title1->AddFrame(new TGLabel(title1, "Distortion Center"), - new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0)); - title1->AddFrame(new TGHorizontal3DLine(title1), - new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7)); - fCenterFrame->AddFrame(title1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0)); - - - { - - TGHorizontalFrame* hf1 = new TGHorizontalFrame(fCenterFrame); + AddFrame(fCurrentDepth, new TGLayoutHints(kLHintsTop, 1, 1, 1, 3)); - fDrawOrigin = new TGCheckButton(hf1, "DrawOrigin"); - hf1->AddFrame(fDrawOrigin, new TGLayoutHints(kLHintsLeft, 2,1,0,4)); - fDrawOrigin->Connect("Toggled(Bool_t)"," TEveProjectionManagerEditor", this, "DoDrawOrigin()"); + //_________ + MakeTitle("Distortion centre"); + fCenterFrame = new TGVerticalFrame(this); - - fDrawCenter = new TGCheckButton(hf1, "DrawCenter"); - hf1->AddFrame(fDrawCenter, new TGLayoutHints(kLHintsLeft, 2,1,0,4)); - fDrawCenter->Connect("Toggled(Bool_t)"," TEveProjectionManagerEditor", this, "DoDrawCenter()"); - - fCenterFrame->AddFrame(hf1, new TGLayoutHints(kLHintsTop, 0,0,0,0)); - - } - - Int_t nel = 8; fCenterX = new TEveGValuator(fCenterFrame, "CenterX:", 90, 0); fCenterX->SetNELength(nel); fCenterX->SetLabelWidth(labelW); @@ -214,6 +126,8 @@ TEveProjectionManagerEditor::TEveProjectionManagerEditor(const TGWindow *p, fCenterZ->Connect("ValueSet(Double_t)", "TEveProjectionManagerEditor", this, "DoCenter()"); fCenterFrame->AddFrame(fCenterZ, new TGLayoutHints(kLHintsTop, 1, 1, 1, 1)); + + AddFrame(fCenterFrame, new TGLayoutHints(kLHintsTop, 1, 1, 1, 0)); } //______________________________________________________________________________ @@ -222,18 +136,12 @@ void TEveProjectionManagerEditor::SetModel(TObject* obj) // Set model object. fM = dynamic_cast<TEveProjectionManager*>(obj); - - fAxisColor->SetColor(TColor::Number2Pixel(fM->GetAxisColor()), kFALSE); - fSIMode->Select(fM->GetSplitInfoMode(), kFALSE); - fSILevel->SetNumber(fM->GetSplitInfoLevel()); - + fType->Select(fM->GetProjection()->GetType(), kFALSE); fDistortion->SetValue(1000.0f * fM->GetProjection()->GetDistortion()); fFixedRadius->SetValue(fM->GetProjection()->GetFixedRadius()); fCurrentDepth->SetValue(fM->GetCurrentDepth()); - fDrawCenter->SetState(fM->GetDrawCenter() ? kButtonDown : kButtonUp); - fDrawOrigin->SetState(fM->GetDrawOrigin() ? kButtonDown : kButtonUp); fCenterX->SetValue(fM->GetCenter().fX); fCenterY->SetValue(fM->GetCenter().fY); fCenterZ->SetValue(fM->GetCenter().fZ); @@ -289,47 +197,3 @@ void TEveProjectionManagerEditor::DoCenter() Update(); } -//______________________________________________________________________________ -void TEveProjectionManagerEditor::DoDrawOrigin() -{ - // Slot for setting draw of origin. - - fM->SetDrawOrigin(fDrawOrigin->IsOn()); - Update(); -} - -//______________________________________________________________________________ -void TEveProjectionManagerEditor::DoDrawCenter() -{ - // Slot for setting draw of center. - - fM->SetDrawCenter(fDrawCenter->IsOn()); - Update(); -} - -//______________________________________________________________________________ -void TEveProjectionManagerEditor::DoSplitInfoMode(Int_t type) -{ - // Slot for setting split info mode. - - fM->SetSplitInfoMode(type); - Update(); -} - -//______________________________________________________________________________ -void TEveProjectionManagerEditor::DoSplitInfoLevel() -{ - // Slot for setting tick-mark density. - - fM->SetSplitInfoLevel((Int_t)fSILevel->GetNumber()); - Update(); -} - -//______________________________________________________________________________ -void TEveProjectionManagerEditor::DoAxisColor(Pixel_t pixel) -{ - // Slot for setting axis color. - - fM->SetAxisColor(Color_t(TColor::GetColor(pixel))); - Update(); -} diff --git a/eve/src/TEveProjectionManagerGL.cxx b/eve/src/TEveProjectionManagerGL.cxx deleted file mode 100644 index 7b09c683850..00000000000 --- a/eve/src/TEveProjectionManagerGL.cxx +++ /dev/null @@ -1,322 +0,0 @@ -// @(#)root/eve:$Id$ -// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 - -/************************************************************************* - * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#include "TEveProjectionManagerGL.h" -#include "TEveProjectionManager.h" - -#include "TGLRnrCtx.h" -#include "TGLIncludes.h" -#include "TGLText.h" -#include "TMath.h" - -#include <list> - -//______________________________________________________________________________ -// TEveProjectionManagerGL -// -// GL-renderer for TEveProjectionManager. - -ClassImp(TEveProjectionManagerGL) - -//______________________________________________________________________________ -TEveProjectionManagerGL::TEveProjectionManagerGL() : - TGLObject(), - - fRange(300), - fLabelSize(0.02), - fLabelOff(0.018), - fTMSize(0.02), - - fM(0), - fText(0) -{ - // Constructor. - - fDLCache = kFALSE; // Disable display list. - fText = new TGLText(); - fText->SetGLTextFont(40); - fText->SetTextColor(0); -} - -/******************************************************************************/ - -//______________________________________________________________________________ -const char* TEveProjectionManagerGL::GetText(Float_t x) const -{ - // Get formatted text. - - using namespace TMath; - if (Abs(x) > 1000) { - Float_t v = 10*TMath::Nint(x/10.0f); - return Form("%.0f", v); - } else if(Abs(x) > 100) { - Float_t v = TMath::Nint(x); - return Form("%.0f", v); - } else if (Abs(x) > 10) - return Form("%.1f", x); - else if ( Abs(x) > 1 ) - return Form("%.2f", x); - else - return Form("%.3f", x); -} - -/******************************************************************************/ - -//______________________________________________________________________________ -void TEveProjectionManagerGL::SetRange(Float_t pos, Int_t ax) const -{ - // Set values for bounding box. - - using namespace TMath; - Float_t limit = fM->GetProjection()->GetLimit(ax, pos > 0 ? kTRUE: kFALSE); - if (fM->GetProjection()->GetDistortion() > 0.001 && Abs(pos) > Abs(limit *0.97)) - { - fPos.push_back(limit *0.7); - fVals.push_back(fM->GetProjection()->GetValForScreenPos(ax, fPos.back())); - } - else - { - fPos.push_back(pos); - fVals.push_back(fM->GetProjection()->GetValForScreenPos(ax, fPos.back())); - } -} - -/******************************************************************************/ - -//______________________________________________________________________________ -void TEveProjectionManagerGL::DrawTickMarks(Float_t tm) const -{ - // Draw tick-marks on the current axis. - - glBegin(GL_LINES); - for (std::list<Float_t>::iterator pi = fPos.begin(); pi!= fPos.end(); ++pi) - { - glVertex3f(*pi, 0, 0.); - glVertex3f(*pi, tm, 0.); - } - glEnd(); -} - -//______________________________________________________________________________ -void TEveProjectionManagerGL::DrawHInfo() const -{ - // Draw labels on horizontal axis. - - Float_t tms = fTMSize*fRange; - DrawTickMarks(-tms); - - glPushMatrix(); - glRotatef(-90, 1, 0, 0); - glTranslatef(0, 0, -tms -fLabelOff*fRange); - const char* txt; - Float_t llx, lly, llz, urx, ury, urz; - std::list<Float_t>::iterator vi = fVals.begin(); - for( std::list<Float_t>::iterator pi = fPos.begin(); pi!= fPos.end(); pi++) - { - txt = GetText(*vi); - fText->BBox(txt, llx, lly, llz, urx, ury, urz); - fText->PaintGLText(*pi -(urx-llx)*fText->GetTextSize()*0.5, 0, 0, txt); - vi++; - } - glPopMatrix(); - - fPos.clear(); fVals.clear(); -} - -//______________________________________________________________________________ -void TEveProjectionManagerGL::DrawVInfo() const -{ - // Draw labels on vertical axis. - - Float_t tms = fTMSize*fRange; - glRotatef(90, 0, 0, 1); - DrawTickMarks(tms); - glRotatef(-90, 0, 0, 1); - - glPushMatrix(); - glRotatef(-90, 1, 0, 0); - glTranslatef(-fLabelOff*fRange -tms, 0, 0); - const char* txt; - Float_t llx, lly, llz, urx, ury, urz; - std::list<Float_t>::iterator vi = fVals.begin(); - for (std::list<Float_t>::iterator pi = fPos.begin(); pi!= fPos.end(); ++pi) - { - txt= GetText(*vi); - fText->BBox(txt, llx, lly, llz, urx, ury, urz); - fText->PaintGLText(-(urx-llx)*fText->GetTextSize(), 0, *pi - (ury - lly)*fText->GetTextSize()*0.5, txt); - vi++; - } - glPopMatrix(); - - fPos.clear(); fVals.clear(); -} - -/******************************************************************************/ - -//______________________________________________________________________________ -void TEveProjectionManagerGL::SplitInterval(Int_t ax) const -{ - // Build a list of labels and their positions. - - if (fM->GetSplitInfoLevel()) - { - if(fM->GetSplitInfoMode()) - SplitIntervalByVal(fVals.front(), fVals.back(), ax, 0); - else - SplitIntervalByPos(fPos.front(), fPos.back(), ax, 0); - } -} - -//______________________________________________________________________________ -void TEveProjectionManagerGL::SplitIntervalByPos(Float_t minp, Float_t maxp, Int_t ax, Int_t level) const -{ - // Add tick-mark and label with position in the middle of given interval. - - Float_t p = (minp+maxp)*0.5; - fPos.push_back(p); - Float_t v = fM->GetProjection()->GetValForScreenPos(ax, p); - fVals.push_back(v); - level++; - if (level<fM->GetSplitInfoLevel()) - { - SplitIntervalByPos(minp, p , ax, level); - SplitIntervalByPos(p, maxp, ax, level); - } -} - -//______________________________________________________________________________ -void TEveProjectionManagerGL::SplitIntervalByVal(Float_t minv, Float_t maxv, Int_t ax, Int_t level) const -{ - // Add tick-mark and label with value in the middle of given interval. - - Float_t v = (minv+maxv)*0.5; - fVals.push_back(v); - Float_t p = fM->GetProjection()->GetScreenVal(ax, v); - fPos.push_back(p); - level++; - if (level<fM->GetSplitInfoLevel()) - { - SplitIntervalByVal(minv, v , ax, level); - SplitIntervalByVal(v, maxv, ax, level); - } -} - -/******************************************************************************/ - -//______________________________________________________________________________ -void TEveProjectionManagerGL::DirectDraw(TGLRnrCtx & /*rnrCtx*/) const -{ - // Actual rendering code. - // Virtual from TGLLogicalShape. - - GLboolean lightp; - glGetBooleanv(GL_LIGHTING, &lightp); - if (lightp) glDisable(GL_LIGHTING); - - Float_t* bbox = fM->GetBBox(); - fRange = bbox[1] - bbox[0]; - // printf("bbox %f, %f\n", bbox[0], bbox[1]); - TEveVector zeroPos; - fM->GetProjection()->ProjectVector(zeroPos); - fText->SetTextSize(fLabelSize*fRange); - fText->SetTextColor(fM->GetAxisColor()); - - { // horizontal - glPushMatrix(); - glTranslatef(0, bbox[2], 0); - // left - SetRange(bbox[0], 0); - fPos.push_back(zeroPos.fX); fVals.push_back(0); - SplitInterval(0); - DrawHInfo(); - // right - fPos.push_back(zeroPos.fX); fVals.push_back(0); - SetRange(bbox[1], 0); - SplitInterval(0); fVals.pop_front(); fPos.pop_front(); - DrawHInfo(); - glPopMatrix(); - } - { // vertical - glPushMatrix(); - glTranslatef(bbox[0], 0, 0); - // bottom - fPos.push_back(zeroPos.fY);fVals.push_back(0); - SetRange(bbox[2], 1); - SplitInterval(1); - DrawVInfo(); - // top - fPos.push_back(zeroPos.fY); fVals.push_back(0); - SetRange(bbox[3], 1); - SplitInterval(1);fPos.pop_front(); fVals.pop_front(); - DrawVInfo(); - glPopMatrix(); - } - - // body - glBegin(GL_LINES); - glVertex3f(bbox[0], bbox[2], 0.); - glVertex3f(bbox[1], bbox[2], 0.); - glVertex3f(bbox[0], bbox[2], 0.); - glVertex3f(bbox[0], bbox[3], 0.); - glEnd(); - - Float_t d = 10; - if (fM->GetDrawCenter()) - { - Float_t* c = fM->GetProjection()->GetProjectedCenter(); - TGLUtil::Color3f(1., 0., 0.); - glBegin(GL_LINES); - glVertex3f(c[0] +d, c[1], c[2]); glVertex3f(c[0] - d, c[1] , c[2]); - glVertex3f(c[0] , c[1] +d, c[2]); glVertex3f(c[0] , c[1] -d, c[2]); - glVertex3f(c[0] , c[1], c[2] + d); glVertex3f(c[0] , c[1] , c[2] - d); - glEnd(); - - } - - if (fM->GetDrawOrigin()) - { - TEveVector zero; - fM->GetProjection()->ProjectVector(zero); - TGLUtil::Color3f(1., 1., 1.); - glBegin(GL_LINES); - glVertex3f(zero[0] +d, zero[1], zero[2]); glVertex3f(zero[0] - d, zero[1] , zero[2]); - glVertex3f(zero[0] , zero[1] +d, zero[2]); glVertex3f(zero[0] , zero[1] -d, zero[2]); - glVertex3f(zero[0] , zero[1], zero[2] + d); glVertex3f(zero[0] , zero[1] , zero[2] - d); - glEnd(); - } - if (lightp) glEnable(GL_LIGHTING); -} - - -/******************************************************************************/ - -//______________________________________________________________________________ -Bool_t TEveProjectionManagerGL::SetModel(TObject* obj, const Option_t* /*opt*/) -{ - // Set model object. - // Virtual from TGLObject. - - if (SetModelCheckClass(obj, TEveProjectionManager::Class())) { - fM = dynamic_cast<TEveProjectionManager*>(obj); - return kTRUE; - } - return kFALSE; -} - -//______________________________________________________________________________ -void TEveProjectionManagerGL::SetBBox() -{ - // Fill the bounding-box data of the logical-shape. - // Virtual from TGLObject. - - // !! This ok if master sub-classed from TAttBBox - SetAxisAlignedBBox(((TEveProjectionManager*)fExternalObj)->AssertBBox()); -} diff --git a/eve/src/TEveText.cxx b/eve/src/TEveText.cxx index 17032b4434c..3d977d0d1cf 100644 --- a/eve/src/TEveText.cxx +++ b/eve/src/TEveText.cxx @@ -12,11 +12,14 @@ #include "TEveText.h" #include "TFTGLManager.h" +#include "TObjArray.h" +#include "TObjString.h" #include "TString.h" #include "TBuffer3D.h" #include "TBuffer3DTypes.h" #include "TVirtualPad.h" #include "TVirtualViewer3D.h" +#include "TMath.h" //______________________________________________________________________________ // TEveText @@ -28,44 +31,84 @@ ClassImp(TEveText); //______________________________________________________________________________ -TEveText::TEveText(const Text_t* text) : +TEveText::TEveText(const Text_t* txt) : TEveElement(fTextColor), - TNamed("TEveText","TEveText"), + TNamed("TEveText", ""), TAtt3D(), TAttBBox(), - fText(text), + fText(txt), fTextColor(0), fSize(12), fFile(4), - fMode(TFTGLManager::kPixmap), + fMode(-1), + fExtrude(1.0f), + fAutoBehave(kTRUE), fLighting(kFALSE), - fExtrude(1.0f) + fHMTrans() { // Constructor. + + SetFontMode(TFTGLManager::kPixmap); +} + +/******************************************************************************/ + +//______________________________________________________________________________ +const TGPicture* TEveText::GetListTreeIcon() +{ + //return pointset icon. + + return TEveElement::fgListTreeIcons[5]; } //______________________________________________________________________________ -void TEveText::SetFont(Int_t size, Int_t file, Int_t mode) +void TEveText::SetFontSize(Int_t val, Bool_t validate) { - // Set current font attributes. + // Set valid font size. + + if (validate) { + Int_t* fsp = &TFTGLManager::GetFontSizeArray()->front(); + Int_t ns = TFTGLManager::GetFontSizeArray()->size(); + Int_t idx = TMath::BinarySearch(ns, fsp, val); + fSize = fsp[idx]; + } else { + fSize = val; + } +} - fSize = size; - fFile = file; - if (fMode != mode) - { - fMode = mode; - if (fMode == TFTGLManager::kBitmap || fMode == TFTGLManager::kPixmap) { - fHMTrans.SetEditRotation(kFALSE); - fHMTrans.SetEditScale(kFALSE); - } else { - fHMTrans.SetEditRotation(kTRUE); - fHMTrans.SetEditScale(kTRUE); +//______________________________________________________________________________ +void TEveText::SetFontFile(const char* name) +{ + // Set font file regarding to staticTFTGLManager fgFontFileArray. + + TObjArray* fa =TFTGLManager::GetFontFileArray(); + TIter next_base(fa); + TObjString* os; + Int_t idx = 0; + while ((os = (TObjString*) next_base()) != 0) { + if (os->GetString() == name) { + SetFontFile(idx); + return; } + idx++; } } +//______________________________________________________________________________ +void TEveText::SetFontMode( Int_t mode) +{ + // Set current font attributes. + + fMode = mode; + + Bool_t edit = (fMode > TFTGLManager::kPixmap); + fHMTrans.SetEditRotation(edit); + fHMTrans.SetEditScale(edit); +} + + //______________________________________________________________________________ void TEveText::Paint(Option_t* ) { diff --git a/eve/src/TEveTextEditor.cxx b/eve/src/TEveTextEditor.cxx index 6033aa8673e..db82893195c 100644 --- a/eve/src/TEveTextEditor.cxx +++ b/eve/src/TEveTextEditor.cxx @@ -37,11 +37,14 @@ TEveTextEditor::TEveTextEditor(const TGWindow *p, Int_t width, Int_t height, UInt_t options, Pixel_t back) : TGedFrame(p, width, height, options | kVerticalFrame, back), fM(0), + fSize(0), fFile(0), fMode(0), + fExtrude(0), + fLighting(0), - fExtrude(0) + fAutoBehave(0) { // Constructor. @@ -55,15 +58,17 @@ TEveTextEditor::TEveTextEditor(const TGWindow *p, Int_t width, Int_t height, // Face Size combo fSize = MakeLabeledCombo("Size:"); - for (Int_t i = 8; i <= 20; i+=2) - fSize->AddEntry(Form("%-2d", i), i); - for (Int_t i = 24; i <= 64; i+=4) - fSize->AddEntry(Form("%-2d", i), i); - fSize->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFont()"); + Int_t* fsp = &TFTGLManager::GetFontSizeArray()->front(); + Int_t nums = TFTGLManager::GetFontSizeArray()->size(); + for(Int_t i= 0; i< nums; i++) + { + fSize->AddEntry(Form("%-2d", fsp[i]), fsp[i]); + } + fSize->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFontSize()"); // Font File combo fFile = MakeLabeledCombo("File:"); - TObjArray* farr = TFTGLManager::GetFontArray(); + TObjArray* farr = TFTGLManager::GetFontFileArray(); TIter next(farr); TObjString* os; Int_t cnt = 0; @@ -72,7 +77,7 @@ TEveTextEditor::TEveTextEditor(const TGWindow *p, Int_t width, Int_t height, fFile->AddEntry(Form("%s", os->GetString().Data()), cnt); cnt++; } - fFile->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFont()"); + fFile->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFontFile()"); // Mode combo fMode = MakeLabeledCombo("Mode:"); @@ -82,28 +87,31 @@ TEveTextEditor::TEveTextEditor(const TGWindow *p, Int_t width, Int_t height, fMode->AddEntry("Polygon", TFTGLManager::kPolygon); fMode->AddEntry("Extrude", TFTGLManager::kExtrude); fMode->AddEntry("Texture", TFTGLManager::kTexture); - fMode->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFont()"); + fMode->Connect("Selected(Int_t)", "TEveTextEditor", this, "DoFontMode()"); + fExtrude = new TEveGValuator(this, "Depth:", 90, 0); + fExtrude->SetLabelWidth(45); + fExtrude->SetNELength(5); + // fExtrude->SetShowSlider(kFALSE); + fExtrude->Build(); + fExtrude->SetLimits(0.01, 10, 100, TGNumberFormat::kNESRealTwo); + fExtrude->SetToolTip("Extrusion depth."); + fExtrude->Connect("ValueSet(Double_t)", "TEveTextEditor", this, "DoExtrude()"); + AddFrame(fExtrude, new TGLayoutHints(kLHintsTop, 4, 1, 1, 1)); + // GLConfig - TGCompositeFrame *f1 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame | kFitWidth | kFixedWidth ); f1->AddFrame(new TGLabel(f1, "GLConfig"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0)); f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7)); AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 8, 0)); - fLighting = new TGCheckButton(this, "Lighting"); + fAutoBehave = new TGCheckButton(this, "AutoBehave"); + AddFrame(fAutoBehave, new TGLayoutHints(kLHintsLeft, 1,2,0,0)); + fAutoBehave->Connect("Toggled(Bool_t)", "TEveTextEditor", this, "DoAutoBehave()"); + + fLighting = new TGCheckButton(this, "GL Lighting"); AddFrame(fLighting, new TGLayoutHints(kLHintsLeft, 1,2,0,0)); fLighting->Connect("Toggled(Bool_t)", "TEveTextEditor", this, "DoLighting()"); - - fExtrude = new TEveGValuator(this, "Extrude:", 90, 0); - fExtrude->SetLabelWidth(52); - fExtrude->SetNELength(6); - fExtrude->SetShowSlider(kFALSE); - fExtrude->Build(); - fExtrude->SetLimits(0.01, 10, 100, TGNumberFormat::kNESRealTwo); - fExtrude->SetToolTip("Extrusion depth."); - fExtrude->Connect("ValueSet(Double_t)", "TEveTextEditor", this, "DoExtrude()"); - AddFrame(fExtrude, new TGLayoutHints(kLHintsTop, 1, 1, 1, 1)); } //______________________________________________________________________________ @@ -152,9 +160,20 @@ void TEveTextEditor::SetModel(TObject* obj) fSize->Select(fM->GetSize(), kFALSE); fFile->Select(fM->GetFile(), kFALSE); + + // mode fMode->Select(fM->GetMode(), kFALSE); - fLighting->SetState(fM->GetLighting() ? kButtonDown : kButtonUp); + // lightning + fAutoBehave->SetState(fM->GetAutoBehave() ? kButtonDown : kButtonUp); + if (fM->GetAutoBehave()) { + fLighting->SetDisabledAndSelected(fM->GetLighting() ? kButtonDown : kButtonUp); + } else { + fLighting->SetEnabled(); + fLighting->SetState(fM->GetLighting() ? kButtonDown : kButtonUp); + } + + // extrude if (fM->GetMode() == TFTGLManager::kExtrude) { ShowFrame(fExtrude); @@ -176,20 +195,28 @@ void TEveTextEditor::DoText(const Text_t* /*txt*/) } //______________________________________________________________________________ -void TEveTextEditor::DoFont() +void TEveTextEditor::DoFontSize() { // Slot for setting FTGL attributes. - fM->SetFont(fSize->GetSelected(), fFile->GetSelected(), fMode->GetSelected()); + fM->SetFontSize(fSize->GetSelected(), kFALSE); Update(); } //______________________________________________________________________________ -void TEveTextEditor::DoLighting() +void TEveTextEditor::DoFontFile() { - // Slot for enabling/disabling GL lighting. + // Slot for setting FTGL attributes. - fM->SetLighting(fLighting->IsOn()); + fM->SetFontFile(fFile->GetSelected()); + Update(); +} +//______________________________________________________________________________ +void TEveTextEditor::DoFontMode() +{ + // Slot for setting FTGL attributes. + + fM->SetFontMode(fMode->GetSelected()); Update(); } @@ -201,3 +228,21 @@ void TEveTextEditor::DoExtrude() fM->SetExtrude(fExtrude->GetValue()); Update(); } + +//______________________________________________________________________________ +void TEveTextEditor::DoAutoBehave() +{ + // Slot for enabling/disabling defaults. + + fM->SetAutoBehave(fAutoBehave->IsOn()); + Update(); +} + +//______________________________________________________________________________ +void TEveTextEditor::DoLighting() +{ + // Slot for enabling/disabling GL lighting. + + fM->SetLighting(fLighting->IsOn()); + Update(); +} diff --git a/eve/src/TEveTextGL.cxx b/eve/src/TEveTextGL.cxx index a8ba502598d..b12c4217d38 100644 --- a/eve/src/TEveTextGL.cxx +++ b/eve/src/TEveTextGL.cxx @@ -61,31 +61,37 @@ void TEveTextGL::SetBBox() } //______________________________________________________________________________ -void TEveTextGL::DirectDraw(TGLRnrCtx & rnrCtx) const +void TEveTextGL::SetModelFont(TEveText* model, TGLRnrCtx & rnrCtx) const { - // Actual rendering code. - // Virtual from TGLLogicalShape. - - static const TEveException eH("TEveTextGL::DirectDraw "); - - if (fSize != fM->GetSize() || fFile != fM->GetFile() || fMode != fM->GetMode()) + if (fSize != model->GetSize() || fFile != model->GetFile() || fMode != model->GetMode()) { if (fFont) rnrCtx.ReleaseFont(fSize, fFile, fMode); - fSize = fM->GetSize(); - fFile = fM->GetFile(); - fMode = fM->GetMode(); + fSize = model->GetSize(); + fFile = model->GetFile(); + fMode = model->GetMode(); fFont = rnrCtx.GetFont(fSize, fFile, fMode); } +} + +/******************************************************************************/ +//______________________________________________________________________________ +void TEveTextGL::DirectDraw(TGLRnrCtx & rnrCtx) const +{ + // Actual rendering code. + // Virtual from TGLLogicalShape. + + static const TEveException eH("TEveTextGL::DirectDraw "); + + SetModelFont(fM, rnrCtx); // bbox initialisation - if (fBoundingBox.IsEmpty() && - fMode != TFTGLManager::kBitmap && fMode != TFTGLManager::kPixmap) + if (fBoundingBox.IsEmpty() && fMode > TFTGLManager::kPixmap) { Float_t bbox[6]; fFont->BBox(fM->GetText(), bbox[0], bbox[1], bbox[2], - bbox[3], bbox[4], bbox[5]); + bbox[3], bbox[4], bbox[5]); if (fMode == TFTGLManager::kExtrude) { // Depth goes, the other z-way, swap. @@ -105,16 +111,15 @@ void TEveTextGL::DirectDraw(TGLRnrCtx & rnrCtx) const ncthis->UpdateBoundingBoxesOfPhysicals(); } - // rendering - TGLCapabilitySwitch lights(GL_LIGHTING, fM->GetLighting()); + // rendering + TFTGLManager::PreRender(fMode); + TGLCapabilitySwitch lights(GL_LIGHTING, fM->GetAutoBehave() ? (fMode > TFTGLManager::kOutline) : (fM->GetLighting())); switch(fMode) { case TFTGLManager::kBitmap: case TFTGLManager::kPixmap: - { - if (rnrCtx.Selection()) - { - // calculate coordinates in 3D + if (rnrCtx.Selection()) { + // calculate 3D coordinates for picking const GLdouble *pm = rnrCtx.RefCamera().RefLastNoPickProjM().CArr(); GLdouble mm[16]; GLint vp[4]; @@ -138,60 +143,28 @@ void TEveTextGL::DirectDraw(TGLRnrCtx & rnrCtx) const glVertex3dv(fX[2]); glVertex3dv(fX[3]); glEnd(); - } - else - { - TGLCapabilitySwitch blending(GL_BLEND, kTRUE); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glAlphaFunc(GL_GEQUAL, 0.0625); - glEnable(GL_ALPHA_TEST); - + } else { glRasterPos3i(0, 0, 0); fFont->Render(fM->GetText()); } break; - } case TFTGLManager::kOutline: case TFTGLManager::kExtrude: case TFTGLManager::kPolygon: - { - TGLCapabilitySwitch normalize(GL_NORMALIZE, kTRUE); - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - TGLCapabilitySwitch col(GL_COLOR_MATERIAL, kTRUE); - TGLCapabilitySwitch cull(GL_CULL_FACE, kFALSE); - if (fM->GetExtrude() != 1.0) - { + if (fM->GetExtrude() != 1.0) { glPushMatrix(); glScalef(1.0f, 1.0f, fM->GetExtrude()); fFont->Render(fM->GetText()); glPopMatrix(); - } - else - { + } else { fFont->Render(fM->GetText()); } break; - } case TFTGLManager::kTexture: - { - TGLCapabilitySwitch alpha(GL_ALPHA_TEST, kTRUE); - TGLCapabilitySwitch blending(GL_BLEND, kTRUE); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glAlphaFunc(GL_GEQUAL, 0.0625); - glEnable(GL_ALPHA_TEST); - - glPushAttrib(GL_POLYGON_BIT | GL_ENABLE_BIT); - TGLCapabilitySwitch texture(GL_TEXTURE_2D, kTRUE); - TGLCapabilitySwitch col(GL_COLOR_MATERIAL, kTRUE); fFont->Render(fM->GetText()); - glPopAttrib(); break; - } default: - { throw(eH + "unsupported FTGL-type."); - } } + TFTGLManager::PostRender(fMode); } diff --git a/eve/src/TEveTransEditor.cxx b/eve/src/TEveTransEditor.cxx index 8451e570ac9..972d3ef0320 100644 --- a/eve/src/TEveTransEditor.cxx +++ b/eve/src/TEveTransEditor.cxx @@ -134,13 +134,12 @@ void TEveTransSubEditor::SetModel(TEveTrans* t) fEditTrans->SetState(fTrans->fEditTrans ? kButtonDown : kButtonUp); if (fTrans->fEditTrans) { - fEditTransFrame->MapWindow(); - for (Int_t i=0; i<3; ++i) { fRot ->GetValuator(i)->GetEntry()->SetState(fTrans->GetEditRotation()); fScale->GetValuator(i)->GetEntry()->SetState(fTrans->GetEditScale()); } + fEditTransFrame->MapWindow(); } else { @@ -212,11 +211,7 @@ void TEveTransSubEditor::DoEditTrans() // Slot for EditTrans. fTrans->SetEditTrans(fEditTrans->IsOn()); - if (fEditTrans->IsOn()) - fEditTransFrame->MapWindow(); - else - fEditTransFrame->UnmapWindow(); - ((TGMainFrame*)fEditTransFrame->GetMainFrame())->Layout(); + TransChanged(); } //______________________________________________________________________________ diff --git a/eve/src/TEveUtil.cxx b/eve/src/TEveUtil.cxx index 7ed2e3c78f1..02cd00e9109 100644 --- a/eve/src/TEveUtil.cxx +++ b/eve/src/TEveUtil.cxx @@ -102,6 +102,9 @@ void TEveUtil::SetupGUI() TEveElement::fgListTreeIcons[2] = gClient->GetPicture(fld + "eve_scene.xpm"); TEveElement::fgListTreeIcons[3] = gClient->GetPicture(fld + "eve_pointset.xpm"); TEveElement::fgListTreeIcons[4] = gClient->GetPicture(fld + "eve_track.xpm"); + TEveElement::fgListTreeIcons[5] = gClient->GetPicture(fld + "eve_text.gif"); + TEveElement::fgListTreeIcons[6] = gClient->GetPicture(fld + "eve_axes.xpm"); + gClient->GetMimeTypeList()->AddType("root/tmacro", "TEveMacro", "tmacro_s.xpm", "tmacro_t.xpm", ""); diff --git a/gl/inc/TFTGLManager.h b/gl/inc/TFTGLManager.h index 279f60c7017..51e42fe087d 100644 --- a/gl/inc/TFTGLManager.h +++ b/gl/inc/TFTGLManager.h @@ -3,6 +3,7 @@ #include "TObjArray.h" #include <set> +#include <vector> class FTFont; class TRefCount; @@ -10,12 +11,12 @@ class TRefCount; class TFTGLManager { public: - enum EMode { kBitmap, kPixmap, kOutline, kPolygon, kExtrude, kTexture }; // FTGL class + enum EMode { kBitmap, kPixmap, kTexture, kOutline, kPolygon, kExtrude}; // FTGL class + + typedef std::vector<Int_t> FontSizeVec_t; -private: struct Font_t { - public: Int_t fSize; // face size Int_t fFile; // file name EMode fMode; // FTGL class id @@ -23,6 +24,10 @@ private: FTFont* fFont; // FTGL font TRefCnt fRefCnt; // FTGL font reference count + + + Font_t(): fSize(0), fFile(0), fMode(kPixmap), fFont(0), fRefCnt() {} + Font_t(Int_t size, Int_t font, EMode mode): fSize(size), fFile(font), fMode(mode), fFont(0), fRefCnt() {} @@ -59,6 +64,11 @@ private: std::set<Font_t> fFontSet; // Set of created fonts. + static TObjArray fgFontFileArray; // Map font-id to ttf-font-file. + static FontSizeVec_t fgFontSizeArray; + static Bool_t fgStaticInitDone; // Global initialization flag. + static void InitStatics(); + public: TFTGLManager(){} virtual ~TFTGLManager(); @@ -66,10 +76,11 @@ public: FTFont* GetFont(Int_t size, Int_t file, EMode mode); Bool_t ReleaseFont(Int_t size, Int_t file, EMode mode); - static Bool_t fgStaticInitDone; // Global initialization flag. - static TObjArray fgFontArray; // Map font-id to ttf-font-file. - static TObjArray* GetFontArray(); - static void InitFontArray(); + + static TObjArray* GetFontFileArray(); + static FontSizeVec_t* GetFontSizeArray(); + static void PreRender(Int_t mode); + static void PostRender(Int_t mode); ClassDef(TFTGLManager, 0); // A FreeType GL font manager. }; diff --git a/gl/src/TFTGLManager.cxx b/gl/src/TFTGLManager.cxx index fb529ea5994..f60bb61b5ad 100644 --- a/gl/src/TFTGLManager.cxx +++ b/gl/src/TFTGLManager.cxx @@ -24,8 +24,9 @@ ClassImp(TFTGLManager) -TObjArray TFTGLManager::fgFontArray; -Bool_t TFTGLManager::fgStaticInitDone = kFALSE; +TObjArray TFTGLManager::fgFontFileArray; +TFTGLManager::FontSizeVec_t TFTGLManager::fgFontSizeArray; +Bool_t TFTGLManager::fgStaticInitDone = kFALSE; TFTGLManager::~TFTGLManager() { @@ -47,7 +48,7 @@ FTFont* TFTGLManager::GetFont(Int_t size, Int_t file, EMode mode) { // Provide font with given size, file and FTGL class. - if (fgStaticInitDone == kFALSE) InitFontArray(); + if (fgStaticInitDone == kFALSE) InitStatics(); Font_t key = Font_t(size, file, mode); std::set<Font_t>::iterator it = fFontSet.find(key); @@ -59,7 +60,7 @@ FTFont* TFTGLManager::GetFont(Int_t size, Int_t file, EMode mode) # else ttpath = gEnv->GetValue("Root.TTFontPath", "$(ROOTSYS)/fonts"); # endif - TObjString* name = (TObjString*)fgFontArray[file]; + TObjString* name = (TObjString*)fgFontFileArray[file]; const char *file = gSystem->Which(ttpath.Data(), Form("%s.ttf", name->GetString().Data())); FTFont* ftfont = 0; @@ -122,18 +123,27 @@ Bool_t TFTGLManager::ReleaseFont(Int_t size, Int_t file, EMode mode) } //______________________________________________________________________________ -TObjArray* TFTGLManager::GetFontArray() +TObjArray* TFTGLManager::GetFontFileArray() { // Get id to file name map. - if (fgStaticInitDone == kFALSE) InitFontArray(); - return &fgFontArray; + if (fgStaticInitDone == kFALSE) InitStatics(); + return &fgFontFileArray; } //______________________________________________________________________________ -void TFTGLManager::InitFontArray() +TFTGLManager::FontSizeVec_t* TFTGLManager::GetFontSizeArray() { - // Create a list of available font files. + // Get valid font size vector. + + if (fgStaticInitDone == kFALSE) InitStatics(); + return &fgFontSizeArray; +} + +//______________________________________________________________________________ +void TFTGLManager::InitStatics() +{ + // Create a list of available font files and allowed font sizes. const char *ttpath = gEnv->GetValue("Root.TTFontPath", # ifdef TTFFONTDIR @@ -149,11 +159,77 @@ void TFTGLManager::InitFontArray() s = name; if (s.EndsWith(".ttf")) { s.Resize(s.Sizeof() -5); - fgFontArray.Add(new TObjString(s.Data())); + fgFontFileArray.Add(new TObjString(s.Data())); } } - fgFontArray.Sort(); + fgFontFileArray.Sort(); gSystem->FreeDirectory(dir); + + // font sizes + for (Int_t i = 8; i <= 20; i+=2) + fgFontSizeArray.push_back(i); + for (Int_t i = 24; i <= 64; i+=4) + fgFontSizeArray.push_back(i); + fgStaticInitDone = kTRUE; } + +//______________________________________________________________________________ +void TFTGLManager::PreRender(Int_t mode) +{ + // Set-up GL state before FTFont rendering. + + switch(mode) { + case kBitmap: + case kPixmap: + glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT); + glEnable(GL_ALPHA_TEST); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glAlphaFunc(GL_GEQUAL, 0.0625); + break; + case kTexture: + glPushAttrib(GL_POLYGON_BIT | GL_ENABLE_BIT); + glEnable(GL_TEXTURE_2D); + glEnable(GL_COLOR_MATERIAL); + glDisable(GL_CULL_FACE); + glEnable(GL_ALPHA_TEST); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glAlphaFunc(GL_GEQUAL, 0.0625); + break; + case kExtrude: + case kPolygon: + case kOutline: + glPushAttrib(GL_POLYGON_BIT | GL_ENABLE_BIT); + glEnable(GL_NORMALIZE); + glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + glEnable(GL_COLOR_MATERIAL); + glDisable(GL_CULL_FACE); + break; + default: + break; + } +} + +//______________________________________________________________________________ +void TFTGLManager::PostRender(Int_t mode) +{ + // Set-up GL state after FTFont rendering. + + switch(mode) { + case kBitmap: + case kPixmap: + glPopAttrib(); + break; + case kTexture: + glPopAttrib(); + break; + case kExtrude: + case kPolygon: + case kOutline: + glPopAttrib(); + break; + default: + break; + } +} diff --git a/tutorials/eve/projection_test.C b/tutorials/eve/projection_test.C new file mode 100644 index 00000000000..853faae3ac1 --- /dev/null +++ b/tutorials/eve/projection_test.C @@ -0,0 +1,40 @@ +const char* esd_geom_file_name = "http://root.cern.ch/files/alice_ESDgeometry.root"; + +void projection_test() +{ + TFile::SetCacheFileDir("."); + TEveManager::Create(); + + // camera + TEveScene* s = gEve->SpawnNewScene("Projected Event"); + gEve->GetDefViewer()->AddScene(s); + TGLViewer* v = (TGLViewer *)gEve->GetGLViewer(); + v->SetCurrentCamera(TGLViewer::kCameraOrthoXOY); + TGLCameraMarkupStyle* mup = v->GetCameraMarkup(); + if(mup) mup->SetShow(kFALSE); + + // projections + TEveProjectionManager* mng = new TEveProjectionManager(); + gEve->AddElement(mng, s); + TEveProjectionAxes* axes = new TEveProjectionAxes(mng); + axes->SetText("TEveProjections demo"); + axes->SetFontFile("comicbd"); + axes->SetFontSize(20); + gEve->AddGlobalElement(axes); + gEve->AddToListTree(axes, kTRUE); + gEve->AddToListTree(mng, kTRUE); + + // Simple geometry + TFile* geom = TFile::Open(esd_geom_file_name, "CACHEREAD"); + if (!geom) + return; + + TEveGeoShapeExtract* gse = (TEveGeoShapeExtract*) geom->Get("Gentle"); + TEveGeoShape* gsre = TEveGeoShape::ImportShapeExtract(gse, 0); + geom->Close(); + delete geom; + mng->ImportElements(gsre); + gsre->SetRnrState(kFALSE); + + gEve->Redraw3D(kTRUE); +} diff --git a/tutorials/eve/text_test.C b/tutorials/eve/text_test.C index a398379aebb..06e53777ef8 100644 --- a/tutorials/eve/text_test.C +++ b/tutorials/eve/text_test.C @@ -8,7 +8,7 @@ TEveText* text_test() marker->SetName("Origin marker"); marker->SetMarkerColor(6); marker->SetMarkerStyle(3); - Float_t a = 10; + Float_t a = 10; marker->SetPoint(0, a, +a, +a); marker->SetPoint(1, a, -a, +a); marker->SetPoint(2, -a, -a, +a); @@ -22,8 +22,7 @@ TEveText* text_test() TEveText* t = new TEveText("DADA"); t->PtrMainHMTrans()->RotateLF(1, 3, TMath::PiOver2()); t->SetMainColor((Color_t)(kOrange-2)); - // t->SetFont(64, 4, TFTGLManager::kPixmap); - t->SetFont(64, 4, TFTGLManager::kExtrude); + t->SetFontSize(64); t->SetLighting(kTRUE); gEve->AddElement(t); -- GitLab