source: trunk/source/visualization/management/src/G4VisCommandsSceneHandler.cc@ 1124

Last change on this file since 1124 was 1041, checked in by garnier, 17 years ago

en test

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