Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4VisCommandsSceneHandler.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// $Id$
28
29// /vis/sceneHandler commands - John Allison 10th October 1998
30
32
33#include "G4VisManager.hh"
35#include "G4VisCommandsScene.hh"
36#include "G4UImanager.hh"
37#include "G4UIcommand.hh"
38#include "G4UIcmdWithAString.hh"
39#include "G4ios.hh"
40#include <sstream>
41
42////////////// /vis/sceneHandler/attach ///////////////////////////////////////
43
45 G4bool omitable, currentAsDefault;
46 fpCommand = new G4UIcmdWithAString ("/vis/sceneHandler/attach", this);
47 fpCommand -> SetGuidance ("Attaches scene to current scene handler.");
48 fpCommand -> SetGuidance
49 ("If scene-name is omitted, current scene is attached. To see scenes and"
50 "\nscene handlers, use \"/vis/scene/list\" and \"/vis/sceneHandler/list\"");
51 fpCommand -> SetParameterName ("scene-name",
52 omitable = true,
53 currentAsDefault = true);
54}
55
57 delete fpCommand;
58}
59
61 G4Scene* pScene = fpVisManager -> GetCurrentScene ();
62 return pScene ? pScene -> GetName () : G4String("");
63}
64
66 G4String newValue) {
67
69
70 G4String& sceneName = newValue;
71
72 if (sceneName.length () == 0) {
73 if (verbosity >= G4VisManager::warnings) {
74 G4cout <<
75 "WARNING: No scene specified. Maybe there are no scenes available"
76 "\n yet. Please create one." << G4endl;
77 }
78 return;
79 }
80
81 G4VSceneHandler* pSceneHandler = fpVisManager -> GetCurrentSceneHandler ();
82 if (!pSceneHandler) {
83 if (verbosity >= G4VisManager::errors) {
84 G4cout <<
85 "ERROR: Current scene handler not defined. Please select or create one."
86 << G4endl;
87 }
88 return;
89 }
90
91 G4SceneList& sceneList = fpVisManager -> SetSceneList ();
92
93 if (sceneList.empty ()) {
94 if (verbosity >= G4VisManager::errors) {
95 G4cout <<
96 "ERROR: No valid scenes available yet. Please create one."
97 << G4endl;
98 }
99 return;
100 }
101
102 G4int iScene, nScenes = sceneList.size ();
103 for (iScene = 0; iScene < nScenes; iScene++) {
104 if (sceneList [iScene] -> GetName () == sceneName) break;
105 }
106 if (iScene < nScenes) {
107 G4Scene* pScene = sceneList [iScene];
108 pSceneHandler -> SetScene (pScene);
109 // Make sure scene is current...
110 fpVisManager -> SetCurrentScene (pScene);
111 // Refresh viewer, if any (only if auto-refresh)...
112 G4VViewer* pViewer = pSceneHandler -> GetCurrentViewer();
113 if (pViewer && pViewer -> GetViewParameters().IsAutoRefresh()) {
114 pViewer -> SetView ();
115 pViewer -> ClearView ();
116 pViewer -> DrawView ();
117 }
118 if (verbosity >= G4VisManager::confirmations) {
119 G4cout << "Scene \"" << sceneName
120 << "\" attached to scene handler \""
121 << pSceneHandler -> GetName () <<
122 ".\n (You may have to refresh with \"/vis/viewer/flush\" if view"
123 " is not \"auto-refresh\".)"
124 << G4endl;
125 }
126 }
127 else {
128 if (verbosity >= G4VisManager::errors) {
129 G4cout << "ERROR: Scene \"" << sceneName
130 << "\" not found. Use \"/vis/scene/list\" to see possibilities."
131 << G4endl;
132 }
133 }
134}
135
136////////////// /vis/sceneHandler/create ///////////////////////////////////////
137
139 G4bool omitable;
140 fpCommand = new G4UIcommand ("/vis/sceneHandler/create", this);
141 fpCommand -> SetGuidance
142 ("Creates an scene handler for a specific graphics system.");
143 fpCommand -> SetGuidance
144 ("Attaches current scene, if any. (You can change attached scenes with"
145 "\n\"/vis/sceneHandler/attach\".) Invents a scene handler name if not"
146 "\nsupplied. This scene handler becomes current.");
147 G4UIparameter* parameter;
148 parameter = new G4UIparameter ("graphics-system-name",
149 's', omitable = false);
150 const G4GraphicsSystemList& gslist =
151 fpVisManager -> GetAvailableGraphicsSystems ();
152 G4String candidates;
153 for (size_t igslist = 0; igslist < gslist.size (); igslist++) {
154 const G4String& name = gslist [igslist] -> GetName ();
155 const G4String& nickname = gslist [igslist] -> GetNickname ();
156 if (nickname.isNull ()) {
157 candidates += name;
158 }
159 else {
160 candidates += nickname;
161 }
162 candidates += " ";
163 }
164 candidates = candidates.strip ();
165 parameter -> SetParameterCandidates(candidates);
166 fpCommand -> SetParameter (parameter);
167 parameter = new G4UIparameter
168 ("scene-handler-name", 's', omitable = true);
169 parameter -> SetCurrentAsDefault (true);
170 fpCommand -> SetParameter (parameter);
171}
172
174 delete fpCommand;
175}
176
177G4String G4VisCommandSceneHandlerCreate::NextName () {
178 std::ostringstream oss;
179 oss << "scene-handler-" << fId;
180 return oss.str();
181}
182
184
185 G4String graphicsSystemName;
186 const G4VGraphicsSystem* graphicsSystem =
187 fpVisManager -> GetCurrentGraphicsSystem ();
188 if (graphicsSystem) {
189 graphicsSystemName = graphicsSystem -> GetName ();
190 }
191 else {
192 const G4GraphicsSystemList& gslist =
193 fpVisManager -> GetAvailableGraphicsSystems ();
194 if (gslist.size ()) {
195 graphicsSystemName = gslist [0] -> GetName ();
196 }
197 else {
198 graphicsSystemName = "none";
199 }
200 }
201
202 return graphicsSystemName + " " + NextName ();
203}
204
206 G4String newValue) {
207
209
210 G4String graphicsSystem, newName;
211 std::istringstream is (newValue);
212 is >> graphicsSystem >> newName;
213
214 const G4GraphicsSystemList& gsl =
215 fpVisManager -> GetAvailableGraphicsSystems ();
216 int nSystems = gsl.size ();
217 if (nSystems <= 0) {
218 if (verbosity >= G4VisManager::errors) {
219 G4cout << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
220 " no graphics systems available."
221 "\n Did you instantiate any in"
222 " YourVisManager::RegisterGraphicsSystems()?"
223 << G4endl;
224 }
225 return;
226 }
227 int iGS; // Selector index.
228 for (iGS = 0; iGS < nSystems; iGS++) {
229 if (graphicsSystem.compareTo (gsl [iGS] -> GetName (),
230 G4String::ignoreCase) == 0 ||
231 graphicsSystem.compareTo (gsl [iGS] -> GetNickname (),
232 G4String::ignoreCase) == 0) {
233 break; // Match found.
234 }
235 }
236 if (iGS < 0 || iGS >= nSystems) {
237 // Invalid command line argument or non.
238 // This shouldn't happen!!!!!!
239 if (verbosity >= G4VisManager::errors) {
240 G4cout << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
241 " invalid graphics system specified."
242 << G4endl;
243 }
244 return;
245 }
246
247 // Check UI session compatibility.
248 if (!gsl[iGS]->IsUISessionCompatible()) {
249 G4String fallbackNickname = gsl[iGS]->GetNickname() + "_FALLBACK";
250 for (iGS = 0; iGS < nSystems; iGS++) {
251 if (fallbackNickname.compareTo (gsl [iGS] -> GetNickname (),
252 G4String::ignoreCase) == 0) {
253 break; // Match found.
254 }
255 }
256 if (iGS < 0 || iGS >= nSystems) {
257 if (verbosity >= G4VisManager::errors) {
258 G4cout << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
259 " could not find fallback graphics system."
260 << G4endl;
261 }
262 return;
263 }
264 if (verbosity >= G4VisManager::warnings) {
265 G4cout << "WARNING: G4VisCommandSceneHandlerCreate::SetNewValue:"
266 " using fallback graphics system."
267 << G4endl;
268 }
269 }
270
271 // Set current graphics system in preparation for
272 // creating scene handler.
273 G4VGraphicsSystem* pSystem = gsl [iGS];
274 fpVisManager -> SetCurrentGraphicsSystem (pSystem);
275 if (verbosity >= G4VisManager::confirmations) {
276 G4cout << "Graphics system set to " << pSystem -> GetName () << G4endl;
277 }
278
279 // Now deal with name of scene handler.
280 G4String nextName = NextName ();
281 if (newName == "") {
282 newName = nextName;
283 }
284 if (newName == nextName) fId++;
285
286 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers ();
287 size_t iScene;
288 for (iScene = 0; iScene < list.size (); iScene++) {
289 G4VSceneHandler* sceneHandler = list [iScene];
290 if (sceneHandler -> GetName () == newName) {
291 if (verbosity >= G4VisManager::errors) {
292 G4cout << "ERROR: Scene handler \"" << newName
293 << "\" already exists." << G4endl;
294 }
295 return;
296 }
297 }
298
299 //Create scene handler.
300 fpVisManager -> CreateSceneHandler (newName);
301 if (fpVisManager -> GetCurrentSceneHandler () -> GetName () != newName) {
302 if (verbosity >= G4VisManager::errors) {
303 G4cout << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
304 " Curious name mismatch."
305 "\n Current name \""
306 << fpVisManager -> GetCurrentSceneHandler () -> GetName ()
307 << "\" is not the new name \""
308 << newName
309 << "\".\n Please report to vis coordinator."
310 << G4endl;
311 }
312 return;
313 }
314
315 if (verbosity >= G4VisManager::confirmations) {
316 G4cout << "New scene handler \"" << newName << "\" created." << G4endl;
317 }
318
319 // Attach scene.
320 if (fpVisManager -> GetCurrentScene ())
321 G4UImanager::GetUIpointer () -> ApplyCommand ("/vis/sceneHandler/attach");
322}
323
324////////////// /vis/sceneHandler/list ///////////////////////////////////////
325
327 G4bool omitable;
328 fpCommand = new G4UIcommand ("/vis/sceneHandler/list", this);
329 fpCommand -> SetGuidance ("Lists scene handler(s).");
330 fpCommand -> SetGuidance
331 ("\"help /vis/verbose\" for definition of verbosity.");
332 G4UIparameter* parameter;
333 parameter = new G4UIparameter("scene-handler-name", 's', omitable = true);
334 parameter -> SetDefaultValue ("all");
335 fpCommand -> SetParameter (parameter);
336 parameter = new G4UIparameter ("verbosity", 's', omitable = true);
337 parameter -> SetDefaultValue ("warnings");
338 fpCommand -> SetParameter (parameter);
339}
340
342 delete fpCommand;
343}
344
346 return "";
347}
348
350 G4String newValue) {
351 G4String name, verbosityString;
352 std::istringstream is (newValue);
353 is >> name >> verbosityString;
354 G4VisManager::Verbosity verbosity =
355 fpVisManager->GetVerbosityValue(verbosityString);
356 const G4VSceneHandler* currentSceneHandler =
357 fpVisManager -> GetCurrentSceneHandler ();
358 G4String currentName;
359 if (currentSceneHandler) currentName = currentSceneHandler->GetName();
360
361 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers ();
362 G4bool found = false;
363 for (size_t iSH = 0; iSH < list.size (); iSH++) {
364 const G4String& iName = list [iSH] -> GetName ();
365 if (name != "all") {
366 if (name != iName) continue;
367 }
368 found = true;
369 if (iName == currentName) {
370 G4cout << " (current)";
371 }
372 else {
373 G4cout << " ";
374 }
375 G4cout << " scene handler \"" << list [iSH] -> GetName () << "\""
376 << " (" << list [iSH] -> GetGraphicsSystem () -> GetName () << ")";
377 if (verbosity >= G4VisManager::parameters) {
378 G4cout << "\n " << *(list [iSH]);
379 }
380 G4cout << G4endl;
381 }
382 if (!found) {
383 G4cout << "No scene handlers found";
384 if (name != "all") {
385 G4cout << " of name \"" << name << "\"";
386 }
387 G4cout << "." << G4endl;
388 }
389}
390
391////////////// /vis/sceneHandler/select ///////////////////////////////////////
392
394 G4bool omitable;
395 fpCommand = new G4UIcmdWithAString ("/vis/sceneHandler/select", this);
396 fpCommand -> SetGuidance ("Selects a scene handler.");
397 fpCommand -> SetGuidance
398 ("Makes the scene handler current. \"/vis/sceneHandler/list\" to see"
399 "\n possible scene handler names.");
400 fpCommand -> SetParameterName ("scene-handler-name",
401 omitable = false);
402}
403
405 delete fpCommand;
406}
407
409 return "";
410}
411
413 G4String newValue) {
414
416
417 G4String& selectName = newValue;
418 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers ();
419
420 size_t iSH;
421 for (iSH = 0; iSH < list.size (); iSH++) {
422 if (list [iSH] -> GetName () == selectName) break;
423 }
424 if (iSH < list.size ()) {
425 if (fpVisManager -> GetCurrentSceneHandler () -> GetName ()
426 == selectName) {
427 if (verbosity >= G4VisManager::confirmations) {
428 G4cout << "Scene handler \"" << selectName << "\""
429 << " already selected." << G4endl;
430 }
431 }
432 else {
433 if (verbosity >= G4VisManager::confirmations) {
434 G4cout << "Scene handler \"" << selectName << "\""
435 << " being selected." << G4endl;
436 }
437 fpVisManager -> SetCurrentSceneHandler (list [iSH]);
438 }
439 }
440 else {
441 if (verbosity >= G4VisManager::errors) {
442 G4cout << "ERROR: Scene handler \"" << selectName << "\""
443 << " not found - \"/vis/sceneHandler/list\""
444 "\n to see possibilities."
445 << G4endl;
446 }
447 }
448}
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
@ ignoreCase
Definition: G4String.hh:111
G4bool isNull() const
G4String strip(G4int strip_Type=trailing, char c=' ')
G4int compareTo(const char *, caseCompare mode=exact) const
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:51
const G4String & GetName() const
static G4VisManager * fpVisManager
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
static Verbosity GetVerbosity()
static Verbosity GetVerbosityValue(const G4String &)