]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4VisManager.cxx
ff31b19e98fc4396f05cf71f81182ac51248669b
[u/mrichter/AliRoot.git] / TGeant4 / TG4VisManager.cxx
1 // $Id$
2 // Category: visualization
3 //
4 // Author: I. Hrivnacova, A. Gheata
5 //
6 // Class TG4VisManager
7 // -------------------
8 // See the class description in the header file.
9 // According to visualization/management/include/MyVisManager.*
10 // John Allison 24th January 1998.
11 // I. Hrivnacova 12.5.98
12 //
13 // Renamed to TG4VisManager
14 // I. Hrivnacova, 3.9.99
15 //
16 // Added AliMC implementation
17 // A. Gheata, 22.2.00
18 //
19 // Added OpenGL*Win32, RayTracer (as replacement of RayX) drivers 
20 // based on G4 suggestions.
21 // I. Gonzalez, 4.4.2000
22 //
23 // Example Visualization Manager description:
24 //   Implements virtual function RegisterGraphicsSystems.  
25 //   Exploits C-pre-processor variables G4VIS_USE_DAWN, etc.,
26 //   which are set by the G4 makefiles if
27 //   environment variables of the same name are set.
28 //
29 // So all you have to do is set environment variables and compile and
30 //   instantiate this in your main().
31 //
32 // Alternatively, you can implement an empty function here and just
33 //   register the systems you want in your main(), e.g.:
34 //   G4VisManager* myVisManager = new MyVisManager;
35 //   myVisManager -> RegisterGraphicsSystem (new MyGraphicsSystem);
36
37
38 #ifdef G4VIS_USE
39
40 #include "TG4VisManager.h"
41 #include "TG4Globals.h"
42
43 #include <G4LogicalVolumeStore.hh>
44 #include <G4PhysicalVolumeStore.hh>
45 #include <G4TransportationManager.hh>
46 #include <G4Material.hh>
47 #include <G4PhysicalVolumeModel.hh>
48 #include <G4VVisManager.hh>
49
50 // Supported drivers...
51
52 #ifdef G4VIS_USE_DAWN
53 #include <G4FukuiRenderer.hh>
54 #endif
55
56 #ifdef G4VIS_USE_DAWNFILE
57 #include <G4DAWNFILE.hh>
58 #endif
59
60 #ifdef G4VIS_USE_OPACS
61 #include <G4Wo.hh>
62 #include <G4Xo.hh>
63 #endif
64
65 #ifdef G4VIS_USE_OPENGLX
66 #include <G4OpenGLImmediateX.hh>
67 #include <G4OpenGLStoredX.hh>
68 #endif
69
70 #ifdef G4VIS_USE_OPENGLXM
71 #include <G4OpenGLImmediateXm.hh>
72 #include <G4OpenGLStoredXm.hh>
73 #endif
74
75 #ifdef G4VIS_USE_OPENGLWIN32
76 #include "G4OpenGLImmediateWin32.hh"
77 #include "G4OpenGLStoredWin32.hh"
78 #endif
79
80 #ifdef G4VIS_USE_OIX
81 #include <G4OpenInventorX.hh>
82 #endif
83
84 #ifdef G4VIS_USE_OIWIN32
85 #include <G4OpenInventorWin32.hh>
86 #endif
87
88 #ifdef G4VIS_USE_RAYTRACER
89 #include "G4RayTracer.hh"
90 #endif
91
92 #ifdef G4VIS_USE_VRML
93 #include <G4VRML1.hh>
94 #include <G4VRML2.hh>
95 #endif
96
97 #ifdef G4VIS_USE_VRMLFILE
98 #include <G4VRML1File.hh>
99 #include <G4VRML2File.hh>
100 #endif
101
102 //_____________________________________________________________________________
103 TG4VisManager::TG4VisManager(G4int verboseLevel) {
104 //  
105   fVerbose = verboseLevel; 
106   fColourFlag = true;
107 }
108
109 //_____________________________________________________________________________
110 TG4VisManager::TG4VisManager(const TG4VisManager& right) {
111 // 
112   TG4Globals::Exception(
113     "Attempt to copy TG4VisManager singleton.");
114 }
115
116 //_____________________________________________________________________________
117 TG4VisManager::~TG4VisManager() {
118 //
119 }  
120
121 // operators
122
123 //_____________________________________________________________________________
124 TG4VisManager& TG4VisManager::operator=(const TG4VisManager& right) 
125 {
126   // check assignement to self
127   if (this == &right) return *this;
128
129   TG4Globals::Exception(
130     "Attempt to assign TG4VisManager singleton.");
131     
132   return *this;  
133 }    
134           
135 // private methods
136
137 //_____________________________________________________________________________
138 void TG4VisManager::RegisterGraphicsSystems() 
139 {
140 // Registers the graphics systems.
141 // ---
142
143   // all created graphics system instances are
144   // deleted in G4VisManager::~G4VisManager()
145 #ifdef G4VIS_USE_DAWN
146   RegisterGraphicsSystem(new G4FukuiRenderer);
147 #endif
148
149 #ifdef G4VIS_USE_DAWNFILE
150   RegisterGraphicsSystem(new G4DAWNFILE);
151 #endif
152
153 #ifdef G4VIS_USE_OPACS
154   RegisterGraphicsSystem(new G4Wo);
155   RegisterGraphicsSystem(new G4Xo);
156 #endif
157
158 #ifdef G4VIS_USE_OPENGLX
159   RegisterGraphicsSystem(new G4OpenGLImmediateX);
160   RegisterGraphicsSystem(new G4OpenGLStoredX);
161 #endif
162
163 #ifdef G4VIS_USE_OPENGLXM
164   RegisterGraphicsSystem(new G4OpenGLImmediateXm);
165   RegisterGraphicsSystem(new G4OpenGLStoredXm);
166 #endif
167
168 #ifdef G4VIS_USE_OPENGLWIN32
169   RegisterGraphicsSystem (new G4OpenGLImmediateWin32);
170   RegisterGraphicsSystem (new G4OpenGLStoredWin32);
171 #endif
172
173 #ifdef G4VIS_USE_OIX
174   RegisterGraphicsSystem(new G4OpenInventorX);
175 #endif
176
177 #ifdef G4VIS_USE_OIWIN32
178   RegisterGraphicsSystem(new G4OpenInventorWin32);
179 #endif
180
181 #ifdef G4VIS_USE_RAYTRACER
182   RegisterGraphicsSystem (new G4RayTracer);
183 #endif
184
185 #ifdef G4VIS_USE_VRML
186   RegisterGraphicsSystem(new G4VRML1);
187   RegisterGraphicsSystem(new G4VRML2);
188 #endif
189
190 #ifdef G4VIS_USE_VRMLFILE
191   RegisterGraphicsSystem(new G4VRML1File);
192   RegisterGraphicsSystem(new G4VRML2File);
193 #endif
194
195   if (fVerbose > 0) {
196     G4cout <<
197       "\nYou have successfully chosen to use the following graphics systems."
198          << G4endl;
199     PrintAvailableGraphicsSystems();
200   }
201 }
202
203 //---------------------------------------------------------------
204 // private methods
205 //---------------------------------------------------------------
206
207  
208 //_____________________________________________________________________________
209 G4bool TG4VisManager::Contains(const LogicalVolumesVector& lvVector,
210                                const G4LogicalVolume* lv) const
211 {
212 // Returns true if the vector contains specified logical volume.
213 // ---
214
215   LogicalVolumesVector::const_iterator i;
216
217   for (i = lvVector.begin(); i != lvVector.end(); i++) 
218     if (*i == lv) return true;
219
220   return false;
221 }
222
223 //_____________________________________________________________________________
224 G4bool TG4VisManager::Contains(const PhysicalVolumesVector& pvVector,
225                                const G4VPhysicalVolume* pv) const
226 {
227 // Returns true if the vector contains specified physical volume.
228 // ---
229
230   PhysicalVolumesVector::const_iterator i;
231
232   for (i = pvVector.begin(); i != pvVector.end(); i++) 
233     if (*i == pv) return true;
234
235   return false;
236 }
237
238 //_____________________________________________________________________________
239 LogicalVolumesVector TG4VisManager::GetLVList(G4String name)
240 {
241 // Get function returning the list of logical volumes
242 // associated to NAME; G4 built clones of a G3 volume (identified 
243 // with NAME_NUMBER will be added to the list)  
244 //  NAME can be the name of a logical or physical volume
245 // ---
246
247  LogicalVolumesVector lvList;
248  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
249  G4LogicalVolume* pLV = 0; 
250  if (pLVStore)
251  {
252    for (G4int i=0; i<pLVStore->size(); i++)
253    {
254      pLV = (*pLVStore)[i];  
255      if (CaseInsensitiveEqual(name,pLV->GetName())) 
256      {
257        if (!Contains(lvList, pLV)) lvList.push_back(pLV);
258      }
259    }
260  }  
261  if (lvList.size()>0) return lvList;
262
263  G4PhysicalVolumeStore* pPVStore = G4PhysicalVolumeStore::GetInstance();
264  G4VPhysicalVolume* pPV = 0;
265  if (pPVStore) 
266  {
267    for (G4int i=0; i<pPVStore->size(); i++)
268    {
269      pPV = (*pPVStore)[i]; 
270      if (CaseInsensitiveEqual(name,pPV->GetName())) 
271      {
272        pLV = pPV->GetLogicalVolume();
273        if (!Contains(lvList, pLV)) lvList.push_back(pLV);
274      }     
275    }
276  }  
277  return lvList;
278 }
279
280
281 //_____________________________________________________________________________
282 PhysicalVolumesVector TG4VisManager::GetPVList(G4String name)
283 {
284 // Get function returning the physical volume pointer for NAME
285 // ---
286
287   PhysicalVolumesVector pvList;
288   G4PhysicalVolumeStore* pPVStore = G4PhysicalVolumeStore::GetInstance();
289   if (!pPVStore)
290   {
291     TG4Globals::Warning("TG4VisManager::Gdraw : No volume store !");
292     return pvList;
293   }
294   G4VPhysicalVolume* pPV = 0;
295   for (G4int i=0; i<pPVStore->size(); i++)
296   {
297     pPV = (*pPVStore)[i];
298     if (CaseInsensitiveEqual(name,pPV->GetName()))
299     {
300       if (!Contains(pvList, pPV)) pvList.push_back(pPV);
301     }  
302   }
303   return pvList;
304 }
305
306
307 //_____________________________________________________________________________
308 G4bool TG4VisManager::CaseInsensitiveEqual(const G4String string1,
309                                            const G4String string2)
310 {
311 // Case insensitive comparison of 2 strings
312 // ---
313
314   G4int i;
315   if (string1 == string2) return true;
316 //  if (string1.length() != string2.length()) return false;
317   for (i=0; i<string1.length(); i++)
318   {
319     G4int diff = abs((G4int)string1(i)-(G4int)string2(i));
320     if (diff && (diff!=32)) return false;
321   }
322   if (string2.length() > string1.length())
323   {
324     if (string2(i) == '_') return true;
325     return false;
326   }    
327   return true;
328 }
329  
330
331 //_____________________________________________________________________________
332 void TG4VisManager::SetAtt4Daughters(G4LogicalVolume* const lv, 
333                                      const TG4G3Attribute att, const G4int val)
334 {
335 // Iterator for setting a visual attribute for all daughters
336 // ---
337
338   SetG4Attribute(lv,att,val);  
339   
340   G4String lvName = lv->GetName();
341   G4int nOfDaughters = lv->GetNoDaughters();
342   if (nOfDaughters>0)
343   {
344     G4String previousName = "";
345     for (G4int i=0; i<nOfDaughters; i++) 
346     { 
347       G4LogicalVolume* lvd = lv->GetDaughter(i)->GetLogicalVolume(); 
348       G4String currentName = lvd->GetName();
349       if (currentName != lvName && currentName != previousName)
350       {
351         SetAtt4Daughters(lvd, att, val);
352         previousName = currentName;
353       } 
354     }
355   }   
356 }
357
358
359 //_____________________________________________________________________________
360 G4bool TG4VisManager::IsSharedVisAttributes(const G4LogicalVolume* pLV)
361 {
362 // Function seeking if the volume's visible attributes are shared with
363 //  other volumes
364 // ---
365
366   G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
367   G4LogicalVolume* pLVCurrent = 0;
368   const G4VisAttributes* pVisAtt = pLV->GetVisAttributes();
369   if (!pVisAtt) return false;
370   for (G4int i=0; i<pLVStore->size(); i++)
371   {
372     pLVCurrent = (*pLVStore)[i];
373     if (pLVCurrent != pLV)
374     {
375       if (pLVCurrent->GetVisAttributes() == pVisAtt) 
376       {
377         return true;
378       }
379     }
380   }
381   return false;
382 }
383
384
385 //_____________________________________________________________________________
386 void TG4VisManager::SetG4Attribute(G4LogicalVolume* const lv,
387                                    const TG4G3Attribute att, const G4int val)
388 {
389 // Set the G4 attribute fo volume LV accordingly to the G3 description
390 //  of (att- val)    
391 // --
392
393  if (!lv) return;
394  // Dupplicating old vis. attributes    
395  const G4VisAttributes* visAttributes = lv->GetVisAttributes();
396  G4VisAttributes* newVisAttributes;
397  if (!visAttributes)
398    newVisAttributes    = new G4VisAttributes(false);
399  else {
400    G4bool visibility = visAttributes->IsVisible();
401    G4Colour colour   = visAttributes->GetColour();
402    newVisAttributes = new G4VisAttributes(visibility, colour);
403  }
404
405  const G4int kAbsVal = abs(val);        // the functionality is given by the abs value
406
407  // Default visible attributes
408  G4double red(0),green(0),blue(0); // default is black
409  G4bool isVisible(false);
410  G4bool isDaughtersInvisible(false);
411  G4VisAttributes::LineStyle lineStyle = G4VisAttributes::unbroken;
412  G4double lineWidth = 1.0;
413  G4bool isForceDrawingStyle(false);
414  G4VisAttributes::ForcedDrawingStyle drawingStyle = G4VisAttributes::wireframe;
415  
416  // a 'hardcopy' of old vis attributes is needed because the copy constructor
417  // resets to defaults some of the data members of G4VisAttributes class
418  if (visAttributes)
419  {
420    isVisible          = visAttributes->IsVisible();
421    isDaughtersInvisible = visAttributes->IsDaughtersInvisible();
422    red   = visAttributes->GetColour().GetRed();
423    green = visAttributes->GetColour().GetGreen(); 
424    blue  = visAttributes->GetColour().GetBlue();        // old RGB components
425    lineStyle = visAttributes->GetLineStyle();
426    lineWidth = visAttributes->GetLineWidth();
427    isForceDrawingStyle = visAttributes->IsForceDrawingStyle();
428    if (isForceDrawingStyle) 
429        drawingStyle = visAttributes->GetForcedDrawingStyle();
430    
431  }
432  G4double luminosityBin(0.04),  // bin for luminosity 
433           luminosity(0);        // colour luminosity
434
435  // Delete old vis. attributes if they are not shared
436  if (visAttributes && !IsSharedVisAttributes(lv)) delete visAttributes;
437
438  // Set the required attribute
439  switch (att)
440  {
441   case kSEEN:
442    switch (val)
443    {
444     case  0:
445      isVisible = false; 
446      break;
447     case  1:
448      isVisible = true;  
449      break;
450     case -1:
451      isVisible = false; 
452      break;
453     case -2:
454      isVisible = false; 
455      break;
456     default:
457      isVisible = false; 
458    }       
459    break;
460   case kLSTY:
461    switch (kAbsVal)
462    {
463     case 1:
464      lineStyle = G4VisAttributes::unbroken; break;
465     case 2:
466      lineStyle = G4VisAttributes::dashed; break;
467     case 3:
468      lineStyle = G4VisAttributes::dotted; break;
469     default:
470      if (fVerbose > 0)
471       G4cout << "TG4VisManager::Gsatt() Usage of LSTY :" << G4endl
472              << "ATT = 1,2,3 means line unbroken, dashed or dotted" << G4endl
473              << "any other value resets to the default : unbroken" << G4endl;
474      lineStyle = G4VisAttributes::unbroken;
475    }       
476    break;
477   case kLWID:
478    lineWidth = kAbsVal;
479    if (lineWidth > 7) lineWidth = 7;
480    if (fVerbose > 0) 
481        G4cout << "TG4VisManager::Gsatt() Usage for LWID :" << G4endl
482               << "  The VAL you supply means the width of lines in pixels "
483               << "for the screen and in 0.1*mm for paper." << G4endl
484               << "  Negative values means the same, but for all daughters"
485               << G4endl;
486    break;
487   case kCOLO:
488    if (kAbsVal < 8)     // G3 base colours
489    {
490     switch (kAbsVal)
491     {
492      case 1:
493        red=0; green=0; blue=0;          //black
494        break;                   
495      case 2:
496        red=1; green=0; blue=0;          //red
497        break;                   
498      case 3:
499        red=0; green=1; blue=0;          //green
500        break;                   
501      case 4:
502        red=0; green=0; blue=1;          //blue
503        break;                   
504      case 5:
505        red=1; green=1; blue=0;          //yellow
506        break;                   
507      case 6:
508        red=1; green=0; blue=1;          //violet
509        break;                   
510      case 7:
511        red=0; green=1; blue=1;          //lightblue (almost !)
512     }
513     luminosity = 0.;
514    }
515    if (kAbsVal>=8 && kAbsVal<=16)
516    {
517      red=0; green=0; blue=0;
518      luminosity = (kAbsVal-7)*luminosityBin;
519    }
520    if (kAbsVal>=17 && kAbsVal<=41)
521    {
522      red=1; green=0; blue=0;
523      luminosity = (kAbsVal-16)*luminosityBin;
524    }
525    if (kAbsVal>=67 && kAbsVal<=91)
526    {
527      red=0; green=1; blue=0;
528      luminosity = (kAbsVal-66)*luminosityBin;
529    }
530    if (kAbsVal>=117 && kAbsVal<=141)
531    {
532      red=0; green=0; blue=1;
533      luminosity = (kAbsVal-116)*luminosityBin;
534    }
535    if (kAbsVal>=42 && kAbsVal<=66)
536    {
537      red=1; green=1; blue=0;
538      luminosity = (kAbsVal-41)*luminosityBin;
539    }
540    if (kAbsVal>=142 && kAbsVal<=166)
541    {
542      red=1; green=0; blue=1;
543      luminosity = (kAbsVal-141)*luminosityBin;
544    }
545    if (kAbsVal>=92 && kAbsVal<=116)
546    {
547      red=0; green=1; blue=1;
548      luminosity = (kAbsVal-91)*luminosityBin;
549    }
550    if (red < luminosityBin)     red += luminosity;
551    if (green < luminosityBin) green += luminosity;
552    if (blue < luminosityBin)   blue += luminosity;
553    break;
554   case kFILL:
555    isForceDrawingStyle = true;
556    switch (kAbsVal)
557    {
558     case 0:
559      drawingStyle = G4VisAttributes::wireframe;
560      break;
561     case 1:
562      drawingStyle = G4VisAttributes::solid;
563      break;
564     default:
565      if (fVerbose > 0)
566          G4cout << "TG4VisManager::Gsatt() FILL usage :" << G4endl
567                 << "  The FILL values you can supply are only :" << G4endl
568                 << "+/- 1 : forces wireframe drawing (default)" << G4endl
569                 << "+/- 2 : forces solid drawing" << G4endl
570                 << "other values sets the drawing style to solid"
571                 << G4endl;              
572      drawingStyle = G4VisAttributes::solid;
573    }      
574  }
575  // Register vis. attributes
576  newVisAttributes->SetVisibility(isVisible);
577  newVisAttributes->SetDaughtersInvisible(isDaughtersInvisible);
578  newVisAttributes->SetColour(red,green,blue);
579  newVisAttributes->SetLineStyle(lineStyle);
580  newVisAttributes->SetLineWidth(lineWidth);
581  if (drawingStyle == G4VisAttributes::wireframe) 
582        newVisAttributes->SetForceWireframe(isForceDrawingStyle);
583  if (drawingStyle == G4VisAttributes::solid) 
584        newVisAttributes->SetForceSolid(isForceDrawingStyle);
585  
586  lv->SetVisAttributes(newVisAttributes);
587
588   
589 //-----------------------------------------------------------------
590 // functions for drawing
591 //-----------------------------------------------------------------
592
593
594 //_____________________________________________________________________________
595 void TG4VisManager::DrawOneSpec(const char* name)
596 {
597 // Function called when one double-clicks on a volume name
598 // in a TPaveLabel drawn by Gdtree
599 // ---
600
601  G4cout << "TG4VisManager::DrawOneSpec() Not yet implemented";
602 }
603
604
605 //_____________________________________________________________________________
606 void TG4VisManager::SetColors()
607 {
608 // Function for setting default volume colours
609 // ---
610
611   G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
612   const G4LogicalVolume* pLV = 0; 
613   if (!pLVStore)
614   {
615     TG4Globals::Warning("TG4VisManager::SetColors : Ignored, geometry not built.");
616     return;
617   }
618   // parse the LV tree and set colours according to material density
619   for (G4int i=0; i<pLVStore->size(); i++)
620   {
621     pLV = (*pLVStore)[i];
622 //    G4cout << "VOLUME : " << pLV->GetName() << G4endl;
623     const G4Material* pMaterial = pLV->GetMaterial();
624     const G4State kState = pMaterial->GetState();
625     G4double density = (pMaterial->GetDensity())*cm3/g;
626     G4String nState = "Undefined";
627     G4int colour = 1;                   //black by default
628     G4double luminosity = 0.;
629     if (kState == kStateUndefined) 
630     {
631       nState = "Undefined";
632     }
633     if (kState == kStateSolid) 
634     {
635       nState = "Solid";
636       if (density < 2)
637       {
638         colour = 17;    //red
639         luminosity = 25 - 25*density/2;
640       }
641       else if (density < 3)
642       {
643         colour = 117;   //blue
644         luminosity = 25 - 25*(density-2);
645       }
646       else if (density < 10)
647       {
648         colour = 67;    //green
649         luminosity = 25 - 25*(density-5)/5;
650       }
651       else if (density < 15)
652       {
653         colour = 92;    //cyan
654         luminosity = 25 - 25*(density-10)/5;
655       }
656       else if (density < 20)
657       {
658         colour = 8;     //black
659         luminosity = 9 - 9*(density-15)/5;
660       }
661     }
662     if (kState == kStateLiquid) 
663     {
664       nState = "Liquid";
665       colour = 142;     //violet
666       luminosity = 25 - 25*density/2;
667     }
668     if (kState == kStateGas) 
669     {
670       nState = "Gas";
671       if (density < 0.001)  {colour = 42;}      //yellow
672       else if (density < 0.002) {colour = 27;}  //light red
673       else if (density < 0.003) {colour = 77;}  //light green
674       else {colour = 102;}                      //light cyan
675       luminosity = 0;
676     }
677     if (luminosity < 0) luminosity=0;
678     colour += (G4int)luminosity;
679     //  Setting the corresponding colour
680     Gsatt(pLV->GetName(),"COLO",colour);
681   }
682
683   
684
685 //_____________________________________________________________________________
686 void TG4VisManager::Gsatt(const char* name, const char* att, Int_t val)
687 {
688 // Geant3 description :
689 //  
690 //    NAME   Volume name
691 //    IOPT   Name of the attribute to be set
692 //    IVAL   Value to which the attribute is to be set
693 //  
694 //    name= "*" stands for all the volumes.
695 //    iopt can be chosen among the following :
696 //    kWORK, kSEEN, kLSTY, kLWID, kCOLO, kFILL, kSET, kDET, kDTYP
697 // ---
698
699  G4int ival = val;
700  G4LogicalVolume* lv = 0; 
701  LogicalVolumesVector lvList;
702  G4String sname(name),
703           satt(att);            
704
705  // seek for known attributes
706  TG4G3Attribute attribute = kUNKNOWN;
707  if (CaseInsensitiveEqual(att,"WORK"))
708  {
709    G4String message = "TG4VisManager::Gsatt: G3Attribute ";
710    message += satt + " not used in G4";
711    TG4Globals::Warning(message);
712    return;
713  }
714  if (CaseInsensitiveEqual(att,"SEEN"))  attribute = kSEEN;  
715  if (CaseInsensitiveEqual(att,"LSTY"))  attribute = kLSTY;  
716  if (CaseInsensitiveEqual(att,"LWID"))  attribute = kLWID;
717  if (CaseInsensitiveEqual(att,"COLO"))  attribute = kCOLO;  
718  if (CaseInsensitiveEqual(att,"FILL"))  attribute = kFILL;  
719  if (CaseInsensitiveEqual(att,"SET"))
720  {
721    G4String message = "TG4VisManager::Gsatt: G3Attribute ";
722    message += satt + " not used in G4";
723    TG4Globals::Warning(message);
724    return;
725  }
726  if (CaseInsensitiveEqual(att,"DET"))
727  {
728    G4String message = "TG4VisManager::Gsatt: G3Attribute ";
729    message += satt + " not used in G4";
730    TG4Globals::Warning(message);
731    return;
732  }
733  if (CaseInsensitiveEqual(att,"DTYP"))
734  {
735    G4String message = "TG4VisManager::Gsatt: G3Attribute ";
736    message += satt + " not used in G4";
737    TG4Globals::Warning(message);
738    return;
739  }
740  if (attribute == kUNKNOWN)
741  {
742    G4String message = "TG4VisManager::Gsatt: G3Attribute ";
743    message += satt + " unknown";
744    TG4Globals::Warning(message);
745    return;
746  }
747  G4bool  doForDaughters(false),         // tree iterator flag 
748          doForAll(false),               // activated if NAME is "*" 
749          topVisible(false);             // activated for kSEEN/-2
750  if (sname == "*")      doForAll = true;
751  if (val < 0 && sname!="*") doForDaughters = true;
752  if (attribute==kSEEN && val==-2) topVisible = true;
753  
754  // parse all the tree
755  if (doForAll)
756  {
757      G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
758      for (G4int i=0; i<pLVStore->size(); i++)
759      {
760          lv = (*pLVStore)[i];
761          SetG4Attribute(lv,attribute,ival);
762      }
763      return;
764  }
765
766  // get the logical volume pointer corresponding to NAME
767  lvList = GetLVList(name);
768  if (lvList.size()==0)
769  {
770      G4String message = "TG4VisManager::Gsatt(): Ignored\n";
771      message += "    Logical volume " + sname + " has not been found.\n";
772      TG4Globals::Warning(message); 
773      return;
774  }
775 // set attribute for all descendents
776  if (doForDaughters)
777  {
778    for (G4int i=0; i<lvList.size(); i++)
779    {
780      lv = lvList[i];
781      SetAtt4Daughters(lv,attribute,ival);
782    }     
783  }
784  else
785  {
786    for (G4int i=0; i<lvList.size(); i++)
787    {
788      lv = lvList[i];
789      SetG4Attribute(lv,attribute,ival);
790    }     
791  }
792  if (topVisible) 
793  {
794    for (G4int i=0; i<lvList.size(); i++)
795    {
796      lv = lvList[i];
797      SetG4Attribute(lv,attribute,1); 
798    }
799  }       
800
801
802
803 //_____________________________________________________________________________
804 void TG4VisManager::Gdraw(const char *name,Float_t theta, Float_t phi, Float_t psi,
805                     Float_t u0,Float_t v0,Float_t ul,Float_t vl)
806
807 // Draw the physical volume NAME and all descendents;
808 // Mandatory : the graphics system, scene and view must be
809 //      initialized, e.g. "/vis~/create_view/new_graphics_system OGLSX";
810 //      Any call of Gdraw() will use the current graphics system and
811 //      the current window.
812 // The result will be a centered view drawing of the designated volume,
813 //      lights moving with camera, viewpoint direction given by theta/phi
814 //      and rotation on the screen given by psi;
815 // The u0, v0, ul, vl factors are ignored since the object will be 
816 //      automatically centered and will be confortable in the window
817 //      at any viewing angle.
818 //
819 // check if G4 graphics is ready for drawing
820 // ---
821
822   G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
823   if (!pVVisManager) { 
824     TG4Globals::Warning(
825        "TG4VisManager::Gdraw: Ignored - No graphics driver is built. ");
826     return;
827   }     
828   if (NeedSetColours())
829   {
830     SetColors();
831     SetColourFlag(false);
832   }
833   
834   const G4double kRad = M_PI/180.;
835   PhysicalVolumesVector pvList;
836   G4String sname(name);
837   G4bool  successful            = false;
838
839   pvList = GetPVList(name);
840   if (pvList.size()==0)
841   {
842     G4String message = "TG4VisManager::Gdraw() :\n";
843     message += "Volume " + sname + " not found. Bailing out";
844     TG4Globals::Warning(message); 
845     return;
846   }
847
848   G4VPhysicalVolume *pPV = 0;
849
850   // clear the current scene if not empty
851   if (!fpScene->IsEmpty()) fpScene->Clear();
852
853   // create and add object's model list to the runtime-duration model 
854   // list and draw it
855   // (it is deleted in the VisManager destructor within 
856   // all the vectors of the scene)
857   for (G4int i=0; i<pvList.size(); i++)
858   { 
859     pPV = pvList[i];
860     G4LogicalVolume* pLV = pPV->GetLogicalVolume();
861     G4VSolid* pSolid = pLV->GetSolid();
862     successful = fpScene->AddRunDurationModel(new G4PhysicalVolumeModel(pPV));
863     if (!successful) 
864     {
865       G4String message = "TG4VisManager::Gdraw() Could not add ";
866       message += pPV->GetName() + " to the drawing list. Probably ";
867       message += "it is already in the list.";
868       TG4Globals::Warning(message);
869     }  
870   }
871   // get the standard target point of the scene
872   const G4Point3D kTargetPoint = fpScene->GetStandardTargetPoint();
873
874   // set the viewpoint and the rotation on the screen
875   G4Vector3D viewpointDirection(sin(theta*kRad)*cos(phi*kRad), 
876                                 sin(theta*kRad)*sin(phi*kRad), cos(theta*kRad)); 
877   G4Vector3D upVector(sin(psi*kRad), cos(psi*kRad),0);                         
878
879   // set and register view parameters to the viewer
880   
881   fVP.SetLightsMoveWithCamera(true);
882   fVP.SetViewGeom();
883   fVP.UnsetViewHits();
884   fVP.UnsetViewDigis();
885   fVP.SetNoOfSides(48);
886   fVP.SetCurrentTargetPoint(kTargetPoint);
887   fVP.SetViewpointDirection(viewpointDirection);
888   fVP.SetUpVector(upVector);
889   fVP.SetDensityCulling(true);
890   fpViewer->SetViewParameters(fVP);
891
892   if (IsValidView())
893   {
894     fpSceneHandler->SetScene(fpScene);
895     fpSceneHandler->SetCurrentViewer(fpViewer);
896     fpViewer->DrawView();
897     fpViewer->ShowView();
898   }
899   else TG4Globals::Warning(
900          "TG4VisManager::Gdraw: Ignored - Failed to register volume"); 
901 }
902 #endif //G4VIS_USE