source: trunk/source/visualization/management/src/G4VisCommandsViewer.cc @ 891

Last change on this file since 891 was 891, checked in by garnier, 15 years ago

pre-tag revision and some improvments

  • Property svn:mime-type set to text/cpp
File size: 53.9 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: G4VisCommandsViewer.cc,v 1.70 2008/04/30 10:07:28 allison Exp $
28// GEANT4 tag $Name: HEAD $
29
30// /vis/viewer commands - John Allison  25th October 1998
31
32#include "G4VisCommandsViewer.hh"
33
34#include "G4VisManager.hh"
35#include "G4GraphicsSystemList.hh"
36#include "G4VisCommandsScene.hh"
37#include "G4UImanager.hh"
38#include "G4UIcommand.hh"
39#include "G4UIcmdWithoutParameter.hh"
40#include "G4UIcmdWithAString.hh"
41#include "G4UIcmdWithADouble.hh"
42#include "G4UIcmdWithADoubleAndUnit.hh"
43#include "G4UIcmdWith3Vector.hh"
44#include "G4UnitsTable.hh"
45#include "G4ios.hh"
46#include <sstream>
47
48G4VVisCommandViewer::G4VVisCommandViewer () {}
49
50G4VVisCommandViewer::~G4VVisCommandViewer () {}
51
52void G4VVisCommandViewer::SetViewParameters
53(G4VViewer* viewer, const G4ViewParameters& viewParams) {
54  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
55  viewer->SetViewParameters(viewParams);
56  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
57  if (sceneHandler && sceneHandler->GetScene()) {
58    if (viewParams.IsAutoRefresh()) {
59      G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
60    }
61    else {
62      if (verbosity >= G4VisManager::confirmations) {
63        G4cout << "Issue /vis/viewer/refresh to see effect." << G4endl;
64      }
65    }
66  }
67}
68
69////////////// /vis/viewer/addCutawayPlane ///////////////////////////////////////
70
71G4VisCommandViewerAddCutawayPlane::G4VisCommandViewerAddCutawayPlane () {
72  G4bool omitable;
73  fpCommand = new G4UIcommand ("/vis/viewer/addCutawayPlane", this);
74  fpCommand -> SetGuidance
75    ("Add cutaway plane to current viewer.");
76  G4UIparameter* parameter;
77  parameter  =  new G4UIparameter("x",'d',omitable = true);
78  parameter  -> SetDefaultValue  (0);
79  parameter  -> SetGuidance      ("Coordinate of point on the plane.");
80  fpCommand->SetParameter(parameter);
81  parameter  =  new G4UIparameter("y",'d',omitable = true);
82  parameter  -> SetDefaultValue  (0);
83  parameter  -> SetGuidance      ("Coordinate of point on the plane.");
84  fpCommand->SetParameter(parameter);
85  parameter  =  new G4UIparameter("z",'d',omitable = true);
86  parameter  -> SetDefaultValue  (0);
87  parameter  -> SetGuidance      ("Coordinate of point on the plane.");
88  fpCommand->SetParameter(parameter);
89  parameter  =  new G4UIparameter("unit",'s',omitable = true);
90  parameter  -> SetDefaultValue  ("m");
91  parameter  -> SetGuidance      ("Unit of point on the plane.");
92  fpCommand->SetParameter(parameter);
93  parameter  =  new G4UIparameter("nx",'d',omitable = true);
94  parameter  -> SetDefaultValue  (1);
95  parameter  -> SetGuidance      ("Component of plane normal.");
96  fpCommand->SetParameter(parameter);
97  parameter  =  new G4UIparameter("ny",'d',omitable = true);
98  parameter  -> SetDefaultValue  (0);
99  parameter  -> SetGuidance      ("Component of plane normal.");
100  fpCommand->SetParameter(parameter);
101  parameter  =  new G4UIparameter("nz",'d',omitable = true);
102  parameter  -> SetDefaultValue  (0);
103  parameter  -> SetGuidance      ("Component of plane normal.");
104  fpCommand->SetParameter(parameter);
105}
106
107G4VisCommandViewerAddCutawayPlane::~G4VisCommandViewerAddCutawayPlane () {
108  delete fpCommand;
109}
110
111G4String G4VisCommandViewerAddCutawayPlane::GetCurrentValue (G4UIcommand*) {
112  return "";
113}
114
115void G4VisCommandViewerAddCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) {
116
117  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
118
119  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
120  if (!viewer) {
121    if (verbosity >= G4VisManager::errors) {
122      G4cout <<
123  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
124             << G4endl;
125    }
126    return;
127  }
128
129  G4double x, y, z, nx, ny, nz;
130  G4String unit;
131  std::istringstream is (newValue);
132  is >> x >> y >> z >> unit >> nx >> ny >> nz;
133  G4double F = G4UIcommand::ValueOf(unit);
134  x *= F; y *= F; z *= F;
135
136  G4ViewParameters vp = viewer->GetViewParameters();
137  vp.AddCutawayPlane(G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
138  if (verbosity >= G4VisManager::confirmations) {
139    G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
140    const G4Planes& cutaways = vp.GetCutawayPlanes();
141    for (size_t i = 0; i < cutaways.size(); ++i)
142      G4cout << "\n  " << i << ": " << cutaways[i];
143    G4cout << G4endl;
144  }
145
146  SetViewParameters(viewer, vp);
147}
148
149////////////// /vis/viewer/changeCutawayPlane ///////////////////////////////////////
150
151G4VisCommandViewerChangeCutawayPlane::G4VisCommandViewerChangeCutawayPlane () {
152  G4bool omitable;
153  fpCommand = new G4UIcommand ("/vis/viewer/changeCutawayPlane", this);
154  fpCommand -> SetGuidance("Change cutaway plane.");
155  G4UIparameter* parameter;
156  parameter  =  new G4UIparameter("index",'i',omitable = false);
157  parameter  -> SetGuidance      ("Index of plane: 0, 1, 2.");
158  fpCommand->SetParameter(parameter);
159  parameter  =  new G4UIparameter("x",'d',omitable = true);
160  parameter  -> SetDefaultValue  (0);
161  parameter  -> SetGuidance      ("Coordinate of point on the plane.");
162  fpCommand->SetParameter(parameter);
163  parameter  =  new G4UIparameter("y",'d',omitable = true);
164  parameter  -> SetDefaultValue  (0);
165  parameter  -> SetGuidance      ("Coordinate of point on the plane.");
166  fpCommand->SetParameter(parameter);
167  parameter  =  new G4UIparameter("z",'d',omitable = true);
168  parameter  -> SetDefaultValue  (0);
169  parameter  -> SetGuidance      ("Coordinate of point on the plane.");
170  fpCommand->SetParameter(parameter);
171  parameter  =  new G4UIparameter("unit",'s',omitable = true);
172  parameter  -> SetDefaultValue  ("m");
173  parameter  -> SetGuidance      ("Unit of point on the plane.");
174  fpCommand->SetParameter(parameter);
175  parameter  =  new G4UIparameter("nx",'d',omitable = true);
176  parameter  -> SetDefaultValue  (1);
177  parameter  -> SetGuidance      ("Component of plane normal.");
178  fpCommand->SetParameter(parameter);
179  parameter  =  new G4UIparameter("ny",'d',omitable = true);
180  parameter  -> SetDefaultValue  (0);
181  parameter  -> SetGuidance      ("Component of plane normal.");
182  fpCommand->SetParameter(parameter);
183  parameter  =  new G4UIparameter("nz",'d',omitable = true);
184  parameter  -> SetDefaultValue  (0);
185  parameter  -> SetGuidance      ("Component of plane normal.");
186  fpCommand->SetParameter(parameter);
187}
188
189G4VisCommandViewerChangeCutawayPlane::~G4VisCommandViewerChangeCutawayPlane () {
190  delete fpCommand;
191}
192
193G4String G4VisCommandViewerChangeCutawayPlane::GetCurrentValue (G4UIcommand*) {
194  return "";
195}
196
197void G4VisCommandViewerChangeCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) {
198
199  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
200
201  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
202  if (!viewer) {
203    if (verbosity >= G4VisManager::errors) {
204      G4cout <<
205  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
206             << G4endl;
207    }
208    return;
209  }
210
211  size_t index;
212  G4double x, y, z, nx, ny, nz;
213  G4String unit;
214  std::istringstream is (newValue);
215  is >> index >> x >> y >> z >> unit >> nx >> ny >> nz;
216  G4double F = G4UIcommand::ValueOf(unit);
217  x *= F; y *= F; z *= F;
218
219  G4ViewParameters vp = viewer->GetViewParameters();
220  vp.ChangeCutawayPlane(index,
221                        G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
222  if (verbosity >= G4VisManager::confirmations) {
223    G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
224    const G4Planes& cutaways = vp.GetCutawayPlanes();
225    for (size_t i = 0; i < cutaways.size(); ++i)
226      G4cout << "\n  " << i << ": " << cutaways[i];
227    G4cout << G4endl;
228  }
229
230  SetViewParameters(viewer, vp);
231}
232
233////////////// /vis/viewer/clear ///////////////////////////////////////
234
235G4VisCommandViewerClear::G4VisCommandViewerClear () {
236  G4bool omitable, currentAsDefault;
237  fpCommand = new G4UIcmdWithAString ("/vis/viewer/clear", this);
238  fpCommand -> SetGuidance ("Clears viewer.");
239  fpCommand -> SetGuidance
240    ("By default, clears current viewer.  Specified viewer becomes current."
241     "\n\"/vis/viewer/list\" to see  possible viewer names.");
242  fpCommand -> SetParameterName ("viewer-name",
243                                 omitable = true,
244                                 currentAsDefault = true);
245}
246
247G4VisCommandViewerClear::~G4VisCommandViewerClear () {
248  delete fpCommand;
249}
250
251G4String G4VisCommandViewerClear::GetCurrentValue (G4UIcommand*) {
252  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
253  return viewer ? viewer -> GetName () : G4String("none");
254}
255
256void G4VisCommandViewerClear::SetNewValue (G4UIcommand*, G4String newValue) {
257
258  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
259
260  G4String& clearName = newValue;
261  G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
262  if (!viewer) {
263    if (verbosity >= G4VisManager::errors) {
264      G4cout << "ERROR: Viewer \"" << clearName
265             << "\" not found - \"/vis/viewer/list\" to see possibilities."
266             << G4endl;
267    }
268    return;
269  }
270
271  viewer->ClearView();
272  viewer->FinishView();
273  if (verbosity >= G4VisManager::confirmations) {
274    G4cout << "Viewer \"" << clearName << "\" cleared." << G4endl;
275  }
276
277}
278
279////////////// /vis/viewer/clearCutawayPlanes ///////////////////////////////////////
280
281G4VisCommandViewerClearCutawayPlanes::G4VisCommandViewerClearCutawayPlanes () {
282  fpCommand = new G4UIcmdWithoutParameter
283    ("/vis/viewer/clearCutawayPlanes", this);
284  fpCommand -> SetGuidance ("Clear cutaway planes of current viewer.");
285}
286
287G4VisCommandViewerClearCutawayPlanes::~G4VisCommandViewerClearCutawayPlanes () {
288  delete fpCommand;
289}
290
291G4String G4VisCommandViewerClearCutawayPlanes::GetCurrentValue (G4UIcommand*) {
292  return "";
293}
294
295void G4VisCommandViewerClearCutawayPlanes::SetNewValue (G4UIcommand*, G4String) {
296
297  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
298
299  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
300  if (!viewer) {
301    if (verbosity >= G4VisManager::errors) {
302      G4cout <<
303  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
304             << G4endl;
305    }
306    return;
307  }
308
309  G4ViewParameters vp = viewer->GetViewParameters();
310  vp.ClearCutawayPlanes();
311  if (verbosity >= G4VisManager::confirmations) {
312    G4cout << "Cutaway planes for viewer \"" << viewer->GetName()
313           << "\" now cleared." << G4endl;
314  }
315
316  SetViewParameters(viewer, vp);
317}
318
319////////////// /vis/viewer/clearTransients //////////////////////////
320
321G4VisCommandViewerClearTransients::G4VisCommandViewerClearTransients () {
322  G4bool omitable, currentAsDefault;
323  fpCommand = new G4UIcmdWithAString ("/vis/viewer/clearTransients", this);
324  fpCommand -> SetGuidance ("Clears transients from viewer.");
325  fpCommand -> SetGuidance
326  ("By default, operates on current viewer.  Specified viewer becomes current."
327     "\n\"/vis/viewer/list\" to see  possible viewer names.");
328  fpCommand -> SetParameterName ("viewer-name",
329                                 omitable = true,
330                                 currentAsDefault = true);
331}
332
333G4VisCommandViewerClearTransients::~G4VisCommandViewerClearTransients () {
334  delete fpCommand;
335}
336
337G4String G4VisCommandViewerClearTransients::GetCurrentValue (G4UIcommand*) {
338  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
339  return viewer ? viewer -> GetName () : G4String("none");
340}
341
342void G4VisCommandViewerClearTransients::SetNewValue (G4UIcommand*, G4String newValue) {
343
344  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
345
346  G4String& clearName = newValue;
347  G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
348  if (!viewer) {
349    if (verbosity >= G4VisManager::errors) {
350      G4cout << "ERROR: Viewer \"" << clearName
351             << "\" not found - \"/vis/viewer/list\" to see possibilities."
352             << G4endl;
353    }
354    return;
355  }
356
357  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
358  sceneHandler->SetMarkForClearingTransientStore(false);
359  fpVisManager->ResetTransientsDrawnFlags();
360  sceneHandler->ClearTransientStore();
361  if (verbosity >= G4VisManager::confirmations) {
362    G4cout << "Viewer \"" << clearName << "\" cleared of transients."
363           << G4endl;
364  }
365
366}
367
368////////////// /vis/viewer/clone ///////////////////////////////////////
369
370G4VisCommandViewerClone::G4VisCommandViewerClone () {
371  G4bool omitable;
372  fpCommand = new G4UIcommand ("/vis/viewer/clone", this);
373  fpCommand -> SetGuidance ("Clones viewer.");
374  fpCommand -> SetGuidance
375    ("By default, clones current viewer.  Clone becomes current."
376     "\nClone name, if not provided, is derived from the original name."
377     "\n\"/vis/viewer/list\" to see  possible viewer names.");
378  G4UIparameter* parameter;
379  parameter = new G4UIparameter ("original-viewer-name", 's', omitable = true);
380  parameter -> SetCurrentAsDefault (true);
381  fpCommand -> SetParameter (parameter);
382  parameter = new G4UIparameter ("clone-name", 's', omitable = true);
383  parameter -> SetDefaultValue ("none");
384  fpCommand -> SetParameter (parameter);
385}
386
387G4VisCommandViewerClone::~G4VisCommandViewerClone () {
388  delete fpCommand;
389}
390
391G4String G4VisCommandViewerClone::GetCurrentValue (G4UIcommand*) {
392  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
393  G4String originalName = viewer ? viewer -> GetName () : G4String("none");
394  return "\"" + originalName + "\"";
395}
396
397void G4VisCommandViewerClone::SetNewValue (G4UIcommand*, G4String newValue) {
398
399  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
400
401  G4String originalName, cloneName;
402  std::istringstream is (newValue);
403
404  // Need to handle the possibility that the names contain embedded
405  // blanks within quotation marks...
406  char c;
407  while (is.get(c) && c == ' '){}
408  if (c == '"') {
409    while (is.get(c) && c != '"') {originalName += c;}
410  }
411  else {
412    originalName += c;
413    while (is.get(c) && c != ' ') {originalName += c;}
414  }
415  originalName = originalName.strip (G4String::both, ' ');
416  originalName = originalName.strip (G4String::both, '"');
417
418  G4VViewer* originalViewer = fpVisManager -> GetViewer (originalName);
419  if (!originalViewer) {
420    if (verbosity >= G4VisManager::errors) {
421      G4cout << "ERROR: Viewer \"" << originalName
422             << "\" not found - \"/vis/viewer/list\" to see possibilities."
423             << G4endl;
424    }
425    return;
426  }
427  originalName = originalViewer->GetName();  // Ensures long name.
428
429  while (is.get(c) && c == ' '){}
430  if (c == '"') {
431    while (is.get(c) && c != '"') {cloneName += c;}
432  }
433  else {
434    cloneName += c;
435    while (is.get(c) && c != ' ') {cloneName += c;}
436  }
437  cloneName = cloneName.strip (G4String::both, ' ');
438  cloneName = cloneName.strip (G4String::both, '"');
439
440  if (cloneName == "none") {
441    G4int subID = 0;
442    do {
443      cloneName = originalName;
444      std::ostringstream oss;
445      oss << '-' << subID++;
446      G4String::size_type lastDashPosition, nextSpacePosition;
447      if ((lastDashPosition = cloneName.rfind('-')) !=  G4String::npos &&
448          (nextSpacePosition = cloneName.find(" ", lastDashPosition)) !=
449          G4String::npos) {
450        cloneName.insert(nextSpacePosition, oss.str());
451      } else {
452        cloneName.insert(cloneName.find(' '), oss.str());
453      }
454    } while (fpVisManager -> GetViewer (cloneName));
455  }
456
457  if (fpVisManager -> GetViewer (cloneName)) {
458    if (verbosity >= G4VisManager::errors) {
459      G4cout << "ERROR: Putative clone viewer \"" << cloneName
460             << "\" already exists."
461             << G4endl;
462    }
463    return;
464  }
465
466  G4String windowSizeHint =
467    originalViewer->GetViewParameters().GetXGeometryString();
468
469  G4UImanager* UImanager = G4UImanager::GetUIpointer();
470  G4int keepVerbose = UImanager->GetVerboseLevel();
471  G4int newVerbose(0);
472  if (keepVerbose >= 2 ||
473      fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
474    newVerbose = 2;
475  UImanager->SetVerboseLevel(newVerbose);
476  UImanager->ApplyCommand(G4String("/vis/viewer/select " + originalName));
477  UImanager->ApplyCommand
478    (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint));
479  UImanager->ApplyCommand(G4String("/vis/viewer/set/all " + originalName));
480  UImanager->SetVerboseLevel(keepVerbose);
481
482  if (verbosity >= G4VisManager::confirmations) {
483    G4cout << "Viewer \"" << originalName << "\" cloned." << G4endl;
484    G4cout << "Clone \"" << cloneName << "\" now current." << G4endl;
485  }
486}
487
488////////////// /vis/viewer/create ///////////////////////////////////////
489
490G4VisCommandViewerCreate::G4VisCommandViewerCreate ():
491  fId (0),
492  NoValue(0x0000),
493  XValue(0x0001),
494  YValue(0x0002),
495  WidthValue(0x0004),
496  HeightValue(0x0008),
497  AllValues(0x000F),
498  XNegative(0x0010),
499  YNegative(0x0020) {
500  G4bool omitable;
501  fpCommand = new G4UIcommand ("/vis/viewer/create", this);
502  fpCommand -> SetGuidance
503    ("Creates a viewer for the specified scene handler.");
504  fpCommand -> SetGuidance
505    ("Default scene handler is the current scene handler.  Invents a name"
506     "\nif not supplied.  (Note: the system adds information to the name"
507     "\nfor identification - only the characters up to the first blank are"
508     "\nused for removing, selecting, etc.)  This scene handler and viewer"
509     "\nbecome current.");
510  G4UIparameter* parameter;
511  parameter = new G4UIparameter ("scene-handler", 's', omitable = true);
512  parameter -> SetCurrentAsDefault (true);
513  fpCommand -> SetParameter (parameter);
514  parameter = new G4UIparameter ("viewer-name", 's', omitable = true);
515  parameter -> SetCurrentAsDefault (true);
516  fpCommand -> SetParameter (parameter);
517  parameter = new G4UIparameter ("window-size-hint", 's', omitable = true);
518  parameter->SetGuidance
519    ("integer (pixels) for square window placed by window manager or"
520     " X-Windows-type geometry string, e.g. 600x600-100+100");
521  parameter->SetDefaultValue("600");
522  fpCommand -> SetParameter (parameter);
523}
524
525G4VisCommandViewerCreate::~G4VisCommandViewerCreate () {
526  delete fpCommand;
527}
528
529G4String G4VisCommandViewerCreate::NextName () {
530  std::ostringstream oss;
531  G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler ();
532  oss << "viewer-" << fId << " (";
533  if (sceneHandler) {
534    oss << sceneHandler -> GetGraphicsSystem () -> GetName ();
535  }
536  else {
537    oss << "no_scene_handlers";
538  }
539  oss << ")";
540  return oss.str();
541}
542
543G4String G4VisCommandViewerCreate::GetCurrentValue (G4UIcommand*) {
544  G4String currentValue;
545  G4VSceneHandler* currentSceneHandler =
546    fpVisManager -> GetCurrentSceneHandler ();
547  if (currentSceneHandler) {
548    currentValue = currentSceneHandler -> GetName ();
549  }
550  else {
551    currentValue = "none";
552  }
553  currentValue += ' ';
554  currentValue += '"';
555  currentValue += NextName ();
556  currentValue += '"';
557
558  currentValue += " 600";  // Default number of pixels for window size hint.
559
560  return currentValue;
561}
562
563void G4VisCommandViewerCreate::SetNewValue (G4UIcommand*, G4String newValue) {
564
565  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
566
567  G4String sceneHandlerName, newName;
568  G4String windowSizeHintString;
569  std::istringstream is (newValue);
570  is >> sceneHandlerName;
571
572  // Now need to handle the possibility that the second string
573  // contains embedded blanks within quotation marks...
574  char c;
575  while (is.get(c) && c == ' '){}
576  if (c == '"') {
577    while (is.get(c) && c != '"') {newName += c;}
578  }
579  else {
580    newName += c;
581    while (is.get(c) && c != ' ') {newName += c;}
582  }
583  newName = newName.strip (G4String::both, ' ');
584  newName = newName.strip (G4String::both, '"');
585
586  // Now get window size hint...
587  is >> windowSizeHintString;
588
589  const G4SceneHandlerList& sceneHandlerList =
590    fpVisManager -> GetAvailableSceneHandlers ();
591  G4int nHandlers = sceneHandlerList.size ();
592  if (nHandlers <= 0) {
593    if (verbosity >= G4VisManager::errors) {
594      G4cout <<
595        "ERROR: G4VisCommandViewerCreate::SetNewValue: no scene handlers."
596        "\n  Create a scene handler with \"/vis/sceneHandler/create\""
597             << G4endl;
598    }
599    return;
600  }
601
602  G4int iHandler;
603  for (iHandler = 0; iHandler < nHandlers; iHandler++) {
604    if (sceneHandlerList [iHandler] -> GetName () == sceneHandlerName) break;
605  }
606
607  if (iHandler < 0 || iHandler >= nHandlers) {
608    // Invalid command line argument or none.
609    // This shouldn't happen!!!!!!
610    if (verbosity >= G4VisManager::errors) {
611      G4cout << "G4VisCommandViewerCreate::SetNewValue:"
612        " invalid scene handler specified."
613            << G4endl;
614    }
615    return;
616  }
617
618  // Valid index.  Set current scene handler and graphics system in
619  // preparation for creating viewer.
620  G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
621  if (sceneHandler != fpVisManager -> GetCurrentSceneHandler ()) {
622    fpVisManager -> SetCurrentSceneHandler (sceneHandler);
623  }
624
625  // Now deal with name of viewer.
626  G4String nextName = NextName ();
627  if (newName == "") {
628    newName = nextName;
629  }
630  if (newName == nextName) fId++;
631  G4String newShortName = fpVisManager -> ViewerShortName (newName);
632
633  for (iHandler = 0; iHandler < nHandlers; iHandler++) {
634    G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
635    const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
636    for (size_t iViewer = 0; iViewer < viewerList.size (); iViewer++) {
637      if (viewerList [iViewer] -> GetShortName () == newShortName ) {
638        if (verbosity >= G4VisManager::errors) {
639          G4cout << "ERROR: Viewer \"" << newShortName << "\" already exists."
640                 << G4endl;
641        }
642        return;
643      }
644    }
645  }
646
647
648  // Parse windowSizeHintString to extract first field for backwards
649  // compatibility...
650  std::istringstream issw;
651  G4int windowSizeHint;
652  size_t i;
653#ifdef G4DEBUG
654    printf("G4VisCommandViewerCreate::SetNewValue string\n");
655#endif
656  for (i = 0; i < windowSizeHintString.size(); ++i) {
657    char c = windowSizeHintString[i];
658#ifdef G4DEBUG
659    printf("%c",c);
660#endif
661    if (c == 'x' || c == 'X' || c == '+' || c == '-') break;
662  }
663#ifdef G4DEBUG
664    printf("\n");
665#endif
666  if (i != windowSizeHintString.size()) {
667    // x or X or + or - found - must be a X-Window-type geometry string...
668    // Pick out the first field for backwards compatibility...
669    issw.str(windowSizeHintString.substr(0,i));
670    issw >> windowSizeHint;
671  } else { // ...old-style integer...
672    issw.str(windowSizeHintString);
673    if (!(issw >> windowSizeHint)) {
674      if (verbosity >= G4VisManager::errors) {
675        G4cout << "ERROR: Unrecognised geometry string \""
676               << windowSizeHintString
677               << "\".  Using 600."
678               << G4endl;
679      }
680      windowSizeHint = 600;
681    }
682    // Reconstitute windowSizeHintString...
683    std::ostringstream ossw;
684    ossw << windowSizeHint << 'x' << windowSizeHint;
685    windowSizeHintString = ossw.str();
686  }
687  fpVisManager->SetWindowSizeHint (windowSizeHint, windowSizeHint);
688  fpVisManager->SetXGeometryString(windowSizeHintString);
689  // WindowSizeHint and XGeometryString are picked up from the vis
690  // manager in the G4VViewer constructor.  They have to be held by
691  // the vis manager until the viewer is contructed - next line...
692
693  ////////
694
695  int x,y = 0;
696  unsigned int w,h = 9999999;
697
698  int m = ParseGeometry( windowSizeHintString, &x, &y, &w, &h );
699  //  QSize minSize = main_widget->minimumSize();
700  //  QSize maxSize = main_widget->maximumSize();
701  if ( (m & XValue) == 0 )
702    x = -1;
703  if ( (m & YValue) == 0 )
704    y = -2;
705  if ( (m & WidthValue) == 0 )
706    w = -3;
707  if ( (m & HeightValue) == 0 )
708    h = -4;
709//   w = QMIN(w,maxSize.width());
710//   h = QMIN(h,maxSize.height());
711//   w = QMAX(w,minSize.width());
712//   h = QMAX(h,minSize.height());
713//   if ( (m & XNegative) ) {
714//     x = desktop()->width()  + x - w;
715//     qt_widget_tlw_gravity = 3;
716//   }
717//   if ( (m & YNegative) ) {
718//              y = desktop()->height() + y - h;
719//              qt_widget_tlw_gravity = (m & XNegative) ? 9 : 7;
720//   }
721//   main_widget->setGeometry( x, y, w, h );
722
723#ifdef G4DEBUG
724  printf  ("Lecture X:%d Y:%d W:%d H:%d\n",x,y,w,h);
725  ////////
726#endif
727
728  // Create viewer.
729  fpVisManager -> CreateViewer (newName);
730  G4VViewer* newViewer = fpVisManager -> GetCurrentViewer ();
731  if (newViewer && newViewer -> GetName () == newName) {
732    if (verbosity >= G4VisManager::confirmations) {
733      G4cout << "New viewer \"" << newName << "\" created." << G4endl;
734    }
735  }
736  else {
737    if (verbosity >= G4VisManager::errors) {
738      if (newViewer) {
739        G4cout << "ERROR: New viewer doesn\'t match!!!  Curious!!" << G4endl;
740      } else {
741        G4cout << "WARNING: No viewer created." << G4endl;
742      }
743    }
744  }
745  // Refresh if appropriate...
746  if (newViewer) {
747    if (newViewer->GetViewParameters().IsAutoRefresh()) {
748      G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
749    }
750    else {
751      if (verbosity >= G4VisManager::confirmations) {
752        G4cout << "Issue /vis/viewer/refresh to see effect." << G4endl;
753      }
754    }
755  }
756}
757
758////////////// /vis/viewer/dolly and dollyTo ////////////////////////////
759
760G4VisCommandViewerDolly::G4VisCommandViewerDolly ():
761  fDollyIncrement  (0.),
762  fDollyTo (0.)
763{
764  G4bool omitable, currentAsDefault;
765
766  fpCommandDolly = new G4UIcmdWithADoubleAndUnit
767    ("/vis/viewer/dolly", this);
768  fpCommandDolly -> SetGuidance
769    ("Incremental dolly.");
770  fpCommandDolly -> SetGuidance
771    ("Moves the camera incrementally towards target point.");
772  fpCommandDolly -> SetParameterName("increment",
773                                     omitable=true,
774                                     currentAsDefault=true);
775  fpCommandDolly -> SetDefaultUnit("m");
776
777  fpCommandDollyTo = new G4UIcmdWithADoubleAndUnit
778    ("/vis/viewer/dollyTo", this);
779  fpCommandDollyTo -> SetGuidance
780    ("Dolly to specific coordinate.");
781  fpCommandDollyTo -> SetGuidance
782 ("Places the camera towards target point relative to standard camera point.");
783  fpCommandDollyTo -> SetParameterName("distance",
784                                       omitable=true,
785                                       currentAsDefault=true);
786  fpCommandDollyTo -> SetDefaultUnit("m");
787}
788
789G4VisCommandViewerDolly::~G4VisCommandViewerDolly () {
790  delete fpCommandDolly;
791  delete fpCommandDollyTo;
792}
793
794G4String G4VisCommandViewerDolly::GetCurrentValue (G4UIcommand* command) {
795  G4String currentValue;
796  if (command == fpCommandDolly) {
797    currentValue = fpCommandDolly->ConvertToString(fDollyIncrement, "m");
798  }
799  else if (command == fpCommandDollyTo) {
800    currentValue = fpCommandDollyTo->ConvertToString(fDollyTo, "m");
801  }
802  return currentValue;
803}
804
805void G4VisCommandViewerDolly::SetNewValue (G4UIcommand* command,
806                                           G4String newValue) {
807
808
809  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
810
811  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
812  if (!currentViewer) {
813    if (verbosity >= G4VisManager::errors) {
814      G4cout <<
815        "ERROR: G4VisCommandsViewerDolly::SetNewValue: no current viewer."
816             << G4endl;
817    }
818    return;
819  }
820
821  G4ViewParameters vp = currentViewer->GetViewParameters();
822
823  if (command == fpCommandDolly) {
824    fDollyIncrement = fpCommandDolly->GetNewDoubleValue(newValue);
825    vp.IncrementDolly(fDollyIncrement);
826  }
827  else if (command == fpCommandDollyTo) {
828    fDollyTo = fpCommandDolly->GetNewDoubleValue(newValue);
829    vp.SetDolly(fDollyTo);
830  }
831
832  if (verbosity >= G4VisManager::confirmations) {
833    G4cout << "Dolly distance changed to " << vp.GetDolly() << G4endl;
834  }
835
836  SetViewParameters(currentViewer, vp);
837}
838
839////////////// /vis/viewer/flush ///////////////////////////////////////
840
841G4VisCommandViewerFlush::G4VisCommandViewerFlush () {
842  G4bool omitable, currentAsDefault;
843  fpCommand = new G4UIcmdWithAString ("/vis/viewer/flush", this);
844  fpCommand -> SetGuidance
845    ("Compound command: \"/vis/viewer/refresh\" + \"/vis/viewer/update\".");
846  fpCommand -> SetGuidance
847    ("Useful for refreshing and initiating post-processing for graphics"
848     "\nsystems which need post-processing.  By default, acts on current"
849     "\nviewer.  \"/vis/viewer/list\" to see possible viewers.  Viewer"
850     "\nbecomes current.");
851  fpCommand -> SetParameterName ("viewer-name",
852                                 omitable = true,
853                                 currentAsDefault = true);
854}
855
856G4VisCommandViewerFlush::~G4VisCommandViewerFlush () {
857  delete fpCommand;
858}
859
860G4String G4VisCommandViewerFlush::GetCurrentValue
861(G4UIcommand*) {
862  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
863  return viewer ? viewer -> GetName () : G4String("none");
864}
865
866void G4VisCommandViewerFlush::SetNewValue (G4UIcommand*, G4String newValue) {
867
868  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
869
870  G4String& flushName = newValue;
871  G4VViewer* viewer = fpVisManager -> GetViewer (flushName);
872  if (!viewer) {
873    if (verbosity >= G4VisManager::errors) {
874      G4cout << "ERROR: Viewer \"" << flushName << "\"" <<
875        " not found - \"/vis/viewer/list\"\n  to see possibilities."
876             << G4endl;
877    }
878    return;
879  }
880
881  G4UImanager* ui = G4UImanager::GetUIpointer();
882  G4int keepVerbose = ui->GetVerboseLevel();
883  G4int newVerbose(0);
884  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
885    newVerbose = 2;
886  ui->SetVerboseLevel(newVerbose);
887  ui->ApplyCommand(G4String("/vis/viewer/refresh " + flushName));
888  ui->ApplyCommand(G4String("/vis/viewer/update " + flushName));
889  ui->SetVerboseLevel(keepVerbose);
890  if (verbosity >= G4VisManager::confirmations) {
891    G4cout << "Viewer \"" << viewer -> GetName () << "\""
892           << " flushed." << G4endl;
893  }
894}
895
896////////////// /vis/viewer/list ///////////////////////////////////////
897
898G4VisCommandViewerList::G4VisCommandViewerList () {
899  G4bool omitable;
900  fpCommand = new G4UIcommand ("/vis/viewer/list", this);
901  fpCommand -> SetGuidance ("Lists viewers(s).");
902  fpCommand -> SetGuidance
903    ("See \"/vis/verbose\" for definition of verbosity.");
904  G4UIparameter* parameter;
905  parameter = new G4UIparameter("viewer-name", 's',
906                                omitable = true);
907  parameter -> SetDefaultValue ("all");
908  fpCommand -> SetParameter (parameter);
909  parameter = new G4UIparameter ("verbosity", 's',
910                                 omitable = true);
911  parameter -> SetDefaultValue ("warnings");
912  fpCommand -> SetParameter (parameter);
913}
914
915G4VisCommandViewerList::~G4VisCommandViewerList () {
916  delete fpCommand;
917}
918
919G4String G4VisCommandViewerList::GetCurrentValue (G4UIcommand*) {
920  return "";
921}
922
923void G4VisCommandViewerList::SetNewValue (G4UIcommand*, G4String newValue) {
924  G4String name, verbosityString;
925  std::istringstream is (newValue);
926  is >> name >> verbosityString;
927  G4String shortName = fpVisManager -> ViewerShortName (name);
928  G4VisManager::Verbosity verbosity =
929    fpVisManager->GetVerbosityValue(verbosityString);
930
931  const G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
932  G4String currentViewerShortName;
933  if (currentViewer) {
934    currentViewerShortName = currentViewer -> GetShortName ();
935  }
936  else {
937    currentViewerShortName = "none";
938  }
939
940  const G4SceneHandlerList& sceneHandlerList = fpVisManager -> GetAvailableSceneHandlers ();
941  G4int nHandlers = sceneHandlerList.size ();
942  G4bool found = false;
943  G4bool foundCurrent = false;
944  for (int iHandler = 0; iHandler < nHandlers; iHandler++) {
945    G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
946    const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
947    G4cout << "Scene handler \"" << sceneHandler -> GetName ();
948    const G4Scene* pScene = sceneHandler -> GetScene ();
949    if (pScene) {
950      G4cout << "\", scene \"" << pScene -> GetName () << "\":";
951    }
952    G4int nViewers = viewerList.size ();
953    if (nViewers == 0) {
954      G4cout << "\n            No viewers for this scene handler." << G4endl;
955    }
956    else {
957      for (int iViewer = 0; iViewer < nViewers; iViewer++) {
958        const G4VViewer* thisViewer = viewerList [iViewer];
959        G4String thisName = thisViewer -> GetName ();
960        G4String thisShortName = thisViewer -> GetShortName ();
961        if (name != "all") {
962          if (thisShortName != shortName) continue;
963        }
964        found = true;
965        G4cout << "\n  ";
966        if (thisShortName == currentViewerShortName) {
967          foundCurrent = true;
968          G4cout << "(current)";
969        }
970        else {
971          G4cout << "         ";
972        }
973        G4cout << " viewer \"" << thisName << "\"";
974        if (verbosity >= G4VisManager::parameters) {
975          G4cout << "\n  " << *thisViewer;
976        }
977      }
978    }
979    G4cout << G4endl;
980  }
981
982  if (!foundCurrent) {
983    G4cout << "No valid current viewer - please create or select one."
984           << G4endl;
985  }
986
987  if (!found) {
988    G4cout << "No viewers";
989    if (name != "all") {
990      G4cout << " of name \"" << name << "\"";
991    }
992    G4cout << " found." << G4endl;
993  }
994}
995
996////////////// /vis/viewer/pan and panTo ////////////////////////////
997
998G4VisCommandViewerPan::G4VisCommandViewerPan ():
999  fPanIncrementRight  (0.),
1000  fPanIncrementUp  (0.),
1001  fPanToRight (0.),
1002  fPanToUp (0.)
1003{
1004  G4bool omitable;
1005
1006  fpCommandPan = new G4UIcommand
1007    ("/vis/viewer/pan", this);
1008  fpCommandPan -> SetGuidance
1009    ("Incremental pan.");
1010  fpCommandPan -> SetGuidance
1011    ("Moves the camera incrementally right and up by these amounts (as seen"
1012     "\nfrom viewpoint direction).");
1013  G4UIparameter* parameter;
1014  parameter = new G4UIparameter("right-increment", 'd', omitable = true);
1015  parameter -> SetCurrentAsDefault (true);
1016  fpCommandPan -> SetParameter (parameter);
1017  parameter = new G4UIparameter("up-increment", 'd', omitable = true);
1018  parameter -> SetCurrentAsDefault (true);
1019  fpCommandPan -> SetParameter (parameter);
1020  parameter = new G4UIparameter ("unit", 's', omitable = true);
1021  parameter -> SetDefaultValue ("m");
1022  fpCommandPan -> SetParameter (parameter);
1023
1024  fpCommandPanTo = new G4UIcommand
1025    ("/vis/viewer/panTo", this);
1026  fpCommandPanTo -> SetGuidance
1027    ("Pan to specific coordinate.");
1028  fpCommandPanTo -> SetGuidance
1029    ("Places the camera in this position right and up relative to standard"
1030     "\ntarget point (as seen from viewpoint direction).");
1031  parameter = new G4UIparameter("right", 'd', omitable = true);
1032  parameter -> SetCurrentAsDefault (true);
1033  fpCommandPanTo -> SetParameter (parameter);
1034  parameter = new G4UIparameter("up", 'd', omitable = true);
1035  parameter -> SetCurrentAsDefault (true);
1036  fpCommandPanTo -> SetParameter (parameter);
1037  parameter = new G4UIparameter ("unit", 's', omitable = true);
1038  parameter -> SetDefaultValue ("m");
1039  fpCommandPanTo -> SetParameter (parameter);
1040}
1041
1042G4VisCommandViewerPan::~G4VisCommandViewerPan () {
1043  delete fpCommandPan;
1044  delete fpCommandPanTo;
1045}
1046
1047G4String G4VisCommandViewerPan::GetCurrentValue (G4UIcommand* command) {
1048  G4String currentValue;
1049  if (command == fpCommandPan) {
1050    currentValue = ConvertToString(fPanIncrementRight, fPanIncrementUp, "m");
1051  }
1052  else if (command == fpCommandPanTo) {
1053    currentValue = ConvertToString(fPanToRight, fPanToUp, "m");
1054  }
1055  return currentValue;
1056}
1057
1058void G4VisCommandViewerPan::SetNewValue (G4UIcommand* command,
1059                                         G4String newValue) {
1060
1061
1062  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1063
1064  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1065  if (!currentViewer) {
1066    if (verbosity >= G4VisManager::errors) {
1067      G4cout <<
1068        "ERROR: G4VisCommandsViewerPan::SetNewValue: no current viewer."
1069             << G4endl;
1070    }
1071    return;
1072  }
1073
1074  G4ViewParameters vp = currentViewer->GetViewParameters();
1075
1076  if (command == fpCommandPan) {
1077    ConvertToDoublePair(newValue, fPanIncrementRight, fPanIncrementUp);
1078    vp.IncrementPan(fPanIncrementRight, fPanIncrementUp);
1079  }
1080  else if (command == fpCommandPanTo) {
1081    ConvertToDoublePair(newValue, fPanToRight, fPanToUp);
1082    vp.SetPan(fPanToRight, fPanToUp);
1083  }
1084
1085  if (verbosity >= G4VisManager::confirmations) {
1086    G4cout << "Current target point now " << vp.GetCurrentTargetPoint()
1087           << G4endl;
1088  }
1089
1090  SetViewParameters(currentViewer, vp);
1091}
1092
1093////////////// /vis/viewer/rebuild ///////////////////////////////////////
1094
1095G4VisCommandViewerRebuild::G4VisCommandViewerRebuild () {
1096  G4bool omitable, currentAsDefault;
1097  fpCommand = new G4UIcmdWithAString ("/vis/viewer/rebuild", this);
1098  fpCommand -> SetGuidance ("Forces rebuild of graphical database.");
1099  fpCommand -> SetGuidance
1100    ("By default, acts on current viewer.  \"/vis/viewer/list\""
1101     "\nto see possible viewers.  Viewer becomes current.");
1102  fpCommand -> SetParameterName ("viewer-name",
1103                                 omitable = true,
1104                                 currentAsDefault = true);
1105}
1106
1107G4VisCommandViewerRebuild::~G4VisCommandViewerRebuild () {
1108  delete fpCommand;
1109}
1110
1111G4String G4VisCommandViewerRebuild::GetCurrentValue (G4UIcommand*) {
1112  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1113  if (viewer) {
1114    return viewer -> GetName ();
1115  }
1116  else {
1117    return "none";
1118  }
1119}
1120
1121void G4VisCommandViewerRebuild::SetNewValue (G4UIcommand*, G4String newValue) {
1122
1123  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1124
1125  G4String& rebuildName = newValue;
1126  G4VViewer* viewer = fpVisManager -> GetViewer (rebuildName);
1127  if (!viewer) {
1128    if (verbosity >= G4VisManager::errors) {
1129      G4cout << "ERROR: Viewer \"" << rebuildName
1130             << "\" not found - \"/vis/viewer/list\" to see possibilities."
1131             << G4endl;
1132    }
1133    return;
1134  }
1135
1136  viewer->NeedKernelVisit();
1137
1138  // Check auto-refresh and print confirmations, but without changing
1139  // view paramters...
1140  SetViewParameters(viewer, viewer->GetViewParameters());
1141}
1142
1143////////////// /vis/viewer/refresh ///////////////////////////////////////
1144
1145G4VisCommandViewerRefresh::G4VisCommandViewerRefresh () {
1146  G4bool omitable, currentAsDefault;
1147  fpCommand = new G4UIcmdWithAString ("/vis/viewer/refresh", this);
1148  fpCommand -> SetGuidance
1149    ("Refreshes viewer.");
1150  fpCommand -> SetGuidance
1151    ("By default, acts on current viewer.  \"/vis/viewer/list\""
1152     "\nto see possible viewers.  Viewer becomes current.");
1153  fpCommand -> SetParameterName ("viewer-name",
1154                                 omitable = true,
1155                                 currentAsDefault = true);
1156}
1157
1158G4VisCommandViewerRefresh::~G4VisCommandViewerRefresh () {
1159  delete fpCommand;
1160}
1161
1162G4String G4VisCommandViewerRefresh::GetCurrentValue (G4UIcommand*) {
1163  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1164  return viewer ? viewer -> GetName () : G4String("none");
1165}
1166
1167void G4VisCommandViewerRefresh::SetNewValue (G4UIcommand*, G4String newValue) {
1168
1169  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1170  G4bool warn(verbosity >= G4VisManager::warnings);
1171
1172  G4String& refreshName = newValue;
1173  G4VViewer* viewer = fpVisManager -> GetViewer (refreshName);
1174  if (!viewer) {
1175    if (verbosity >= G4VisManager::errors) {
1176      G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
1177        " not found - \"/vis/viewer/list\"\n  to see possibilities."
1178             << G4endl;
1179    }
1180    return;
1181  }
1182
1183  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1184  if (!sceneHandler) {
1185    if (verbosity >= G4VisManager::errors) {
1186      G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
1187        " has no scene handler - report serious bug."
1188             << G4endl;
1189    }
1190    return;
1191  }
1192
1193  G4Scene* scene = sceneHandler->GetScene();
1194  if (!scene) {
1195    if (verbosity >= G4VisManager::confirmations) {
1196      G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
1197             << "\", to which viewer \"" << refreshName << "\"" <<
1198        "\n  is attached, has no scene - \"/vis/scene/create\" and"
1199        " \"/vis/sceneHandler/attach\""
1200        "\n  (or use compound command \"/vis/drawVolume\")."
1201             << G4endl;
1202    }
1203    return;
1204  }
1205  if (scene->GetRunDurationModelList().empty()) {
1206    G4bool successful = scene -> AddWorldIfEmpty (warn);
1207    if (!successful) {
1208      if (verbosity >= G4VisManager::warnings) {
1209        G4cout <<
1210          "WARNING: Scene is empty.  Perhaps no geometry exists."
1211          "\n  Try /run/initialize."
1212               << G4endl;
1213      }
1214      return;
1215    }
1216    // Scene has changed.  UpdateVisManagerScene issues
1217    // /vis/scene/notifyHandlers, which does a refresh anyway, so the
1218    // ordinary refresh becomes part of the else phrase...
1219    UpdateVisManagerScene(scene->GetName());
1220  } else {
1221    if (verbosity >= G4VisManager::confirmations) {
1222      G4cout << "Refreshing viewer \"" << viewer -> GetName () << "\"..."
1223             << G4endl;
1224    }
1225    viewer -> SetView ();
1226    viewer -> ClearView ();
1227    viewer -> DrawView ();
1228    if (verbosity >= G4VisManager::confirmations) {
1229      G4cout << "Viewer \"" << viewer -> GetName () << "\"" << " refreshed."
1230        "\n  (You might also need \"/vis/viewer/update\".)" << G4endl;
1231    }
1232  }
1233}
1234
1235////////////// /vis/viewer/reset ///////////////////////////////////////
1236
1237G4VisCommandViewerReset::G4VisCommandViewerReset () {
1238  G4bool omitable, currentAsDefault;
1239  fpCommand = new G4UIcmdWithAString ("/vis/viewer/reset", this);
1240  fpCommand -> SetGuidance ("Resets viewer.");
1241  fpCommand -> SetGuidance
1242    ("By default, acts on current viewer.  \"/vis/viewer/list\""
1243     "\nto see possible viewers.  Viewer becomes current.");
1244  fpCommand -> SetParameterName ("viewer-name",
1245                                 omitable = true,
1246                                 currentAsDefault = true);
1247}
1248
1249G4VisCommandViewerReset::~G4VisCommandViewerReset () {
1250  delete fpCommand;
1251}
1252
1253G4String G4VisCommandViewerReset::GetCurrentValue (G4UIcommand*) {
1254  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1255  if (viewer) {
1256    return viewer -> GetName ();
1257  }
1258  else {
1259    return "none";
1260  }
1261}
1262
1263void G4VisCommandViewerReset::SetNewValue (G4UIcommand*, G4String newValue) {
1264
1265  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1266
1267  G4String& resetName = newValue;
1268  G4VViewer* viewer = fpVisManager -> GetViewer (resetName);
1269  if (!viewer) {
1270    if (verbosity >= G4VisManager::errors) {
1271      G4cout << "ERROR: Viewer \"" << resetName
1272             << "\" not found - \"/vis/viewer/list\" to see possibilities."
1273             << G4endl;
1274    }
1275    return;
1276  }
1277
1278  SetViewParameters(viewer, viewer->GetDefaultViewParameters());
1279}
1280
1281////////////// /vis/viewer/scale and scaleTo ////////////////////////////
1282
1283G4VisCommandViewerScale::G4VisCommandViewerScale ():
1284  fScaleMultiplier (G4Vector3D (1., 1., 1.)),
1285  fScaleTo         (G4Vector3D (1., 1., 1.))
1286{
1287  G4bool omitable, currentAsDefault;
1288
1289  fpCommandScale = new G4UIcmdWith3Vector
1290    ("/vis/viewer/scale", this);
1291  fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling.");
1292  fpCommandScale -> SetGuidance
1293    ("Multiplies components of current scaling by components of this factor."
1294     "\n Scales (x,y,z) by corresponding components of the resulting factor.");
1295  fpCommandScale -> SetGuidance
1296    ("");
1297  fpCommandScale -> SetParameterName
1298    ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier",
1299     omitable=true, currentAsDefault=true);
1300
1301  fpCommandScaleTo = new G4UIcmdWith3Vector
1302    ("/vis/viewer/scaleTo", this);
1303  fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling.");
1304  fpCommandScaleTo -> SetGuidance
1305    ("Scales (x,y,z) by corresponding components of this factor.");
1306  fpCommandScaleTo -> SetParameterName
1307    ("x-scale-factor","y-scale-factor","z-scale-factor",
1308     omitable=true, currentAsDefault=true);
1309}
1310
1311G4VisCommandViewerScale::~G4VisCommandViewerScale () {
1312  delete fpCommandScale;
1313  delete fpCommandScaleTo;
1314}
1315
1316G4String G4VisCommandViewerScale::GetCurrentValue (G4UIcommand* command) {
1317  G4String currentValue;
1318  if (command == fpCommandScale) {
1319    currentValue = fpCommandScale->ConvertToString(G4ThreeVector(fScaleMultiplier));
1320  }
1321  else if (command == fpCommandScaleTo) {
1322    currentValue = fpCommandScaleTo->ConvertToString(G4ThreeVector(fScaleTo));
1323  }
1324  return currentValue;
1325}
1326
1327void G4VisCommandViewerScale::SetNewValue (G4UIcommand* command,
1328                                           G4String newValue) {
1329
1330
1331  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1332
1333  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1334  if (!currentViewer) {
1335    if (verbosity >= G4VisManager::errors) {
1336      G4cout <<
1337        "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer."
1338             << G4endl;
1339    }
1340    return;
1341  }
1342
1343  G4ViewParameters vp = currentViewer->GetViewParameters();
1344
1345  if (command == fpCommandScale) {
1346    fScaleMultiplier = fpCommandScale->GetNew3VectorValue(newValue);
1347    vp.MultiplyScaleFactor(fScaleMultiplier);
1348  }
1349  else if (command == fpCommandScaleTo) {
1350    fScaleTo = fpCommandScale->GetNew3VectorValue(newValue);
1351    vp.SetScaleFactor(fScaleTo);
1352  }
1353
1354  if (verbosity >= G4VisManager::confirmations) {
1355    G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl;
1356  }
1357
1358  SetViewParameters(currentViewer, vp);
1359}
1360
1361////////////// /vis/viewer/select ///////////////////////////////////////
1362
1363G4VisCommandViewerSelect::G4VisCommandViewerSelect () {
1364  G4bool omitable;
1365  fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this);
1366  fpCommand -> SetGuidance ("Selects viewer.");
1367  fpCommand -> SetGuidance
1368    ("Specify viewer by name.  \"/vis/viewer/list\" to see possible viewers.");
1369  fpCommand -> SetParameterName ("viewer-name", omitable = false);
1370}
1371
1372G4VisCommandViewerSelect::~G4VisCommandViewerSelect () {
1373  delete fpCommand;
1374}
1375
1376G4String G4VisCommandViewerSelect::GetCurrentValue (G4UIcommand*) {
1377  return "";
1378}
1379
1380void G4VisCommandViewerSelect::SetNewValue (G4UIcommand*, G4String newValue) {
1381
1382  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1383
1384  G4String& selectName = newValue;
1385  G4VViewer* viewer = fpVisManager -> GetViewer (selectName);
1386
1387  if (!viewer) {
1388    if (verbosity >= G4VisManager::errors) {
1389      G4cout << "ERROR: Viewer \"" << selectName << "\"";
1390      G4cout << " not found - \"/vis/viewer/list\""
1391        "\n  to see possibilities."
1392             << G4endl;
1393    }
1394    return;
1395  }
1396
1397  if (viewer == fpVisManager -> GetCurrentViewer ()) {
1398    if (verbosity >= G4VisManager::warnings) {
1399      G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\""
1400             << " already selected." << G4endl;
1401    }
1402    return;
1403  }
1404
1405  fpVisManager -> SetCurrentViewer (viewer);  // Prints confirmation.
1406
1407  SetViewParameters(viewer, viewer->GetViewParameters());
1408}
1409
1410////////////// /vis/viewer/update ///////////////////////////////////////
1411
1412G4VisCommandViewerUpdate::G4VisCommandViewerUpdate () {
1413  G4bool omitable, currentAsDefault;
1414  fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this);
1415  fpCommand -> SetGuidance
1416    ("Triggers graphical database post-processing for viewers"
1417     "\nusing that technique.");
1418  fpCommand -> SetGuidance
1419    ("For such viewers the view only becomes visible with this command."
1420     "\nBy default, acts on current viewer.  \"/vis/viewer/list\""
1421     "\nto see possible viewers.  Viewer becomes current.");
1422  fpCommand -> SetParameterName ("viewer-name",
1423                                 omitable = true,
1424                                 currentAsDefault = true);
1425}
1426
1427G4VisCommandViewerUpdate::~G4VisCommandViewerUpdate () {
1428  delete fpCommand;
1429}
1430
1431G4String G4VisCommandViewerUpdate::GetCurrentValue (G4UIcommand*) {
1432  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1433  if (viewer) {
1434    return viewer -> GetName ();
1435  }
1436  else {
1437    return "none";
1438  }
1439}
1440
1441void G4VisCommandViewerUpdate::SetNewValue (G4UIcommand*, G4String newValue) {
1442
1443  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1444
1445  G4String& updateName = newValue;
1446
1447  G4VViewer* viewer = fpVisManager -> GetViewer (updateName);
1448  if (!viewer) {
1449    if (verbosity >= G4VisManager::errors) {
1450      G4cout <<
1451        "ERROR: G4VisCommandsViewerUpdate::SetNewValue: no current viewer."
1452             << G4endl;
1453    }
1454    return;
1455  }
1456
1457  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1458  if (!sceneHandler) {
1459    if (verbosity >= G4VisManager::errors) {
1460      G4cout << "ERROR: Viewer \"" << updateName << "\"" <<
1461        " has no scene handler - report serious bug."
1462             << G4endl;
1463    }
1464    return;
1465  }
1466
1467  G4Scene* scene = sceneHandler->GetScene();
1468  if (!scene) {
1469    if (verbosity >= G4VisManager::confirmations) {
1470      G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
1471             << "\", to which viewer \"" << updateName << "\"" <<
1472        "\n  is attached, has no scene - \"/vis/scene/create\" and"
1473        " \"/vis/sceneHandler/attach\""
1474        "\n  (or use compound command \"/vis/drawVolume\")."
1475             << G4endl;
1476    }
1477    return;
1478  }
1479
1480  if (viewer) {
1481    if (verbosity >= G4VisManager::confirmations) {
1482      G4cout << "Viewer \"" << viewer -> GetName () << "\"";
1483      G4cout << " post-processing triggered." << G4endl;
1484    }
1485    viewer -> ShowView ();
1486    // Assume future need to "refresh" transients...
1487    sceneHandler -> SetMarkForClearingTransientStore(true);
1488  }
1489  else {
1490    if (verbosity >= G4VisManager::errors) {
1491      G4cout << "ERROR: Viewer \"" << updateName << "\"";
1492      G4cout << " not found - \"/vis/viewer/list\""
1493        "\n  to see possibilities." << G4endl;
1494    }
1495  }
1496}
1497
1498////////////// /vis/viewer/zoom and zoomTo ////////////////////////////
1499
1500G4VisCommandViewerZoom::G4VisCommandViewerZoom ():
1501  fZoomMultiplier (1.),
1502  fZoomTo         (1.)
1503{
1504  G4bool omitable, currentAsDefault;
1505
1506  fpCommandZoom = new G4UIcmdWithADouble
1507    ("/vis/viewer/zoom", this);
1508  fpCommandZoom -> SetGuidance ("Incremental zoom.");
1509  fpCommandZoom -> SetGuidance
1510    ("Multiplies current magnification by this factor.");
1511  fpCommandZoom -> SetParameterName("multiplier",
1512                                     omitable=true,
1513                                     currentAsDefault=true);
1514
1515  fpCommandZoomTo = new G4UIcmdWithADouble
1516    ("/vis/viewer/zoomTo", this);
1517  fpCommandZoomTo -> SetGuidance ("Absolute zoom.");
1518  fpCommandZoomTo -> SetGuidance
1519    ("Magnifies standard magnification by this factor.");
1520  fpCommandZoomTo -> SetParameterName("factor",
1521                                       omitable=true,
1522                                       currentAsDefault=true);
1523}
1524
1525G4VisCommandViewerZoom::~G4VisCommandViewerZoom () {
1526  delete fpCommandZoom;
1527  delete fpCommandZoomTo;
1528}
1529
1530G4String G4VisCommandViewerZoom::GetCurrentValue (G4UIcommand* command) {
1531  G4String currentValue;
1532  if (command == fpCommandZoom) {
1533    currentValue = fpCommandZoom->ConvertToString(fZoomMultiplier);
1534  }
1535  else if (command == fpCommandZoomTo) {
1536    currentValue = fpCommandZoomTo->ConvertToString(fZoomTo);
1537  }
1538  return currentValue;
1539}
1540
1541void G4VisCommandViewerZoom::SetNewValue (G4UIcommand* command,
1542                                          G4String newValue) {
1543
1544
1545  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1546
1547  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1548  if (!currentViewer) {
1549    if (verbosity >= G4VisManager::errors) {
1550      G4cout <<
1551        "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer."
1552             << G4endl;
1553    }
1554    return;
1555  }
1556
1557  G4ViewParameters vp = currentViewer->GetViewParameters();
1558
1559  if (command == fpCommandZoom) {
1560    fZoomMultiplier = fpCommandZoom->GetNewDoubleValue(newValue);
1561    vp.MultiplyZoomFactor(fZoomMultiplier);
1562  }
1563  else if (command == fpCommandZoomTo) {
1564    fZoomTo = fpCommandZoom->GetNewDoubleValue(newValue);
1565    vp.SetZoomFactor(fZoomTo);
1566  }
1567
1568  if (verbosity >= G4VisManager::confirmations) {
1569    G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl;
1570  }
1571
1572  SetViewParameters(currentViewer, vp);
1573}
1574
1575/* Keep from :
1576 * ftp://ftp.trolltech.com/qt/source/qt-embedded-free-3.0.6.tar.gz/qt-embedded-free-3.0.6/src/kernel/qapplication_qws.cpp
1577 *
1578 *    ParseGeometry parses strings of the form
1579 *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
1580 *   width, height, xoffset, and yoffset are unsigned integers.
1581 *   Example:  "=80x24+300-49"
1582 *   The equal sign is optional.
1583 *   It returns a bitmask that indicates which of the four values
1584 *   were actually found in the string. For each value found,
1585 *   the corresponding argument is updated;  for each value
1586 *   not found, the corresponding argument is left unchanged.
1587 */
1588
1589
1590int G4VisCommandViewerCreate::ParseGeometry (
1591 const char *string,
1592 int *x,
1593 int *y,
1594 unsigned int *width,
1595 unsigned int *height)
1596{
1597
1598  int mask = NoValue;
1599  register char *strind;
1600  unsigned int tempWidth, tempHeight;
1601  int tempX, tempY;
1602  char *nextCharacter;
1603  if ( (string == NULL) || (*string == '\0')) {
1604    return(mask);
1605  }
1606  if (*string == '=')
1607    string++;  /* ignore possible '=' at beg of geometry spec */
1608  strind = (char *)string;
1609  if (*strind != '+' && *strind != '-' && *strind != 'x') {
1610    tempWidth = ReadInteger(strind, &nextCharacter);
1611    if (strind == nextCharacter)
1612      return (0);
1613    strind = nextCharacter;
1614    mask |= WidthValue;
1615  }
1616  if (*strind == 'x' || *strind == 'X') {
1617    strind++;
1618    tempHeight = ReadInteger(strind, &nextCharacter);
1619    if (strind == nextCharacter)
1620      return (0);
1621    strind = nextCharacter;
1622    mask |= HeightValue;
1623  }
1624
1625  if ((*strind == '+') || (*strind == '-')) {
1626    if (*strind == '-') {
1627      strind++;
1628      tempX = -ReadInteger(strind, &nextCharacter);
1629      if (strind == nextCharacter)
1630        return (0);
1631      strind = nextCharacter;
1632      mask |= XNegative;
1633
1634    }
1635    else
1636      { strind++;
1637        tempX = ReadInteger(strind, &nextCharacter);
1638        if (strind == nextCharacter)
1639          return(0);
1640        strind = nextCharacter;
1641      }
1642    mask |= XValue;
1643    if ((*strind == '+') || (*strind == '-')) {
1644      if (*strind == '-') {
1645        strind++;
1646        tempY = -ReadInteger(strind, &nextCharacter);
1647        if (strind == nextCharacter)
1648          return(0);
1649        strind = nextCharacter;
1650        mask |= YNegative;
1651      }
1652      else
1653        {
1654          strind++;
1655          tempY = ReadInteger(strind, &nextCharacter);
1656          if (strind == nextCharacter)
1657            return(0);
1658          strind = nextCharacter;
1659        }
1660      mask |= YValue;
1661    }
1662  }
1663  /* If strind isn't at the end of the string the it's an invalid
1664     geometry specification. */
1665  if (*strind != '\0') return (0);
1666  if (mask & XValue)
1667    *x = tempX;
1668  if (mask & YValue)
1669    *y = tempY;
1670  if (mask & WidthValue)
1671    *width = tempWidth;
1672  if (mask & HeightValue)
1673    *height = tempHeight;
1674  return (mask);
1675}
1676
1677/* Keep from :
1678 * ftp://ftp.trolltech.com/qt/source/qt-embedded-free-3.0.6.tar.gz/qt-embedded-free-3.0.6/src/kernel/qapplication_qws.cpp
1679 *
1680 */
1681int G4VisCommandViewerCreate::ReadInteger(char *string, char **NextString)
1682{
1683    register int Result = 0;
1684    int Sign = 1;
1685
1686    if (*string == '+')
1687        string++;
1688    else if (*string == '-')
1689    {
1690        string++;
1691        Sign = -1;
1692    }
1693    for (; (*string >= '0') && (*string <= '9'); string++)
1694    {
1695        Result = (Result * 10) + (*string - '0');
1696    }
1697    *NextString = string;
1698    if (Sign >= 0)
1699        return (Result);
1700    else
1701        return (-Result);
1702}
Note: See TracBrowser for help on using the repository browser.