00001
00002 #include <OnXSvc/Win32.h>
00003
00004
00005 #include "SoDetElemCnv.h"
00006
00007
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
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
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
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
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
00155
00156 separator->addChild(rotation);
00157 separator->addChild(translation);
00158 separator->addChild(node);
00159
00160
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 }