Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
g4viscp.py
Go to the documentation of this file.
1 #$Id: g4viscp.py 66892 2013-01-17 10:57:59Z gunter $
2 """
3 # ==================================================================
4 # Python module
5 #
6 # Visualization Control Panel
7 #
8 # Q, 2005
9 # ==================================================================
10 """
11 from G4interface import *
12 
13 # ------------------------------------------------------------------
14 # Scene
15 # ------------------------------------------------------------------
16 class G4Scene :
17  "Scene"
18  def __init__(self, aname, vol= "world", acopyno=0,
19  amode=0, bmode=1):
20  self.name= aname
21  self.volume= vol
22  self.copyno= acopyno
23  self.mode_eventaction= amode # 0: accumulate / 1: refresh
24  self.mode_runaction= bmode # 0: accumulate / 1: refresh
25  self.mode= ("accumulate", "refresh")
26 
27  def create_scene(self):
28  ApplyUICommand("/vis/scene/create " + self.name)
29  ApplyUICommand("/vis/scene/add/volume %s %d" %
30  (self.volume, self.copyno))
31  ApplyUICommand("/vis/scene/add/trajectories")
32  self.update_scene()
33 
34  def update_scene(self):
35  ApplyUICommand("/vis/scene/select " + self.name)
36  ApplyUICommand("/vis/sceneHandler/attach")
37  ApplyUICommand("/vis/scene/endOfEventAction %s" %
38  (self.mode[self.mode_eventaction]) )
39  ApplyUICommand("/vis/scene/endOfRunAction %s" %
40  (self.mode[self.mode_runaction]) )
41 
42 # ------------------------------------------------------------------
43 # Visualization Control Panel
44 # ------------------------------------------------------------------
45 class G4VisCP :
46  "G4 Visualization Control Panel"
47 
48  def __init__(self, gsys="OGLIX"):
49  self.gsystem= gsys
50  self.scenelist= [G4Scene("default")]
51  self.viewpoint= [270., 90.]
52 
53  rc= ApplyUICommand("/vis/open " + gsys)
54  if (rc != 0):
55  return
56 
57  self.scenelist[0].create_scene()
58  ApplyUICommand("/vis/viewer/set/viewpointThetaPhi %f %f"
59  % (self.viewpoint[0], self.viewpoint[1]) )
60  ApplyUICommand("/tracking/storeTrajectory 1")
61 
62  def add_scene(self, ascene):
63  self.scenelist.append(ascene)
64 
65  def select_scene(self, iscene):
66  self.scenelist[iscene].update_scene()
67  ApplyUICommand("/vis/viewer/set/viewpointThetaPhi %f %f"
68  % (self.viewpoint[0], self.viewpoint[1]) )
69