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