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