| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

SoDetElemCnv.cpp

Go to the documentation of this file.
00001 // To fix clashes between Gaudi and Windows :
00002 #include <OnXSvc/Win32.h>
00003 
00004 // this :
00005 #include "SoDetElemCnv.h"
00006 
00007 // Inventor :
00008 #include <Inventor/nodes/SoSeparator.h>
00009 #include <Inventor/nodes/SoTranslation.h>
00010 #include <Inventor/nodes/SoRotation.h>
00011 
00012 #include <Lib/Interfaces/ISession.h>
00013 #include <Lib/smanip.h>
00014 
00015 #include <GaudiKernel/Converter.h>
00016 #include <GaudiKernel/CnvFactory.h>
00017 #include <GaudiKernel/ISvcLocator.h>
00018 #include <GaudiKernel/MsgStream.h>
00019 
00020 #include <DetDesc/CLIDDetectorElement.h>
00021 #include <DetDesc/DetectorElement.h>
00022 #include <DetDesc/Solids.h>
00023 #include <DetDesc/IGeometryInfo.h>
00024 #include <DetDesc/ILVolume.h>
00025 #include <DetDesc/ISolid.h>
00026 
00027 #include <OnXSvc/IUserInterfaceSvc.h>
00028 #include <OnXSvc/ClassID.h>
00029 #include <OnXSvc/Helpers.h>
00030 
00031 #include "SoDetConverter.h"
00032 
00033 DECLARE_CONVERTER_FACTORY(SoDetElemCnv)
00034 
00035 /*
00036 class Transform3D : public HepTransform3D {
00037 public:
00038   Transform3D(const HepTransform3D& aHT3D) : HepTransform3D(aHT3D) {
00039     m[0]  = xx;     m[1]  = yx;    m[2]  = zx;     m[3]  = 0;
00040     m[4]  = xy;     m[5]  = yy;    m[6]  = zy;     m[7]  = 0;
00041     m[8]  = xz;     m[9]  = yz;    m[10] = zz;     m[11] = 0;
00042     m[12] = dx;     m[13] = dy;    m[14] = dz;     m[15] = 1;
00043   }
00044   SbMatrix* getMatrix () const {
00045     return new SbMatrix(m[0],m[1],m[2],m[3],
00046                         m[4],m[5],m[6],m[7],
00047                         m[8],m[9],m[10],m[11],
00048                         m[12],m[13],m[14],m[15]);
00049   }
00050 private:
00051   float m[16];
00052 };
00053 */
00054 
00055 
00056 SoDetElemCnv::SoDetElemCnv( ISvcLocator* aSvcLoc ) 
00057   :SoDetConverter(aSvcLoc, CLID_DetectorElement)
00060 {
00061 }
00063 StatusCode SoDetElemCnv::createRep( 
00064  DataObject* aObject
00065 ,IOpaqueAddress*& 
00066 )
00069 {
00070   MsgStream log(messageService(), "SoDetElemCnv");
00071 
00072   if(!fUISvc) {
00073     log << MSG::INFO << " UI service not found" << endreq;
00074     return StatusCode::SUCCESS; 
00075   }
00076 
00077   ISession* session = fUISvc->session();
00078   if(!session) {
00079     log << MSG::INFO << " can't get OnX session." << endreq;
00080     return StatusCode::FAILURE; 
00081   }
00082 
00083   SoRegion* region = fUISvc->currentSoRegion();
00084   if(!region) {
00085     log << MSG::INFO << " can't get viewing region." << endreq;
00086     return StatusCode::FAILURE; 
00087   }
00088 
00089   std::string value;
00090   bool opened = false;
00091   if(session->parameterValue("modeling.opened",value))
00092     Lib::smanip::tobool(value,opened);
00093 
00094   log << MSG::INFO << "SoDetElemCnv::createReps() called" << endreq;
00095 
00096   if(!aObject) {
00097     log << MSG::INFO << " NULL object." << endreq;
00098     return StatusCode::FAILURE; 
00099   }
00100 
00101   DetectorElement* de  = dynamic_cast<DetectorElement*>(aObject);
00102   if(!de) {
00103     log << MSG::INFO << " bad object type." << endreq;
00104     return StatusCode::FAILURE; 
00105   }
00106 
00107   if(!de->geometry()) {
00108     log << MSG::INFO << " no geometry associated" << endreq;
00109     return StatusCode::SUCCESS; 
00110   }
00111 
00112   const ILVolume* lv  = de->geometry()->lvolume();
00113   // check if the detector element has a geometry associated
00114   if( 0 == lv ) { 
00115     log << MSG::INFO << " no geometry associated" << endreq;
00116     log << MSG::INFO << " lvolume name :" << de->geometry()->lvolumeName() 
00117         << "|" << endreq;
00118     return StatusCode::SUCCESS; 
00119   }
00120 
00121   log << MSG::DEBUG << " lvolume : " 
00122       << de->geometry()->lvolumeName() << endreq;
00123 
00124   SoNode* node = volumeToSoDetectorTreeKit(*lv,Gaudi::Transform3D(),opened);
00125   if(!node) { 
00126     log << MSG::INFO << " no representation" << endreq;
00127     return StatusCode::SUCCESS; 
00128   }
00129 
00130   SoSeparator* separator = new SoSeparator;
00131 
00132   // Deal with the Transformation
00133   Gaudi::Rotation3D rot;
00134   Gaudi::XYZVector c;
00135   de->geometry()->toLocalMatrix().GetDecomposition(rot,c);
00136   c = c * -1.0;
00137   rot.Invert();
00138   Gaudi::AxisAngle axisAngle(rot);
00139   double angle; 
00140   Gaudi::XYZVector v;
00141   axisAngle.GetComponents(v,angle);
00142 
00143   log << MSG::DEBUG << " translation "
00144       << c.x() << " " << c.y() << " " << c.z() << endreq;
00145   log << MSG::DEBUG << " rotation " 
00146       << v.x() << " " << v.y() << " " << v.z() << " " << angle << endreq;
00147 
00148   SoTranslation* translation = new SoTranslation;
00149   translation->translation = SbVec3f((float)c.x(),(float)c.y(),(float)c.z());
00150   SoRotation* rotation = new SoRotation;
00151   rotation->rotation = 
00152    SbRotation(SbVec3f((float)v.x(),(float)v.y(),(float)v.z()),(float)angle);
00153 
00154   // Add transformation and logical volume representation :
00155   // The volume is placed and rotated :
00156   separator->addChild(rotation);
00157   separator->addChild(translation);
00158   separator->addChild(node);
00159 
00160   // Send scene graph to the viewing region (in the "static" sub-scene graph) :
00161   region_addToStaticScene(*region,separator);
00162 
00163   return StatusCode::SUCCESS;
00164 }
00166 const CLID& SoDetElemCnv::classID( ) 
00167 
00168 
00169 { 
00170   return CLID_DetectorElement;
00171 }
00173 const unsigned char SoDetElemCnv::storageType( ) 
00174 
00175 
00176 { 
00177   return So_TechnologyType; 
00178 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:02:29 2011 for SoDet by doxygen 1.4.7