From 7f5c8b2bf796fd2d5a0e342f79b10e4c01ff3efc Mon Sep 17 00:00:00 2001
From: Rene Brun <Rene.Brun@cern.ch>
Date: Fri, 23 Jun 2006 11:55:15 +0000
Subject: [PATCH] From Andrei and matevz Tadel: a patch allowing to paint
 volumes/nodes with a pre-defined global transformation.

git-svn-id: http://root.cern.ch/svn/root/trunk@15523 27541ba8-7e3a-0410-8455-c3a389f83636
---
 geom/inc/TVirtualGeoPainter.h   |  7 ++---
 geompainter/inc/TGeoPainter.h   |  4 +--
 geompainter/src/TGeoPainter.cxx | 47 ++++++++++++++++++++++-----------
 3 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/geom/inc/TVirtualGeoPainter.h b/geom/inc/TVirtualGeoPainter.h
index 6a7e3c81f2e..580e49b2e96 100644
--- a/geom/inc/TVirtualGeoPainter.h
+++ b/geom/inc/TVirtualGeoPainter.h
@@ -1,4 +1,4 @@
-// @(#)root/geom:$Name:  $:$Id: TVirtualGeoPainter.h,v 1.34 2006/04/25 09:38:27 brun Exp $
+// @(#)root/geom:$Name:  $:$Id: TVirtualGeoPainter.h,v 1.35 2006/06/11 12:56:48 brun Exp $
 // Author: Andrei Gheata   11/01/02
 
 /*************************************************************************
@@ -28,6 +28,7 @@
 class TGeoVolume;
 class TGeoNode;
 class TGeoShape;
+class TGeoMatrix;
 class TGeoHMatrix;
 class TGeoManager;
 class TVirtualGeoTrack;
@@ -108,11 +109,11 @@ public:
                             Double_t rmin=0., Double_t rmax=9999999, Option_t *option="") = 0;
    virtual void       ModifiedPad() const = 0;
    virtual void       Paint(Option_t *option="") = 0;
-   virtual void       PaintNode(TGeoNode *node, Option_t *option="") = 0;
+   virtual void       PaintNode(TGeoNode *node, Option_t *option="", TGeoMatrix* global=0) = 0;
    virtual void       PaintShape(TGeoShape *shape, Option_t *option="") = 0;
    virtual void       PaintOverlap(void *ovlp, Option_t *option="")  = 0;
    virtual void       PrintOverlaps() const = 0;
-   virtual void       PaintVolume(TGeoVolume *vol, Option_t *option="") = 0;
+   virtual void       PaintVolume(TGeoVolume *vol, Option_t *option="", TGeoMatrix* global=0) = 0;
    virtual void       RandomPoints(const TGeoVolume *vol, Int_t npoints, Option_t *option="") = 0;
    virtual void       RandomRays(Int_t nrays, Double_t startx, Double_t starty, Double_t startz) = 0;
    virtual void       Raytrace(Option_t *option="") = 0;
diff --git a/geompainter/inc/TGeoPainter.h b/geompainter/inc/TGeoPainter.h
index 09b97159f38..37f0ac20073 100644
--- a/geompainter/inc/TGeoPainter.h
+++ b/geompainter/inc/TGeoPainter.h
@@ -130,11 +130,11 @@ public:
    void               Lock(Bool_t flag = kTRUE) {fVisLock = flag;}
    virtual void       ModifiedPad() const;
    virtual void       Paint(Option_t *option="");
-   virtual void       PaintNode(TGeoNode *node, Option_t *option="");
+   virtual void       PaintNode(TGeoNode *node, Option_t *option="", TGeoMatrix* global=0);
    Bool_t             PaintShape(const TGeoShape & shape, Option_t * option) const;
    virtual void       PaintShape(TGeoShape *shape, Option_t *option="");
    virtual void       PaintOverlap(void *ovlp, Option_t *option="");
-   virtual void       PaintVolume(TGeoVolume *vol, Option_t *option="");
+   virtual void       PaintVolume(TGeoVolume *vol, Option_t *option="", TGeoMatrix* global=0);
    virtual void       PrintOverlaps() const;
    void               PaintPhysicalNode(TGeoPhysicalNode *node, Option_t *option="");
    virtual void       RandomPoints(const TGeoVolume *vol, Int_t npoints, Option_t *option="");
diff --git a/geompainter/src/TGeoPainter.cxx b/geompainter/src/TGeoPainter.cxx
index 4ca4b0517d9..7fcfb51f849 100644
--- a/geompainter/src/TGeoPainter.cxx
+++ b/geompainter/src/TGeoPainter.cxx
@@ -1,4 +1,4 @@
-// @(#)root/geompainter:$Name:  $:$Id: TGeoPainter.cxx,v 1.89 2006/06/11 12:56:48 brun Exp $
+// @(#)root/geompainter:$Name:  $:$Id: TGeoPainter.cxx,v 1.90 2006/06/13 12:28:44 brun Exp $
 // Author: Andrei Gheata   05/03/02
 /*************************************************************************
  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
@@ -483,12 +483,11 @@ Int_t TGeoPainter::CountNodes(TGeoVolume *volume, Int_t rlevel) const
    Int_t count = 0;
    Bool_t vis = vol->IsVisible();
    // Do I need to look for the top volume ?
-   if (fTopVisible && vis) count++;
+   if ((fTopVisible && vis) || !vol->GetNdaughters() || !vol->IsVisDaughters() || vol->IsVisOnly()) 
+      count++;
    // Is this the only volume?
-   if (volume->IsVisOnly()) {
-      if (!fTopVisible) count++;
-      return count;
-   }   
+   if (volume->IsVisOnly()) return count;
+
    // Do we need to check a branch only?
    if (volume->IsVisBranch()) {
       fGeoManager->PushPath();
@@ -1089,14 +1088,14 @@ void TGeoPainter::PaintOverlap(void *ovlp, Option_t *option)
 }
 
 //______________________________________________________________________________
-void TGeoPainter::PaintNode(TGeoNode *node, Option_t *option)
+void TGeoPainter::PaintNode(TGeoNode *node, Option_t *option, TGeoMatrix* global)
 {
 // Paint recursively a node and its content accordind to visualization options.
-   PaintVolume(node->GetVolume(), option);
+   PaintVolume(node->GetVolume(), option, global);
 } 
 
 //______________________________________________________________________________
-void TGeoPainter::PaintVolume(TGeoVolume *top, Option_t *option)
+void TGeoPainter::PaintVolume(TGeoVolume *top, Option_t *option, TGeoMatrix* global)
 {
 // Paint recursively a node and its content accordind to visualization options.
    if (fTopVolume != top) {
@@ -1106,7 +1105,10 @@ void TGeoPainter::PaintVolume(TGeoVolume *top, Option_t *option)
    fTopVolume = top;
    if (!fVisLevel) return;
    TGeoVolume *vol = top;
-   fGlobal->Clear();
+   if(global)
+      *fGlobal = *global;
+   else
+      fGlobal->Clear();
    TGeoShape::SetTransform(fGlobal);
    Bool_t drawDaughters = kTRUE;
    Bool_t vis = (top->IsVisible() && !top->IsAssembly());
@@ -1120,7 +1122,6 @@ void TGeoPainter::PaintVolume(TGeoVolume *top, Option_t *option)
       fGeoManager->cd(fVisBranch.Data());
       Int_t transparency;
       while (fGeoManager->GetLevel()) {
-         fGeoManager->SetMatrixReflection(fGeoManager->GetCurrentMatrix()->IsReflection());
          vol = fGeoManager->GetCurrentVolume();
          if (!fVisLock) {
             fVisVolumes->Add(vol);
@@ -1130,7 +1131,13 @@ void TGeoPainter::PaintVolume(TGeoVolume *top, Option_t *option)
          transparency = vol->GetTransparency();
          vol->SetTransparency(40);
          if (!strstr(option,"range")) ((TAttLine*)vol)->Modify();
-         *fGlobal = fGeoManager->GetCurrentMatrix();
+         if (global) {
+            *fGlobal  = *global;
+            *fGlobal *= *fGeoManager->GetCurrentMatrix();
+         } else {
+            *fGlobal = fGeoManager->GetCurrentMatrix();
+         }
+         fGeoManager->SetMatrixReflection(fGlobal->IsReflection());
          PaintShape(*(vol->GetShape()),option);
          vol->SetTransparency(transparency);
          fGeoManager->CdUp();
@@ -1144,7 +1151,7 @@ void TGeoPainter::PaintVolume(TGeoVolume *top, Option_t *option)
    // Do I need to draw the top volume ?
    if ((fTopVisible && vis) || !top->GetNdaughters() || !top->IsVisDaughters() || top->IsVisOnly()) {
       fGeoManager->SetPaintVolume(vol);
-      fGeoManager->SetMatrixReflection(kFALSE);
+      fGeoManager->SetMatrixReflection(fGlobal->IsReflection());
       drawDaughters = PaintShape(*(vol->GetShape()),option);
       if (!fVisLock && !vol->TestAttBit(TGeoAtt::kVisOnScreen)) {
          fVisVolumes->Add(vol);
@@ -1173,7 +1180,12 @@ void TGeoPainter::PaintVolume(TGeoVolume *top, Option_t *option)
       if (top->IsVisContainers()) {
          if (vis && level<=fVisLevel) {
             if (!strstr(option,"range")) ((TAttLine*)vol)->Modify();
-            *fGlobal = next.GetCurrentMatrix();
+            if (global) {
+               *fGlobal  = *global;
+               *fGlobal *= *next.GetCurrentMatrix();
+            } else {
+               *fGlobal = next.GetCurrentMatrix();
+            }
             fGeoManager->SetMatrixReflection(fGlobal->IsReflection());
             drawDaughters = PaintShape(*(vol->GetShape()),option);
             if (!fVisLock && !daughter->IsOnScreen()) {
@@ -1190,7 +1202,12 @@ void TGeoPainter::PaintVolume(TGeoVolume *top, Option_t *option)
          last = ((nd==0) || (level==fVisLevel) || (!daughter->IsVisDaughters()))?kTRUE:kFALSE;
          if (vis && last) {
             if (!strstr(option,"range")) ((TAttLine*)vol)->Modify();
-            *fGlobal = next.GetCurrentMatrix();
+            if (global) {
+               *fGlobal  = *global;
+               *fGlobal *= *next.GetCurrentMatrix();
+            } else {
+               *fGlobal = next.GetCurrentMatrix();
+            }
             fGeoManager->SetMatrixReflection(fGlobal->IsReflection());
             drawDaughters = PaintShape(*(vol->GetShape()),option);
             if (!fVisLock && !daughter->IsOnScreen()) {
-- 
GitLab