CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/Fireworks/Core/src/FWGlimpseView.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWGlimpseView
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Thu Feb 21 11:22:41 EST 2008
00011 // $Id: FWGlimpseView.cc,v 1.42 2011/02/22 18:37:31 amraktad Exp $
00012 //
00013 
00014 #include <boost/bind.hpp>
00015 
00016 
00017 #include "TGLPerspectiveCamera.h"
00018 #include "TGLViewer.h"
00019 #include "TGLScenePad.h"
00020 #include "TEveScene.h"
00021 #include "TEveViewer.h"
00022 
00023 #include "TEveManager.h"
00024 #include "TEveElement.h"
00025 
00026 #include "TEveText.h"
00027 #include "TGLFontManager.h"
00028 
00029 #include "TEveTrans.h"
00030 #include "TGeoTube.h"
00031 #include "TEveGeoNode.h"
00032 #include "TEveStraightLineSet.h"
00033 
00034 // user include files
00035 #include "Fireworks/Core/interface/FWGlimpseView.h"
00036 #include "Fireworks/Core/interface/BuilderUtils.h"
00037 
00038 //
00039 // constants, enums and typedefs
00040 //
00041 
00042 //
00043 // static data member definitions
00044 //
00045 //double FWGlimpseView::m_scale = 1;
00046 
00047 //
00048 // constructors and destructorquery
00049 //
00050 FWGlimpseView::FWGlimpseView(TEveWindowSlot* iParent, FWViewType::EType typeId) :
00051    FWEveView(iParent, typeId),
00052    m_cylinder(0),
00053    m_showAxes(this, "Show Axes", true ),
00054    m_showCylinder(this, "Show Cylinder", true)
00055 {
00056    createAxis();
00057 
00058    // made new wireframe scene
00059    TEveScene* wns = gEve->SpawnNewScene(Form("Wireframe Scene %s", typeName().c_str()));
00060    viewer()->AddScene(wns);
00061    TGLScene* gls  = wns->GetGLScene();
00062    gls->SetStyle(TGLRnrCtx::kWireFrame);
00063    gls->SetLOD(TGLRnrCtx::kLODMed);
00064    gls->SetSelectable(kFALSE);
00065 
00066    TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur());
00067    TGeoTube* tube = new TGeoTube(129,130,310);
00068    m_cylinder = fireworks::getShape("Detector outline", tube, kWhite);
00069    m_cylinder->SetPickable(kFALSE);
00070    m_cylinder->SetMainColor(kGray+3);
00071    wns->AddElement(m_cylinder);
00072 
00073    TGLViewer* ev = viewerGL();
00074    ev->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
00075    m_showAxes.changed_.connect(boost::bind(&FWGlimpseView::showAxes,this));
00076    m_showCylinder.changed_.connect(boost::bind(&FWGlimpseView::showCylinder,this));
00077 }
00078 
00079 FWGlimpseView::~FWGlimpseView()
00080 {
00081 }
00082 
00083 
00084 //
00085 // member functions
00086 //
00087 
00088 void
00089 FWGlimpseView::createAxis()
00090 {
00091    // create 3D axes
00092    TEveElementList* axisHolder = new TEveElementList("GlimpseAxisHolder");
00093 
00094    TGLFont::EMode fontMode = TGLFont::kPixmap;
00095    Int_t fs = 14;
00096    Color_t fcol = kGray+1;
00097 
00098    // X axis
00099    TEveStraightLineSet* xAxis = new TEveStraightLineSet( "GlimpseXAxis" );
00100    xAxis->SetPickable(kTRUE);
00101    xAxis->SetTitle("Energy Scale, 100 GeV, X-axis (LHC center)");
00102    xAxis->SetLineStyle(3);
00103    xAxis->SetLineColor(fcol);
00104    xAxis->AddLine(-100,0,0,100,0,0);
00105    axisHolder->AddElement(xAxis);
00106 
00107    TEveText* xTxt = new TEveText( "X+" );
00108    xTxt->PtrMainTrans()->SetPos(100-fs, -fs, 0);
00109    xTxt->SetFontMode(fontMode);
00110    xTxt->SetMainColor(fcol);
00111    axisHolder->AddElement(xTxt);
00112 
00113    // Y axis
00114    TEveStraightLineSet* yAxis = new TEveStraightLineSet( "GlimpseYAxis" );
00115    yAxis->SetPickable(kTRUE);
00116    yAxis->SetTitle("Energy Scale, 100 GeV, Y-axis (upward)");
00117    yAxis->SetLineColor(fcol);
00118    yAxis->SetLineStyle(3);
00119    yAxis->AddLine(0,-100,0,0,100,0);
00120    axisHolder->AddElement(yAxis);
00121 
00122    TEveText* yTxt = new TEveText( "Y+" );
00123    yTxt->PtrMainTrans()->SetPos(0, 100-fs, 0);
00124    yTxt->SetFontMode(fontMode);
00125    yTxt->SetMainColor(fcol);
00126    axisHolder->AddElement(yTxt);
00127 
00128    // Z axis
00129    TEveStraightLineSet* zAxis = new TEveStraightLineSet( "GlimpseZAxis" );
00130    zAxis->SetPickable(kTRUE);
00131    zAxis->SetTitle("Energy Scale, 100 GeV, Z-axis (west, along beam)");
00132    zAxis->SetLineColor(fcol);
00133    zAxis->AddLine(0,0,-100,0,0,100);
00134    axisHolder->AddElement(zAxis);
00135 
00136    TEveText* zTxt = new TEveText( "Z+" );
00137    zTxt->PtrMainTrans()->SetPos(0, -fs,  100 - zTxt->GetExtrude()*2);
00138    zTxt->SetFontMode(fontMode);
00139    zTxt->SetMainColor(fcol);
00140    axisHolder->AddElement(zTxt);
00141 
00142    geoScene()->AddElement(axisHolder);
00143 }
00144 
00145 
00146 void
00147 FWGlimpseView::showAxes( )
00148 {
00149    if ( m_showAxes.value() )
00150       viewerGL()->SetGuideState(TGLUtil::kAxesOrigin, kTRUE, kFALSE, 0);
00151    else
00152       viewerGL()->SetGuideState(TGLUtil::kAxesNone, kTRUE, kFALSE, 0);
00153 }
00154 
00155 
00156 void
00157 FWGlimpseView::showCylinder( )
00158 {
00159    if ( m_showCylinder.value() )
00160       m_cylinder->SetRnrState(kTRUE);
00161    else
00162       m_cylinder->SetRnrState(kFALSE);
00163 
00164    gEve->Redraw3D();
00165 }
00166 
00167 
00168 void
00169 FWGlimpseView::addTo(FWConfiguration& iTo) const
00170 {
00171    FWEveView::addTo(iTo);   
00172    TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
00173    if (camera)
00174       addToPerspectiveCamera(camera, typeName(), iTo);
00175 }
00176 
00177 void
00178 FWGlimpseView::setFrom(const FWConfiguration& iFrom)
00179 {
00180    FWEveView::setFrom(iFrom);
00181    TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
00182    if (camera)
00183       setFromPerspectiveCamera(camera, typeName(), iFrom);
00184 }
00185