source: trunk/source/visualization/management/src/G4VisCommandsCompound.cc@ 912

Last change on this file since 912 was 850, checked in by garnier, 17 years ago

geant4.8.2 beta

  • Property svn:mime-type set to text/cpp
File size: 13.0 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.39 2007/11/16 20:29:04 perl Exp $
28// GEANT4 tag $Name: HEAD $
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., HepRep");
186 fpCommand->SetParameterName("physical-volume-name", omitable = true);
187 fpCommand->SetDefaultValue("world");
188}
189
190G4VisCommandDrawVolume::~G4VisCommandDrawVolume() {
191 delete fpCommand;
192}
193
194void G4VisCommandDrawVolume::SetNewValue(G4UIcommand*, G4String newValue) {
195 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
196 G4UImanager* UImanager = G4UImanager::GetUIpointer();
197 G4int keepVerbose = UImanager->GetVerboseLevel();
198 G4int newVerbose(0);
199 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
200 newVerbose = 2;
201 UImanager->SetVerboseLevel(newVerbose);
202 UImanager->ApplyCommand("/vis/scene/create");
203 UImanager->ApplyCommand(G4String("/vis/scene/add/volume " + newValue));
204 UImanager->ApplyCommand("/vis/sceneHandler/attach");
205 UImanager->SetVerboseLevel(keepVerbose);
206 static G4bool warned = false;
207 if (verbosity >= G4VisManager::confirmations && !warned) {
208 G4cout <<
209 "NOTE: For systems which are not \"auto-refresh\" you will need to"
210 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
211 << G4endl;
212 warned = true;
213 }
214}
215
216////////////// /vis/open ///////////////////////////////////////
217
218G4VisCommandOpen::G4VisCommandOpen() {
219 G4bool omitable;
220 fpCommand = new G4UIcommand("/vis/open", this);
221 fpCommand->SetGuidance
222 ("Creates a scene handler ready for drawing.");
223 fpCommand->SetGuidance
224 ("The scene handler becomes current (the name is auto-generated).");
225 G4UIparameter* parameter;
226 parameter = new G4UIparameter("graphics-system-name", 's', omitable = false);
227 const G4GraphicsSystemList& gslist =
228 fpVisManager->GetAvailableGraphicsSystems();
229 G4String candidates;
230 for (size_t igslist = 0; igslist < gslist.size(); igslist++) {
231 const G4String& name = gslist[igslist]->GetName();
232 const G4String& nickname = gslist[igslist]->GetNickname();
233 if (nickname.isNull()) {
234 candidates += name;
235 }
236 else {
237 candidates += nickname;
238 }
239 candidates += " ";
240 }
241 candidates = candidates.strip();
242 parameter->SetParameterCandidates(candidates);
243 fpCommand->SetParameter(parameter);
244 parameter = new G4UIparameter("window-size-hint", 's', omitable = true);
245 parameter->SetGuidance
246 ("integer (pixels) for square window placed by window manager or"
247 " X-Windows-type geometry string, e.g. 600x600-100+100");
248 parameter->SetDefaultValue("600");
249 fpCommand->SetParameter(parameter);
250}
251
252G4VisCommandOpen::~G4VisCommandOpen() {
253 delete fpCommand;
254}
255
256void G4VisCommandOpen::SetNewValue (G4UIcommand*, G4String newValue) {
257 G4String systemName, windowSizeHint;
258 std::istringstream is(newValue);
259 is >> systemName >> windowSizeHint;
260 G4UImanager* UImanager = G4UImanager::GetUIpointer();
261 G4int keepVerbose = UImanager->GetVerboseLevel();
262 G4int newVerbose(0);
263 if (keepVerbose >= 2 ||
264 fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
265 newVerbose = 2;
266 UImanager->SetVerboseLevel(newVerbose);
267 UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
268 UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
269 UImanager->SetVerboseLevel(keepVerbose);
270}
271
272////////////// /vis/specify ///////////////////////////////////////
273
274G4VisCommandSpecify::G4VisCommandSpecify() {
275 G4bool omitable;
276 fpCommand = new G4UIcommand("/vis/specify", this);
277 fpCommand->SetGuidance
278 ("Draws logical volume with Boolean components, voxels and readout geometry.");
279 fpCommand->SetGuidance
280 ("Creates a scene consisting of this logical volume and asks the"
281 "\n current viewer to draw it to the specified depth of descent"
282 "\n showing boolean components (if any), voxels (if any)"
283 "\n and readout geometry (if any), under control of the appropriate flag.");
284 fpCommand->SetGuidance
285 ("Note: voxels are not constructed until start of run - /run/beamOn.");
286 fpCommand->SetGuidance("The scene becomes current.");
287 G4UIparameter* parameter;
288 parameter = new G4UIparameter("logical-volume-name", 's', omitable = false);
289 fpCommand->SetParameter(parameter);
290 parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true);
291 parameter->SetDefaultValue(1);
292 fpCommand->SetParameter(parameter);
293 parameter = new G4UIparameter("booleans-flag", 'b', omitable = true);
294 parameter->SetDefaultValue(true);
295 fpCommand->SetParameter(parameter);
296 parameter = new G4UIparameter("voxels-flag", 'b', omitable = true);
297 parameter->SetDefaultValue(true);
298 fpCommand->SetParameter(parameter);
299 parameter = new G4UIparameter("readout-flag", 'b', omitable = true);
300 parameter->SetDefaultValue(true);
301 fpCommand->SetParameter(parameter);
302}
303
304G4VisCommandSpecify::~G4VisCommandSpecify() {
305 delete fpCommand;
306}
307
308void G4VisCommandSpecify::SetNewValue(G4UIcommand*, G4String newValue) {
309 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
310 G4UImanager* UImanager = G4UImanager::GetUIpointer();
311 G4int keepVerbose = UImanager->GetVerboseLevel();
312 G4int newVerbose(0);
313 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
314 newVerbose = 2;
315 UImanager->SetVerboseLevel(newVerbose);
316 // UImanager->ApplyCommand(G4String("/geometry/print " + newValue));
317 UImanager->ApplyCommand("/vis/scene/create");
318 UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
319 UImanager->ApplyCommand("/vis/sceneHandler/attach");
320 UImanager->SetVerboseLevel(keepVerbose);
321 static G4bool warned = false;
322 if (verbosity >= G4VisManager::confirmations && !warned) {
323 G4cout <<
324 "NOTE: For systems which are not \"auto-refresh\" you will need to"
325 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
326 << G4endl;
327 warned = true;
328 }
329}
Note: See TracBrowser for help on using the repository browser.