Geant4-11
G4VisCommandsCompound.cc
Go to the documentation of this file.
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
28// Compound /vis/ commands - John Allison 15th May 2000
29
31
32#include "G4VisManager.hh"
33#include "G4UImanager.hh"
34#include "G4UIcommandTree.hh"
35#include "G4UIcmdWithAString.hh"
36
37#include <sstream>
38#include <set>
39
41
43 G4bool omitable;
44 fpCommand = new G4UIcommand("/vis/drawTree", this);
46 ("Produces a representation of the geometry hierarchy. Further"
47 "\nguidance is given on running the command. Or look at the guidance"
48 "\nfor \"/vis/ASCIITree/verbose\".");
49 fpCommand->SetGuidance("The pre-existing scene and view are preserved.");
50 G4UIparameter* parameter;
51 parameter = new G4UIparameter("physical-volume-name", 's', omitable = true);
52 parameter -> SetDefaultValue("world");
53 fpCommand -> SetParameter (parameter);
54 parameter = new G4UIparameter("system", 's', omitable = true);
55 parameter -> SetDefaultValue("ATree");
56 fpCommand -> SetParameter (parameter);
57}
58
60 delete fpCommand;
61}
62
64
65 G4String pvname, system;
66 std::istringstream is(newValue);
67 is >> pvname >> system;
68
69 // Note: The second parameter, "system", is intended to allow the user
70 // a choice of dedicated tree printing/displaying systems but at present
71 // the only such dedicated system is ASCIITree. It doesn't make sense to
72 // specify OGLSX, for example. So to avoid confusion we restrict this
73 // feature to systems that have "Tree" in the name or nickname.
74
75 // Of course, some other systems, such as OGLSQt, have a tree browser
76 // built-in. The HepRApp offline browser also has a tree browser
77 // built in.
78
79 if (!G4StrUtil::contains(system, "Tree")) {
80 system = "ATree";
81 }
82
84 G4Scene* keepScene = fpVisManager->GetCurrentScene();
88 G4bool keepAbleness = fpVisManager->GetConcreteInstance()? true: false;
89
91 G4int keepUIVerbose = UImanager->GetVerboseLevel();
92 G4int newVerbose(0);
93 if (keepUIVerbose >= 2 ||
95 newVerbose = 2;
96 UImanager->SetVerboseLevel(newVerbose);
97
98 auto errorCode = UImanager->ApplyCommand(G4String("/vis/open " + system));
99 if (errorCode == 0) {
100 if (!keepAbleness) { // Enable temporarily
102 UImanager->ApplyCommand("/vis/enable");
103 fpVisManager->SetVerboseLevel(keepVisVerbosity);
104 }
105 UImanager->ApplyCommand("/vis/viewer/reset");
106 UImanager->ApplyCommand(G4String("/vis/drawVolume " + pvname));
107 UImanager->ApplyCommand("/vis/viewer/flush");
108 if (!keepAbleness) { // Disable again
110 UImanager->ApplyCommand("/vis/disable");
111 fpVisManager->SetVerboseLevel(keepVisVerbosity);
112 }
113 if (keepViewer) {
115 G4cout << "Reverting to " << keepViewer->GetName() << G4endl;
116 }
118 fpVisManager->SetCurrentScene(keepScene);
119 fpVisManager->SetCurrentSceneHandler(keepSceneHandler);
120 fpVisManager->SetCurrentViewer(keepViewer);
121 }
122 }
123 UImanager->SetVerboseLevel(keepUIVerbose);
124}
125
127
129 G4bool omitable;
130 fpCommand = new G4UIcommand("/vis/drawView", this);
132 ("Draw view from this angle, etc.");
133 G4UIparameter* parameter;
134 parameter = new G4UIparameter("theta-degrees", 'd', omitable = true);
135 parameter -> SetDefaultValue(0.);
136 fpCommand -> SetParameter (parameter);
137 parameter = new G4UIparameter("phi-degrees", 'd', omitable = true);
138 parameter -> SetDefaultValue(0.);
139 fpCommand -> SetParameter (parameter);
140 parameter = new G4UIparameter("pan-right", 'd', omitable = true);
141 parameter -> SetDefaultValue(0.);
142 fpCommand -> SetParameter (parameter);
143 parameter = new G4UIparameter("pan-up", 'd', omitable = true);
144 parameter -> SetDefaultValue(0.);
145 fpCommand -> SetParameter (parameter);
146 parameter = new G4UIparameter("pan-unit", 's', omitable = true);
147 parameter -> SetDefaultValue("cm");
148 fpCommand -> SetParameter (parameter);
149 parameter = new G4UIparameter("zoom-factor", 'd', omitable = true);
150 parameter -> SetDefaultValue(1.);
151 fpCommand -> SetParameter (parameter);
152 parameter = new G4UIparameter("dolly", 'd', omitable = true);
153 parameter -> SetDefaultValue(0.);
154 fpCommand -> SetParameter (parameter);
155 parameter = new G4UIparameter("dolly-unit", 's', omitable = true);
156 parameter -> SetDefaultValue("cm");
157 fpCommand -> SetParameter (parameter);
158}
159
161 delete fpCommand;
162}
163
165
167
168 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
169 if (!currentViewer) {
170 if (verbosity >= G4VisManager::warnings) {
171 G4cout <<
172 "WARNING: G4VisCommandsDrawView::SetNewValue: no current viewer."
173 << G4endl;
174 }
175 return;
176 }
177
178 G4String thetaDeg;
179 G4String phiDeg;
180 G4String panRight;
181 G4String panUp;
182 G4String panUnit;
183 G4String zoomFactor;
184 G4String dolly;
185 G4String dollyUnit;
186 std::istringstream is(newValue);
187 is >> thetaDeg >> phiDeg >> panRight >> panUp >> panUnit
188 >> zoomFactor >> dolly >> dollyUnit;
189
191 G4int keepVerbose = UImanager->GetVerboseLevel();
192 G4int newVerbose(0);
193 if (keepVerbose >= 2 ||
195 newVerbose = 2;
196 UImanager->SetVerboseLevel(newVerbose);
197 G4ViewParameters vp = currentViewer->GetViewParameters();
198 G4bool keepAutoRefresh = vp.IsAutoRefresh();
199 vp.SetAutoRefresh(false);
200 currentViewer->SetViewParameters(vp);
201 UImanager->ApplyCommand(
202 G4String("/vis/viewer/set/viewpointThetaPhi " + thetaDeg + " " + phiDeg + " deg"));
203 UImanager->ApplyCommand(
204 G4String("/vis/viewer/panTo " + panRight + " " + panUp + " " + panUnit));
205 UImanager->ApplyCommand(
206 G4String("/vis/viewer/zoomTo " + zoomFactor));
207 vp = currentViewer->GetViewParameters();
208 vp.SetAutoRefresh(keepAutoRefresh);
209 currentViewer->SetViewParameters(vp);
210 UImanager->ApplyCommand(
211 G4String("/vis/viewer/dollyTo " + dolly + " " + dollyUnit));
212 UImanager->SetVerboseLevel(keepVerbose);
213}
214
216
218 fpCommand = new G4UIcommand("/vis/drawLogicalVolume", this);
220 ("Draws logical volume with additional components.");
222 ("Synonymous with \"/vis/specify\".");
224 ("Creates a scene consisting of this logical volume and asks the"
225 "\n current viewer to draw it. The scene becomes current.");
227 const G4UIcommand* addLogVolCmd = tree->FindPath("/vis/scene/add/logicalVolume");
228 // Pick up guidance from /vis/scene/add/logicalVolume
229 CopyGuidanceFrom(addLogVolCmd,fpCommand);
230 // Pick up parameters from /vis/scene/add/logicalVolume
231 CopyParametersFrom(addLogVolCmd,fpCommand);
232}
233
235 delete fpCommand;
236}
237
241 G4int keepVerbose = UImanager->GetVerboseLevel();
242 G4int newVerbose(0);
243 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
244 newVerbose = 2;
245 UImanager->SetVerboseLevel(newVerbose);
246 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
247 const G4ViewParameters& currentViewParams = currentViewer->GetViewParameters();
248 G4bool keepAutoRefresh = currentViewParams.IsAutoRefresh();
249 if (keepAutoRefresh) UImanager->ApplyCommand("/vis/viewer/set/autoRefresh false");
250 UImanager->ApplyCommand("/vis/scene/create");
251 UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
252 UImanager->ApplyCommand("/vis/sceneHandler/attach");
253 G4ViewParameters::DrawingStyle keepDrawingStyle = currentViewParams.GetDrawingStyle();
254 if(keepDrawingStyle != G4ViewParameters::wireframe)
255 UImanager->ApplyCommand("/vis/viewer/set/style wireframe");
256 G4bool keepMarkerNotHidden = currentViewParams.IsMarkerNotHidden();
257 if (!keepMarkerNotHidden) UImanager->ApplyCommand("/vis/viewer/set/hiddenMarker false");
258 if (keepAutoRefresh) UImanager->ApplyCommand("/vis/viewer/set/autoRefresh true");
259 UImanager->SetVerboseLevel(keepVerbose);
260 if (verbosity >= G4VisManager::warnings) {
261 if (keepDrawingStyle != currentViewParams.GetDrawingStyle()) {
262 G4cout
263 << "Drawing style changed to wireframe. To restore previous style:";
264 G4String style, edge;
265 switch (keepDrawingStyle) {
267 style = "wireframe"; edge = "false"; break;
269 style = "wireframe"; edge = "true"; break;
271 style = "surface"; edge = "false"; break;
273 style = "surface"; edge = "true"; break;
275 style = "cloud"; edge = ""; break;
276 }
277 G4cout << "\n /vis/viewer/set/style " + style;
278 if (!edge.empty()) G4cout << "\n /vis/viewer/set/hiddenEdge " + edge;
279 G4cout << G4endl;
280 }
281 if (keepMarkerNotHidden != currentViewParams.IsMarkerNotHidden()) {
282 G4cout
283 << "Markers changed to \"not hidden\". To restore previous condition:"
284 << "\n /vis/viewer/set/hiddenmarker true"
285 << G4endl;
286 }
287 }
288 static G4bool warned = false;
289 if (verbosity >= G4VisManager::confirmations && !warned) {
290 G4cout <<
291 "NOTE: For systems which are not \"auto-refresh\" you will need to"
292 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
293 << G4endl;
294 warned = true;
295 }
296}
297
299
301 fpCommand = new G4UIcommand("/vis/drawVolume", this);
303 ("Creates a scene containing this physical volume and asks the"
304 "\ncurrent viewer to draw it. The scene becomes current.");
306 const G4UIcommand* addVolCmd = tree->FindPath("/vis/scene/add/volume");
307 // Pick up guidance from /vis/scene/add/volume
308 CopyGuidanceFrom(addVolCmd,fpCommand);
309 // Pick up parameters from /vis/scene/add/volume
310 CopyParametersFrom(addVolCmd,fpCommand);
311}
312
314 delete fpCommand;
315}
316
320 G4int keepVerbose = UImanager->GetVerboseLevel();
321 G4int newVerbose(0);
322 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
323 newVerbose = 2;
324 UImanager->SetVerboseLevel(newVerbose);
325 UImanager->ApplyCommand("/vis/scene/create");
326 UImanager->ApplyCommand(G4String("/vis/scene/add/volume " + newValue));
327 UImanager->ApplyCommand("/vis/sceneHandler/attach");
328 UImanager->SetVerboseLevel(keepVerbose);
329 static G4bool warned = false;
330 if (verbosity >= G4VisManager::confirmations && !warned) {
331 G4cout <<
332 "NOTE: For systems which are not \"auto-refresh\" you will need to"
333 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
334 << G4endl;
335 warned = true;
336 }
337}
338
340
342 G4bool omitable;
343 fpCommand = new G4UIcommand("/vis/open", this);
345 ("Creates a scene handler ready for drawing.");
347 ("The scene handler becomes current (the name is auto-generated).");
348 G4UIparameter* parameter;
349 parameter = new G4UIparameter("graphics-system-name", 's', omitable = false);
350 fpCommand->SetParameter(parameter);
351 parameter = new G4UIparameter("window-size-hint", 's', omitable = true);
352 parameter->SetGuidance
353 ("integer (pixels) for square window placed by window manager or"
354 " X-Windows-type geometry string, e.g. 600x600-100+100");
355 parameter->SetDefaultValue("600");
356 fpCommand->SetParameter(parameter);
357}
358
360 delete fpCommand;
361}
362
364{
365 G4String systemName, windowSizeHint;
366 std::istringstream is(newValue);
367 is >> systemName >> windowSizeHint;
369 G4int keepVerbose = UImanager->GetVerboseLevel();
370 G4int newVerbose(0);
371 if (keepVerbose >= 2 ||
373 newVerbose = 2;
374 UImanager->SetVerboseLevel(newVerbose);
375
376 auto errorCode = UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
377 if (errorCode) {
379 ed << "sub-command \"/vis/sceneHandler/create\" failed.";
380 command->CommandFailed(errorCode,ed);
381 goto finish;
382 }
383 errorCode = UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
384 if (errorCode) {
386 ed << "sub-command \"/vis/viewer/create\" failed.";
387 command->CommandFailed(errorCode,ed);
388 goto finish;
389 }
390
391finish:
392 if (errorCode) {
393 std::set<G4String> candidates;
394 for (const auto gs: fpVisManager -> GetAvailableGraphicsSystems()) {
395 // Just list nicknames, but exclude FALLBACK nicknames
396 for (const auto& nickname: gs->GetNicknames()) {
397 if (!G4StrUtil::contains(nickname, "FALLBACK")) {
398 candidates.insert(nickname);
399 }
400 }
401 }
403 ed << "Invoked command has failed - see above. Available graphics systems are (short names):\n ";
404 for (const auto& candidate: candidates) {
405 ed << ' ' << candidate;
406 };
407 command->CommandFailed(errorCode,ed);
408 }
409
410 UImanager->SetVerboseLevel(keepVerbose);
411}
412
414
416 G4bool omitable;
417 fpCommand = new G4UIcommand("/vis/specify", this);
419 ("Draws logical volume with Boolean components, voxels and readout geometry.");
421 ("Synonymous with \"/vis/drawLogicalVolume\".");
423 ("Creates a scene consisting of this logical volume and asks the"
424 "\n current viewer to draw it to the specified depth of descent"
425 "\n showing boolean components (if any), voxels (if any),"
426 "\n readout geometry (if any), local axes and overlaps (if any),"
427 "\n under control of the appropriate flag.");
429 ("Note: voxels are not constructed until start of run - /run/beamOn."
430 "\n (For voxels without a run, \"/run/beamOn 0\".)");
431 fpCommand->SetGuidance("The scene becomes current.");
432 G4UIparameter* parameter;
433 parameter = new G4UIparameter("logical-volume-name", 's', omitable = false);
434 fpCommand->SetParameter(parameter);
435 parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true);
436 parameter->SetDefaultValue(1);
437 fpCommand->SetParameter(parameter);
438 parameter = new G4UIparameter("booleans-flag", 'b', omitable = true);
439 parameter->SetDefaultValue(true);
440 fpCommand->SetParameter(parameter);
441 parameter = new G4UIparameter("voxels-flag", 'b', omitable = true);
442 parameter->SetDefaultValue(true);
443 fpCommand->SetParameter(parameter);
444 parameter = new G4UIparameter("readout-flag", 'b', omitable = true);
445 parameter->SetDefaultValue(true);
446 fpCommand->SetParameter(parameter);
447 parameter = new G4UIparameter("axes-flag", 'b', omitable = true);
448 parameter->SetDefaultValue(true);
449 parameter -> SetGuidance ("Set \"false\" to suppress axes.");
450 fpCommand->SetParameter(parameter);
451 parameter = new G4UIparameter("check-overlap-flag", 'b', omitable = true);
452 parameter->SetDefaultValue(true);
453 parameter -> SetGuidance ("Set \"false\" to suppress overlap check.");
454 fpCommand->SetParameter(parameter);
455}
456
458 delete fpCommand;
459}
460
464 G4int keepVerbose = UImanager->GetVerboseLevel();
465 G4int newVerbose(0);
466 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
467 newVerbose = 2;
468 UImanager->SetVerboseLevel(newVerbose);
469 // UImanager->ApplyCommand(G4String("/geometry/print " + newValue));
470 UImanager->ApplyCommand("/vis/scene/create");
471 UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
472 UImanager->ApplyCommand("/vis/sceneHandler/attach");
473 UImanager->SetVerboseLevel(keepVerbose);
474 static G4bool warned = false;
475 if (verbosity >= G4VisManager::confirmations && !warned) {
476 G4cout <<
477 "NOTE: For systems which are not \"auto-refresh\" you will need to"
478 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
479 << G4endl;
480 warned = true;
481 }
482}
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4UIcommand * FindPath(const char *commandPath) const
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:146
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:179
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:186
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:200
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:199
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)
const G4String & GetName() const
const G4ViewParameters & GetViewParameters() const
void SetViewParameters(const G4ViewParameters &vp)
Definition: G4VViewer.cc:120
static G4VisManager * fpVisManager
void CopyParametersFrom(const G4UIcommand *fromCmd, G4UIcommand *toCmd)
void CopyGuidanceFrom(const G4UIcommand *fromCmd, G4UIcommand *toCmd, G4int startLine=0)
static G4VVisManager * GetConcreteInstance()
void SetAutoRefresh(G4bool)
G4bool IsMarkerNotHidden() const
G4bool IsAutoRefresh() const
DrawingStyle GetDrawingStyle() const
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetCurrentGraphicsSystem(G4VGraphicsSystem *)
G4Scene * GetCurrentScene() const
void SetCurrentSceneHandler(G4VSceneHandler *)
void SetCurrentScene(G4Scene *)
void SetCurrentViewer(G4VViewer *)
G4VGraphicsSystem * GetCurrentGraphicsSystem() const
G4VViewer * GetCurrentViewer() const
G4VSceneHandler * GetCurrentSceneHandler() const
static Verbosity GetVerbosity()
void SetVerboseLevel(G4int)
G4bool contains(const G4String &str, std::string_view ss)
Check if a string contains a given substring.
#define errorCode
Definition: xmlparse.cc:618