Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
40#define G4warn G4cout
41
42////////////// /vis/drawTree ///////////////////////////////////////
43
45 G4bool omitable;
46 fpCommand = new G4UIcommand("/vis/drawTree", this);
47 fpCommand->SetGuidance
48 ("Produces a representation of the geometry hierarchy. Further"
49 "\nguidance is given on running the command. Or look at the guidance"
50 "\nfor \"/vis/ASCIITree/verbose\".");
51 fpCommand->SetGuidance("The pre-existing scene and view are preserved.");
52 G4UIparameter* parameter;
53 parameter = new G4UIparameter("physical-volume-name", 's', omitable = true);
54 parameter -> SetDefaultValue("world");
55 fpCommand -> SetParameter (parameter);
56 parameter = new G4UIparameter("system", 's', omitable = true);
57 parameter -> SetDefaultValue("ATree");
58 fpCommand -> SetParameter (parameter);
59}
60
62 delete fpCommand;
63}
64
66
67 G4String pvname, system;
68 std::istringstream is(newValue);
69 is >> pvname >> system;
70
71 // Note: The second parameter, "system", is intended to allow the user
72 // a choice of dedicated tree printing/displaying systems but at present
73 // the only such dedicated system is ASCIITree. It doesn't make sense to
74 // specify OGLSX, for example. So to avoid confusion we restrict this
75 // feature to systems that have "Tree" in the name or nickname.
76
77 // Of course, some other systems, such as OGLSQt, have a tree browser
78 // built-in. The HepRApp offline browser also has a tree browser
79 // built in.
80
81 if (!G4StrUtil::contains(system, "Tree")) {
82 system = "ATree";
83 }
84
86 G4Scene* keepScene = fpVisManager->GetCurrentScene();
90 G4bool keepAbleness = fpVisManager->GetConcreteInstance()? true: false;
91
93 G4int keepUIVerbose = UImanager->GetVerboseLevel();
94 G4int newVerbose(0);
95 if (keepUIVerbose >= 2 ||
97 newVerbose = 2;
98 UImanager->SetVerboseLevel(newVerbose);
99
100 auto errorCode = UImanager->ApplyCommand(G4String("/vis/open " + system));
101 if (errorCode == 0) {
102 if (!keepAbleness) { // Enable temporarily
104 UImanager->ApplyCommand("/vis/enable");
105 fpVisManager->SetVerboseLevel(keepVisVerbosity);
106 }
107 UImanager->ApplyCommand("/vis/viewer/reset");
108 UImanager->ApplyCommand(G4String("/vis/drawVolume " + pvname));
109 UImanager->ApplyCommand("/vis/viewer/flush");
110 if (!keepAbleness) { // Disable again
112 UImanager->ApplyCommand("/vis/disable");
113 fpVisManager->SetVerboseLevel(keepVisVerbosity);
114 }
115 if (keepViewer) {
117 G4warn << "Reverting to " << keepViewer->GetName() << G4endl;
118 }
120 fpVisManager->SetCurrentScene(keepScene);
121 fpVisManager->SetCurrentSceneHandler(keepSceneHandler);
122 fpVisManager->SetCurrentViewer(keepViewer);
123 }
124 }
125 UImanager->SetVerboseLevel(keepUIVerbose);
126}
127
128////////////// /vis/drawView ///////////////////////////////////////
129
131 G4bool omitable;
132 fpCommand = new G4UIcommand("/vis/drawView", this);
133 fpCommand->SetGuidance
134 ("Draw view from this angle, etc.");
135 G4UIparameter* parameter;
136 parameter = new G4UIparameter("theta-degrees", 'd', omitable = true);
137 parameter -> SetDefaultValue(0.);
138 fpCommand -> SetParameter (parameter);
139 parameter = new G4UIparameter("phi-degrees", 'd', omitable = true);
140 parameter -> SetDefaultValue(0.);
141 fpCommand -> SetParameter (parameter);
142 parameter = new G4UIparameter("pan-right", 'd', omitable = true);
143 parameter -> SetDefaultValue(0.);
144 fpCommand -> SetParameter (parameter);
145 parameter = new G4UIparameter("pan-up", 'd', omitable = true);
146 parameter -> SetDefaultValue(0.);
147 fpCommand -> SetParameter (parameter);
148 parameter = new G4UIparameter("pan-unit", 's', omitable = true);
149 parameter -> SetDefaultValue("cm");
150 fpCommand -> SetParameter (parameter);
151 parameter = new G4UIparameter("zoom-factor", 'd', omitable = true);
152 parameter -> SetDefaultValue(1.);
153 fpCommand -> SetParameter (parameter);
154 parameter = new G4UIparameter("dolly", 'd', omitable = true);
155 parameter -> SetDefaultValue(0.);
156 fpCommand -> SetParameter (parameter);
157 parameter = new G4UIparameter("dolly-unit", 's', omitable = true);
158 parameter -> SetDefaultValue("cm");
159 fpCommand -> SetParameter (parameter);
160}
161
163 delete fpCommand;
164}
165
167
169
170 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
171 if (!currentViewer) {
172 if (verbosity >= G4VisManager::warnings) {
173 G4warn <<
174 "WARNING: G4VisCommandsDrawView::SetNewValue: no current viewer."
175 << G4endl;
176 }
177 return;
178 }
179
180 G4String thetaDeg;
181 G4String phiDeg;
182 G4String panRight;
183 G4String panUp;
184 G4String panUnit;
185 G4String zoomFactor;
186 G4String dolly;
187 G4String dollyUnit;
188 std::istringstream is(newValue);
189 is >> thetaDeg >> phiDeg >> panRight >> panUp >> panUnit
190 >> zoomFactor >> dolly >> dollyUnit;
191
193 G4ViewParameters vp = currentViewer->GetViewParameters();
194 G4bool keepAutoRefresh = vp.IsAutoRefresh();
195 vp.SetAutoRefresh(false);
196 currentViewer->SetViewParameters(vp);
197 UImanager->ApplyCommand(
198 G4String("/vis/viewer/set/viewpointThetaPhi " + thetaDeg + " " + phiDeg + " deg"));
199 UImanager->ApplyCommand(
200 G4String("/vis/viewer/panTo " + panRight + " " + panUp + " " + panUnit));
201 UImanager->ApplyCommand(
202 G4String("/vis/viewer/zoomTo " + zoomFactor));
203 vp = currentViewer->GetViewParameters();
204 vp.SetAutoRefresh(keepAutoRefresh);
205 currentViewer->SetViewParameters(vp);
206 UImanager->ApplyCommand(
207 G4String("/vis/viewer/dollyTo " + dolly + " " + dollyUnit));
208}
209
210////////////// /vis/drawLogicalVolume ///////////////////////////////////////
211
213 fpCommand = new G4UIcommand("/vis/drawLogicalVolume", this);
214 fpCommand->SetGuidance
215 ("Draws logical volume with additional components.");
216 fpCommand->SetGuidance
217 ("Synonymous with \"/vis/specify\".");
218 fpCommand->SetGuidance
219 ("Creates a scene consisting of this logical volume and asks the"
220 "\n current viewer to draw it. The scene becomes current.");
222 const G4UIcommand* addLogVolCmd = tree->FindPath("/vis/scene/add/logicalVolume");
223 // Pick up guidance from /vis/scene/add/logicalVolume
224 CopyGuidanceFrom(addLogVolCmd,fpCommand);
225 // Pick up parameters from /vis/scene/add/logicalVolume
226 CopyParametersFrom(addLogVolCmd,fpCommand);
227}
228
230 delete fpCommand;
231}
232
236 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
237 const G4ViewParameters& currentViewParams = currentViewer->GetViewParameters();
238 G4bool keepAutoRefresh = currentViewParams.IsAutoRefresh();
239 if (keepAutoRefresh) UImanager->ApplyCommand("/vis/viewer/set/autoRefresh false");
240 UImanager->ApplyCommand("/vis/scene/create");
241 UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
242 UImanager->ApplyCommand("/vis/sceneHandler/attach");
243 G4ViewParameters::DrawingStyle keepDrawingStyle = currentViewParams.GetDrawingStyle();
244 if(keepDrawingStyle != G4ViewParameters::wireframe)
245 UImanager->ApplyCommand("/vis/viewer/set/style wireframe");
246 G4bool keepMarkerNotHidden = currentViewParams.IsMarkerNotHidden();
247 if (!keepMarkerNotHidden) UImanager->ApplyCommand("/vis/viewer/set/hiddenMarker false");
248 if (keepAutoRefresh) UImanager->ApplyCommand("/vis/viewer/set/autoRefresh true");
249 if (verbosity >= G4VisManager::warnings) {
250 if (keepDrawingStyle != currentViewParams.GetDrawingStyle()) {
251 G4warn
252 << "Drawing style changed to wireframe. To restore previous style:";
253 G4String style, edge;
254 switch (keepDrawingStyle) {
256 style = "wireframe"; edge = "false"; break;
258 style = "wireframe"; edge = "true"; break;
260 style = "surface"; edge = "false"; break;
262 style = "surface"; edge = "true"; break;
264 style = "cloud"; edge = ""; break;
265 }
266 G4warn << "\n /vis/viewer/set/style " + style;
267 if (!edge.empty()) G4warn << "\n /vis/viewer/set/hiddenEdge " + edge;
268 G4warn << G4endl;
269 }
270 if (keepMarkerNotHidden != currentViewParams.IsMarkerNotHidden()) {
271 G4warn
272 << "Markers changed to \"not hidden\". To restore previous condition:"
273 << "\n /vis/viewer/set/hiddenmarker true"
274 << G4endl;
275 }
276 }
277 static G4bool warned = false;
278 if (verbosity >= G4VisManager::confirmations && !warned) {
279 G4cout <<
280 "NOTE: For systems which are not \"auto-refresh\" you will need to"
281 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
282 << G4endl;
283 warned = true;
284 }
285}
286
287////////////// /vis/drawVolume ///////////////////////////////////////
288
290 fpCommand = new G4UIcommand("/vis/drawVolume", this);
291 fpCommand->SetGuidance
292 ("Creates a scene containing this physical volume and asks the"
293 "\ncurrent viewer to draw it. The scene becomes current.");
295 const G4UIcommand* addVolCmd = tree->FindPath("/vis/scene/add/volume");
296 // Pick up guidance from /vis/scene/add/volume
297 CopyGuidanceFrom(addVolCmd,fpCommand);
298 // Pick up parameters from /vis/scene/add/volume
299 CopyParametersFrom(addVolCmd,fpCommand);
300}
301
303 delete fpCommand;
304}
305
309 UImanager->ApplyCommand("/vis/scene/create");
310 UImanager->ApplyCommand(G4String("/vis/scene/add/volume " + newValue));
311 UImanager->ApplyCommand("/vis/sceneHandler/attach");
312 static G4bool warned = false;
313 if (verbosity >= G4VisManager::confirmations && !warned) {
314 G4cout <<
315 "NOTE: For systems which are not \"auto-refresh\" you will need to"
316 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
317 << G4endl;
318 warned = true;
319 }
320}
321
322////////////// /vis/open ///////////////////////////////////////
323
325 G4bool omitable;
326 fpCommand = new G4UIcommand("/vis/open", this);
327 fpCommand->SetGuidance
328 ("Creates a scene handler and viewer ready for drawing.");
329 fpCommand->SetGuidance
330 ("The scene handler and viewer names are auto-generated.");
331 // Pick up guidance from /vis/viewer/create
333 const G4UIcommand* viewerCreateCmd = tree->FindPath("/vis/viewer/create");
334 CopyGuidanceFrom(viewerCreateCmd,fpCommand,2);
335 G4UIparameter* parameter;
336 parameter = new G4UIparameter("graphics-system-name", 's', omitable = true);
337 parameter->SetCurrentAsDefault(true);
338 fpCommand->SetParameter(parameter);
339 parameter = new G4UIparameter("window-size-hint", 's', omitable = true);
340 parameter->SetGuidance
341 ("integer (pixels) for square window placed by window manager or"
342 " X-Windows-type geometry string, e.g. 600x600-100+100");
343 parameter->SetDefaultValue("none");
344 fpCommand->SetParameter(parameter);
345}
346
348 delete fpCommand;
349}
350
352{
353 G4String graphicsSystemName;
354 auto graphicsSystem = fpVisManager->GetCurrentGraphicsSystem();
355 if (graphicsSystem) {
356 graphicsSystemName = graphicsSystem->GetName ();
357 }
358 else {
359 graphicsSystemName = "none";
360 }
361 return graphicsSystemName;
362}
363
365{
366 G4String systemName, windowSizeHint;
367 std::istringstream is(newValue);
368 is >> systemName >> windowSizeHint;
370
371 auto errorCode = UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
372 if (errorCode) {
374 ed << "sub-command \"/vis/sceneHandler/create\" failed.";
375 command->CommandFailed(errorCode,ed);
376 goto finish;
377 }
378 errorCode = UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
379 if (errorCode) {
381 ed << "sub-command \"/vis/viewer/create\" failed.";
382 command->CommandFailed(errorCode,ed);
383 goto finish;
384 }
385
386finish:
387 if (errorCode) {
389 ed << "Invoked command has failed - see above. Available graphics systems are:\n ";
391 command->CommandFailed(errorCode,ed);
392 }
393}
394
395////////////// /vis/plot ///////////////////////////////////////
396
398{
399 G4bool omitable;
400 G4UIparameter* parameter;
401
402 fpCommand = new G4UIcommand("/vis/plot", this);
403 fpCommand -> SetGuidance("Draws plots.");
404 parameter = new G4UIparameter ("type", 's', omitable = false);
405 parameter -> SetParameterCandidates("h1 h2");
406 fpCommand -> SetParameter (parameter);
407 parameter = new G4UIparameter ("id", 'i', omitable = false);
408 fpCommand -> SetParameter (parameter);
409}
410
412{
413 delete fpCommand;
414}
415
417{
418 return "";
419}
420
422{
423 auto currentViewer = fpVisManager->GetCurrentViewer();
424 if (currentViewer->GetName().find("TOOLSSG") == std::string::npos) {
425 G4warn <<
426 "WARNING: Current viewer not able to draw plots."
427 "\n Try \"/vis/open TSG\", then \"/vis/plot " << newValue << "\" again."
428 << G4endl;
429 return;
430 }
431
432 G4String type, id;
433 std::istringstream is (newValue);
434 is >> type >> id;
435
436 auto keepEnable = fpVisManager->IsEnabled();
437
438 auto ui = G4UImanager::GetUIpointer();
439 ui->ApplyCommand("/vis/enable");
440 ui->ApplyCommand("/vis/viewer/resetCameraParameters");
441 ui->ApplyCommand("/vis/scene/create");
442 ui->ApplyCommand("/vis/scene/endOfEventAction accumulate 0"); // Don't keep events
443 static G4int plotterID = 0;
444 std::ostringstream ossPlotter;
445 ossPlotter << "plotter-" << plotterID++;
446 const G4String& plotterName = ossPlotter.str();
447 ui->ApplyCommand("/vis/plotter/create " + plotterName);
448 ui->ApplyCommand("/vis/scene/add/plotter " + plotterName);
449 ui->ApplyCommand("/vis/plotter/add/" + type + ' ' + id + ' ' + plotterName);
450 ui->ApplyCommand("/vis/sceneHandler/attach");
451
452 if (!keepEnable) {
454 G4warn <<
455 "WARNING: drawing was enabled for plotting but is now restored to disabled mode."
456 << G4endl;
457 }
458}
459
460////////////// /vis/specify ///////////////////////////////////////
461
463 G4bool omitable;
464 fpCommand = new G4UIcommand("/vis/specify", this);
465 fpCommand->SetGuidance
466 ("Draws logical volume with Boolean components, voxels and readout geometry.");
467 fpCommand->SetGuidance
468 ("Synonymous with \"/vis/drawLogicalVolume\".");
469 fpCommand->SetGuidance
470 ("Creates a scene consisting of this logical volume and asks the"
471 "\n current viewer to draw it to the specified depth of descent"
472 "\n showing boolean components (if any), voxels (if any),"
473 "\n readout geometry (if any), local axes and overlaps (if any),"
474 "\n under control of the appropriate flag.");
475 fpCommand->SetGuidance
476 ("Note: voxels are not constructed until start of run - /run/beamOn."
477 "\n (For voxels without a run, \"/run/beamOn 0\".)");
478 fpCommand->SetGuidance("The scene becomes current.");
479 G4UIparameter* parameter;
480 parameter = new G4UIparameter("logical-volume-name", 's', omitable = false);
481 fpCommand->SetParameter(parameter);
482 parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true);
483 parameter->SetDefaultValue(1);
484 fpCommand->SetParameter(parameter);
485 parameter = new G4UIparameter("booleans-flag", 'b', omitable = true);
486 parameter->SetDefaultValue(true);
487 fpCommand->SetParameter(parameter);
488 parameter = new G4UIparameter("voxels-flag", 'b', omitable = true);
489 parameter->SetDefaultValue(true);
490 fpCommand->SetParameter(parameter);
491 parameter = new G4UIparameter("readout-flag", 'b', omitable = true);
492 parameter->SetDefaultValue(true);
493 fpCommand->SetParameter(parameter);
494 parameter = new G4UIparameter("axes-flag", 'b', omitable = true);
495 parameter->SetDefaultValue(true);
496 parameter -> SetGuidance ("Set \"false\" to suppress axes.");
497 fpCommand->SetParameter(parameter);
498 parameter = new G4UIparameter("check-overlap-flag", 'b', omitable = true);
499 parameter->SetDefaultValue(true);
500 parameter -> SetGuidance ("Set \"false\" to suppress overlap check.");
501 fpCommand->SetParameter(parameter);
502}
503
505 delete fpCommand;
506}
507
511 // UImanager->ApplyCommand(G4String("/geometry/print " + newValue));
512 UImanager->ApplyCommand("/vis/scene/create");
513 UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
514 UImanager->ApplyCommand("/vis/sceneHandler/attach");
515 static G4bool warned = false;
516 if (verbosity >= G4VisManager::confirmations && !warned) {
517 G4cout <<
518 "NOTE: For systems which are not \"auto-refresh\" you will need to"
519 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
520 << G4endl;
521 warned = true;
522 }
523}
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
#define G4warn
Definition: G4Scene.cc:41
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:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:157
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:495
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)
void SetCurrentAsDefault(G4bool val)
const G4String & GetName() const
const G4ViewParameters & GetViewParameters() const
void SetViewParameters(const G4ViewParameters &vp)
Definition: G4VViewer.cc:126
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)
G4String GetCurrentValue(G4UIcommand *)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetCurrentGraphicsSystem(G4VGraphicsSystem *)
G4Scene * GetCurrentScene() const
void PrintAvailableGraphicsSystems(Verbosity, std::ostream &=G4cout) const
G4bool IsEnabled() 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.