#include "Utilities/Configuration/interface/Architecture.h"
#include "Visualisation/G3DetectorVis/interface/TwigTk2D.h"
#include <iostream>

#include <Inventor/nodes/SoMaterial.h>
#include "Inventor/SbLinear.h"
#include <Inventor/nodes/SoTranslation.h>
#include <Inventor/nodes/SoTransform.h>
#include <Inventor/nodes/SoRotation.h>
#include <Inventor/nodes/SoIndexedLineSet.h>

#include "Ig_Extensions/IgOpenInventor/interface/IgSoG4Trap.h"
#include "Ig_Extensions/IgOpenInventor/interface/IgSoCube.h"

#include "Tracker/TkLayout/interface/FullTracker.h"
#include "Tracker/TkLayout/interface/CmsTracker.h"
#include "ClassReuse/GeomVector/interface/GlobalPoint.h"
#include "CommonDet/DetGeometry/interface/TkRotation.h"
#include "CommonDet/DetGeometry/interface/Surface.h"
#include "CommonDet/DetLayout/interface/DetLayer.h"
#include "CommonDet/BasicDet/interface/DetUnit.h"
#include "CommonDet/BasicDet/interface/Enumerators.h"
#include "CommonDet/BasicDet/interface/Det.h"
#include "CommonDet/BasicDet/interface/DetType.h"
#include "CommonDet/BasicDet/interface/SimHit.h"  
#include "CommonDet/BasicDet/interface/SimDet.h"

#include "CommonDet/DetGeometry/interface/Bounds.h"
#include "CommonDet/DetGeometry/interface/GeneralTrapezoidalPlaneBounds.h"
#include "CommonDet/DetGeometry/interface/RectangularPlaneBounds.h"




void TwigTk2D::drawMe() 
{
   inherited::drawMe();
   if(nw==0){ 
   rootp = new SoSeparator;
    root = new SoSeparator;
    
    getIvNode()->addChild( rootp );  
    rootp->addChild(root);
     root->ref();
    nw = new TkSceneUpdate(rootp,root);
    w = new TkSelectionWindow(nw);
    w->show();
    w->tracker->crea();
    cout <<root<< " -rootp2D-" <<rootp<<endl;
   }

}

void TwigTk2D::printInfo(ostream& ostr, const SoNode* node) const
{
     nw->pos1 = nw->tkPickedModuleMap.find(node);
     if(nw->pos1!=nw->tkPickedModuleMap.end()){
        const DetUnit* det=nw->pos1->second;
	
	float posx = det->surface().position().x()/ 100.0;  // cm -> m
        float posy = det->surface().position().y()/ 100.0;  // cm -> m
        float posz = det->surface().position().z()/ 100.0;  // cm -> m
	   
	 ostr << " Center position of the module" <<posx<< " " <<posy << " "<<posz <<endl;    
	 if(det->type().isStereo()){
	   ostr<<"stereo module"<<endl;
	 } else {ostr << "single module"<<endl;}
         ostr << det->type().module() << " "<<det->type().part()<<endl;
     } else {ostr << "node not found"<<endl;}
}





