source: trunk/geant4/visualization/management/src/G4VisCommandsCompound.cc @ 558

Last change on this file since 558 was 531, checked in by garnier, 17 years ago

r660@mac-90108: laurentgarnier | 2007-06-25 16:10:12 +0200
ajout de fichiers NON modifies

  • Property svn:mime-type set to text/cpp
File size: 13.1 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: G4VisCommandsCompound.cc,v 1.35 2006/12/12 11:48:13 gcosmo Exp $
28// GEANT4 tag $Name: geant4-08-02-patch-01 $
29
30// Compound /vis/ commands - John Allison  15th May 2000
31
32#include "G4VisCommandsCompound.hh"
33
34#include "G4VisManager.hh"
35#include "G4UImanager.hh"
36#include "G4UIcmdWithAString.hh"
37
38#include <sstream>
39
40////////////// /vis/drawTree ///////////////////////////////////////
41
42G4VisCommandDrawTree::G4VisCommandDrawTree() {
43  G4bool omitable;
44  fpCommand = new G4UIcommand("/vis/drawTree", this);
45  fpCommand->SetGuidance
46    ("(DTREE) Creates a scene consisting of this physical volume and"
47     "\n  produces a representation of the geometry hieracrhy.");
48  fpCommand->SetGuidance("The scene becomes current.");
49  G4UIparameter* parameter;
50  parameter = new G4UIparameter("physical-volume-name", 's', omitable = true);
51  parameter -> SetDefaultValue("world");
52  fpCommand -> SetParameter (parameter);
53  parameter = new G4UIparameter("system", 's', omitable = true);
54  parameter -> SetDefaultValue("ATree");
55  fpCommand -> SetParameter (parameter);
56}
57
58G4VisCommandDrawTree::~G4VisCommandDrawTree() {
59  delete fpCommand;
60}
61
62void G4VisCommandDrawTree::SetNewValue(G4UIcommand*, G4String newValue) {
63
64  G4String pvname, system;
65  std::istringstream is(newValue);
66  is >> pvname >> system;
67
68  G4UImanager* UImanager = G4UImanager::GetUIpointer();
69  G4int keepVerbose = UImanager->GetVerboseLevel();
70  G4int newVerbose(0);
71  if (keepVerbose >= 2 ||
72      fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
73    newVerbose = 2;
74  UImanager->SetVerboseLevel(newVerbose);
75  UImanager->ApplyCommand(G4String("/vis/open " + system));
76  UImanager->ApplyCommand(G4String("/vis/drawVolume " + pvname));
77  UImanager->ApplyCommand("/vis/viewer/flush");
78  UImanager->SetVerboseLevel(keepVerbose);
79}
80
81////////////// /vis/drawView ///////////////////////////////////////
82
83G4VisCommandDrawView::G4VisCommandDrawView() {
84  G4bool omitable;
85  fpCommand = new G4UIcommand("/vis/drawView", this);
86  fpCommand->SetGuidance
87    ("Draw view from this angle, etc.");
88  G4UIparameter* parameter;
89  parameter = new G4UIparameter("theta-degrees", 'd', omitable = true);
90  parameter -> SetDefaultValue(0.);
91  fpCommand -> SetParameter (parameter);
92  parameter = new G4UIparameter("phi-degrees", 'd', omitable = true);
93  parameter -> SetDefaultValue(0.);
94  fpCommand -> SetParameter (parameter);
95  parameter = new G4UIparameter("pan-right", 'd', omitable = true);
96  parameter -> SetDefaultValue(0.);
97  fpCommand -> SetParameter (parameter);
98  parameter = new G4UIparameter("pan-up", 'd', omitable = true);
99  parameter -> SetDefaultValue(0.);
100  fpCommand -> SetParameter (parameter);
101  parameter = new G4UIparameter("pan-unit", 's', omitable = true);
102  parameter -> SetDefaultValue("cm");
103  fpCommand -> SetParameter (parameter);
104  parameter = new G4UIparameter("zoom-factor", 'd', omitable = true);
105  parameter -> SetDefaultValue(1.);
106  fpCommand -> SetParameter (parameter);
107  parameter = new G4UIparameter("dolly", 'd', omitable = true);
108  parameter -> SetDefaultValue(0.);
109  fpCommand -> SetParameter (parameter);
110  parameter = new G4UIparameter("dolly-unit", 's', omitable = true);
111  parameter -> SetDefaultValue("cm");
112  fpCommand -> SetParameter (parameter);
113}
114
115G4VisCommandDrawView::~G4VisCommandDrawView() {
116  delete fpCommand;
117}
118
119void G4VisCommandDrawView::SetNewValue(G4UIcommand*, G4String newValue) {
120
121  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
122
123  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
124  if (!currentViewer) {
125    if (verbosity >= G4VisManager::warnings) {
126      G4cout <<
127        "WARNING: G4VisCommandsDrawView::SetNewValue: no current viewer."
128             << G4endl;
129    }
130    return;
131  }
132
133  G4String thetaDeg;
134  G4String phiDeg;
135  G4String panRight;
136  G4String panUp;
137  G4String panUnit;
138  G4String zoomFactor;
139  G4String dolly;
140  G4String dollyUnit;
141  std::istringstream is(newValue);
142  is >> thetaDeg >> phiDeg >> panRight >> panUp >> panUnit
143     >> zoomFactor >> dolly >> dollyUnit;
144 
145  G4UImanager* UImanager = G4UImanager::GetUIpointer();
146  G4int keepVerbose = UImanager->GetVerboseLevel();
147  G4int newVerbose(0);
148  if (keepVerbose >= 2 ||
149      fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
150    newVerbose = 2;
151  UImanager->SetVerboseLevel(newVerbose);
152  G4ViewParameters vp = currentViewer->GetViewParameters();
153  G4bool keepAutoRefresh = vp.IsAutoRefresh();
154  vp.SetAutoRefresh(false);
155  currentViewer->SetViewParameters(vp);
156  UImanager->ApplyCommand(
157    G4String("/vis/viewer/set/viewpointThetaPhi " + thetaDeg + " " + phiDeg + " deg"));
158  UImanager->ApplyCommand(
159    G4String("/vis/viewer/panTo " + panRight + " " + panUp + " " + panUnit));
160  UImanager->ApplyCommand(
161    G4String("/vis/viewer/zoomTo " + zoomFactor));
162  vp = currentViewer->GetViewParameters();
163  vp.SetAutoRefresh(keepAutoRefresh);
164  currentViewer->SetViewParameters(vp);
165  UImanager->ApplyCommand(
166    G4String("/vis/viewer/dollyTo " + dolly + " " + dollyUnit));
167  UImanager->SetVerboseLevel(keepVerbose);
168}
169
170////////////// /vis/drawVolume ///////////////////////////////////////
171
172G4VisCommandDrawVolume::G4VisCommandDrawVolume() {
173  G4bool omitable;
174  fpCommand = new G4UIcmdWithAString("/vis/drawVolume", this);
175  fpCommand->SetGuidance
176    ("Creates a scene containing this physical volume and asks the"
177     "\ncurrent viewer to draw it.  The scene becomes current.");
178  fpCommand -> SetGuidance
179    ("If physical-volume-name is \"world\" (the default), the main geometry"
180     "\ntree (material world) is drawn.  If \"worlds\", all worlds - material"
181     "\nworld and parallel worlds, if any - are drawn.  Otherwise a search of"
182     "\nall worlds is made, taking the first matching occurence only.  To see"
183     "\na representation of the geometry hierarchy of the worlds, try"
184     "\n\"/vis/drawTree [worlds]\" or one of the driver/browser combinations"
185     "\nthat have the required functionality, e.g., HepRepFile/XML with the"
186     "\nWIRED3/4 browser.");
187  fpCommand->SetParameterName("physical-volume-name", omitable = true);
188  fpCommand->SetDefaultValue("world");
189}
190
191G4VisCommandDrawVolume::~G4VisCommandDrawVolume() {
192  delete fpCommand;
193}
194
195void G4VisCommandDrawVolume::SetNewValue(G4UIcommand*, G4String newValue) {
196  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
197  G4UImanager* UImanager = G4UImanager::GetUIpointer();
198  G4int keepVerbose = UImanager->GetVerboseLevel();
199  G4int newVerbose(0);
200  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
201    newVerbose = 2;
202  UImanager->SetVerboseLevel(newVerbose);
203  UImanager->ApplyCommand("/vis/scene/create");
204//  UImanager->ApplyCommand("/vis/scene/add/eventID");
205  UImanager->ApplyCommand(G4String("/vis/scene/add/volume " + newValue));
206  UImanager->ApplyCommand("/vis/sceneHandler/attach");
207  UImanager->SetVerboseLevel(keepVerbose);
208  static G4bool warned = false;
209  if (verbosity >= G4VisManager::warnings && !warned) {
210    G4cout <<
211      "WARNING: For systems which are not \"auto-refresh\" you will need to"
212      "\n  issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
213           << G4endl;
214    warned = true;
215  }
216}
217
218////////////// /vis/open ///////////////////////////////////////
219
220G4VisCommandOpen::G4VisCommandOpen() {
221  G4bool omitable;
222  fpCommand = new G4UIcommand("/vis/open", this);
223  fpCommand->SetGuidance
224    ("Creates a scene handler ready for drawing.");
225  fpCommand->SetGuidance
226    ("The scene handler becomes current (the name is auto-generated).");
227  G4UIparameter* parameter;
228  parameter = new G4UIparameter("graphics-system-name", 's', omitable = false);
229   const G4GraphicsSystemList& gslist =
230    fpVisManager->GetAvailableGraphicsSystems();
231  G4String candidates;
232  for (size_t igslist = 0; igslist < gslist.size(); igslist++) {
233    const G4String& name = gslist[igslist]->GetName();
234    const G4String& nickname = gslist[igslist]->GetNickname();
235    if (nickname.isNull()) {
236      candidates += name;
237    }
238    else {
239      candidates += nickname;
240    }
241    candidates += " ";
242  }
243  candidates = candidates.strip();
244  parameter->SetParameterCandidates(candidates);
245  fpCommand->SetParameter(parameter);
246  parameter = new G4UIparameter("window-size-hint", 's', omitable = true);
247  parameter->SetGuidance
248    ("integer (pixels) for square window placed by window manager or"
249     " X-Windows-type geometry string, e.g. 600x600-100+100");
250  parameter->SetDefaultValue("600");
251  fpCommand->SetParameter(parameter);
252}
253
254G4VisCommandOpen::~G4VisCommandOpen() {
255  delete fpCommand;
256}
257
258void G4VisCommandOpen::SetNewValue (G4UIcommand*, G4String newValue) {
259  G4String systemName, windowSizeHint;
260  std::istringstream is(newValue);
261  is >> systemName >> windowSizeHint;
262  G4UImanager* UImanager = G4UImanager::GetUIpointer();
263  G4int keepVerbose = UImanager->GetVerboseLevel();
264  G4int newVerbose(0);
265  if (keepVerbose >= 2 ||
266      fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
267    newVerbose = 2;
268  UImanager->SetVerboseLevel(newVerbose);
269  UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
270  UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
271  UImanager->SetVerboseLevel(keepVerbose);
272}
273
274////////////// /vis/specify ///////////////////////////////////////
275
276G4VisCommandSpecify::G4VisCommandSpecify() {
277  G4bool omitable;
278  fpCommand = new G4UIcommand("/vis/specify", this);
279  fpCommand->SetGuidance
280    ("Draws logical volume with Boolean components, voxels and readout geometry.");
281  fpCommand->SetGuidance
282    ("Creates a scene consisting of this logical volume and asks the"
283     "\n  current viewer to draw it to the specified depth of descent"
284     "\n  showing boolean components (if any), voxels (if any)"
285     "\n  and readout geometry (if any), under control of the appropriate flag.");
286  fpCommand->SetGuidance
287    ("Note: voxels are not constructed until start of run - /run/beamOn.");
288  fpCommand->SetGuidance("The scene becomes current.");
289  G4UIparameter* parameter;
290  parameter = new G4UIparameter("logical-volume-name", 's', omitable = false);
291  fpCommand->SetParameter(parameter);
292  parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true);
293  parameter->SetDefaultValue(1);
294  fpCommand->SetParameter(parameter);
295  parameter = new G4UIparameter("booleans-flag", 'b', omitable = true);
296  parameter->SetDefaultValue(true);
297  fpCommand->SetParameter(parameter);
298  parameter = new G4UIparameter("voxels-flag", 'b', omitable = true);
299  parameter->SetDefaultValue(true);
300  fpCommand->SetParameter(parameter);
301  parameter = new G4UIparameter("readout-flag", 'b', omitable = true);
302  parameter->SetDefaultValue(true);
303  fpCommand->SetParameter(parameter);
304}
305
306G4VisCommandSpecify::~G4VisCommandSpecify() {
307  delete fpCommand;
308}
309
310void G4VisCommandSpecify::SetNewValue(G4UIcommand*, G4String newValue) {
311  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
312  G4UImanager* UImanager = G4UImanager::GetUIpointer();
313  G4int keepVerbose = UImanager->GetVerboseLevel();
314  G4int newVerbose(0);
315  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
316    newVerbose = 2;
317  UImanager->SetVerboseLevel(newVerbose);
318  // UImanager->ApplyCommand(G4String("/geometry/print " + newValue));
319  UImanager->ApplyCommand("/vis/scene/create");
320  UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
321  UImanager->ApplyCommand("/vis/sceneHandler/attach");
322  UImanager->SetVerboseLevel(keepVerbose);
323  static G4bool warned = false;
324  if (verbosity >= G4VisManager::warnings && !warned) {
325    G4cout <<
326      "WARNING: For systems which are not \"auto-refresh\" you will need to"
327      "\n  issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
328           << G4endl;
329    warned = true;
330  }
331}
Note: See TracBrowser for help on using the repository browser.