Geant4 10.7.0
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////////////// /vis/drawTree ///////////////////////////////////////
41
43 G4bool omitable;
44 fpCommand = new G4UIcommand("/vis/drawTree", this);
45 fpCommand->SetGuidance
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 (!system.contains("Tree")) {
80 system = "ATree";
81 }
82
84 G4Scene* keepScene = fpVisManager->GetCurrentScene();
88
90 G4int keepUIVerbose = UImanager->GetVerboseLevel();
91 G4int newVerbose(0);
92 if (keepUIVerbose >= 2 ||
94 newVerbose = 2;
95 UImanager->SetVerboseLevel(newVerbose);
96
97 G4bool keepAbleness = fpVisManager->GetConcreteInstance()? true: false;
98
99 auto errorCode = UImanager->ApplyCommand(G4String("/vis/open " + system));
100 if (errorCode == 0) {
101 if (!keepAbleness) { // Enable temporarily
103 UImanager->ApplyCommand("/vis/enable");
104 fpVisManager->SetVerboseLevel(keepVisVerbosity);
105 }
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
126////////////// /vis/drawView ///////////////////////////////////////
127
129 G4bool omitable;
130 fpCommand = new G4UIcommand("/vis/drawView", this);
131 fpCommand->SetGuidance
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
215////////////// /vis/drawLogicalVolume ///////////////////////////////////////
216
218 fpCommand = new G4UIcommand("/vis/drawLogicalVolume", this);
219 fpCommand->SetGuidance
220 ("Draws logical volume with additional components.");
221 fpCommand->SetGuidance
222 ("Synonymous with \"/vis/specify\".");
223 fpCommand->SetGuidance
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
298////////////// /vis/drawVolume ///////////////////////////////////////
299
301 fpCommand = new G4UIcommand("/vis/drawVolume", this);
302 fpCommand->SetGuidance
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
339////////////// /vis/open ///////////////////////////////////////
340
342 G4bool omitable;
343 fpCommand = new G4UIcommand("/vis/open", this);
344 fpCommand->SetGuidance
345 ("Creates a scene handler ready for drawing.");
346 fpCommand->SetGuidance
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 G4String systemName, windowSizeHint;
365 std::istringstream is(newValue);
366 is >> systemName >> windowSizeHint;
368 G4int keepVerbose = UImanager->GetVerboseLevel();
369 G4int newVerbose(0);
370 if (keepVerbose >= 2 ||
372 newVerbose = 2;
373 UImanager->SetVerboseLevel(newVerbose);
374 auto errorCode = UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
375 if (errorCode == 0) {
376 UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
377 } else {
378 // Use set to get alphabetical order
379 std::set<G4String> candidates;
380 for (const auto gs: fpVisManager -> GetAvailableGraphicsSystems()) {
381 // Just list nicknames, but exclude FALLBACK nicknames
382 for (const auto& nickname: gs->GetNicknames()) {
383 if (!nickname.contains("FALLBACK")) {
384 candidates.insert(nickname);
385 }
386 }
387 }
388 std::ostringstream oss;
389 oss << "Candidates are:";
390 for (const auto& candidate: candidates) {
391 oss << ' ' << candidate;
392 };
393 G4cerr << oss.str() << G4endl;
394 command->CommandFailed(oss);
395 }
396 UImanager->SetVerboseLevel(keepVerbose);
397}
398
399////////////// /vis/specify ///////////////////////////////////////
400
402 G4bool omitable;
403 fpCommand = new G4UIcommand("/vis/specify", this);
404 fpCommand->SetGuidance
405 ("Draws logical volume with Boolean components, voxels and readout geometry.");
406 fpCommand->SetGuidance
407 ("Synonymous with \"/vis/drawLogicalVolume\".");
408 fpCommand->SetGuidance
409 ("Creates a scene consisting of this logical volume and asks the"
410 "\n current viewer to draw it to the specified depth of descent"
411 "\n showing boolean components (if any), voxels (if any),"
412 "\n readout geometry (if any), local axes and overlaps (if any),"
413 "\n under control of the appropriate flag.");
414 fpCommand->SetGuidance
415 ("Note: voxels are not constructed until start of run - /run/beamOn."
416 "\n (For voxels without a run, \"/run/beamOn 0\".)");
417 fpCommand->SetGuidance("The scene becomes current.");
418 G4UIparameter* parameter;
419 parameter = new G4UIparameter("logical-volume-name", 's', omitable = false);
420 fpCommand->SetParameter(parameter);
421 parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true);
422 parameter->SetDefaultValue(1);
423 fpCommand->SetParameter(parameter);
424 parameter = new G4UIparameter("booleans-flag", 'b', omitable = true);
425 parameter->SetDefaultValue(true);
426 fpCommand->SetParameter(parameter);
427 parameter = new G4UIparameter("voxels-flag", 'b', omitable = true);
428 parameter->SetDefaultValue(true);
429 fpCommand->SetParameter(parameter);
430 parameter = new G4UIparameter("readout-flag", 'b', omitable = true);
431 parameter->SetDefaultValue(true);
432 fpCommand->SetParameter(parameter);
433 parameter = new G4UIparameter("axes-flag", 'b', omitable = true);
434 parameter->SetDefaultValue(true);
435 parameter -> SetGuidance ("Set \"false\" to suppress axes.");
436 fpCommand->SetParameter(parameter);
437 parameter = new G4UIparameter("check-overlap-flag", 'b', omitable = true);
438 parameter->SetDefaultValue(true);
439 parameter -> SetGuidance ("Set \"false\" to suppress overlap check.");
440 fpCommand->SetParameter(parameter);
441}
442
444 delete fpCommand;
445}
446
450 G4int keepVerbose = UImanager->GetVerboseLevel();
451 G4int newVerbose(0);
452 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
453 newVerbose = 2;
454 UImanager->SetVerboseLevel(newVerbose);
455 // UImanager->ApplyCommand(G4String("/geometry/print " + newValue));
456 UImanager->ApplyCommand("/vis/scene/create");
457 UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
458 UImanager->ApplyCommand("/vis/sceneHandler/attach");
459 UImanager->SetVerboseLevel(keepVerbose);
460 static G4bool warned = false;
461 if (verbosity >= G4VisManager::confirmations && !warned) {
462 G4cout <<
463 "NOTE: For systems which are not \"auto-refresh\" you will need to"
464 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
465 << G4endl;
466 warned = true;
467 }
468}
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4bool contains(const std::string &) const
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:179
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:193
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:192
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:119
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)
#define errorCode
Definition: xmlparse.cc:618