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