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

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

make 3.80 added because 3.81 is bad

  • Property svn:mime-type set to text/cpp
File size: 53.8 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  // WindowSizeHint and XGeometryString are picked up from the vis
688  // manager in the G4VViewer constructor.  They have to be held by
689  // the vis manager until the viewer is contructed - next line...
690
691  ////////
692
693  int x,y = 0;
694  unsigned int w,h = 0;
695
696  int m = ParseGeometry( windowSizeHintString, &x, &y, &w, &h );
697  //  QSize minSize = main_widget->minimumSize();
698  //  QSize maxSize = main_widget->maximumSize();
699  if ( ((m & YValue) == 0) ||
700       ((m & XValue) == 0) ||
701       ((m & HeightValue) == 0 ) ||
702       ((m & WidthValue)  == 0 )) {
703    if (verbosity >= G4VisManager::errors) {
704      G4cout << "ERROR: Unrecognised geometry string \""
705             << windowSizeHintString
706             << "\".  Using 100 for X and Y location."
707             << "\".  Using 600 for Width and Height."
708             << G4endl;
709    }
710    x = 100;
711    y = 100;
712    w = 600;
713    h = 600;
714  }
715
716#ifdef G4DEBUG
717  printf  ("Lecture X:%d Y:%d W:%d H:%d\n",x,y,w,h);
718#endif
719
720
721  // Create viewer.
722  fpVisManager -> CreateViewer (newName);
723
724  // set parameters AFTER
725  fpVisManager->SetWindowSizeHint (w,h);
726  fpVisManager->SetWindowLocationHint (x,y);
727  fpVisManager->SetXGeometryString(windowSizeHintString);
728  G4VViewer* newViewer = fpVisManager -> GetCurrentViewer ();
729  if (newViewer && newViewer -> GetName () == newName) {
730    if (verbosity >= G4VisManager::confirmations) {
731      G4cout << "New viewer \"" << newName << "\" created." << G4endl;
732    }
733  }
734  else {
735    if (verbosity >= G4VisManager::errors) {
736      if (newViewer) {
737        G4cout << "ERROR: New viewer doesn\'t match!!!  Curious!!" << G4endl;
738      } else {
739        G4cout << "WARNING: No viewer created." << G4endl;
740      }
741    }
742  }
743  // Refresh if appropriate...
744  if (newViewer) {
745    if (newViewer->GetViewParameters().IsAutoRefresh()) {
746      G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
747    }
748    else {
749      if (verbosity >= G4VisManager::confirmations) {
750        G4cout << "Issue /vis/viewer/refresh to see effect." << G4endl;
751      }
752    }
753  }
754}
755
756////////////// /vis/viewer/dolly and dollyTo ////////////////////////////
757
758G4VisCommandViewerDolly::G4VisCommandViewerDolly ():
759  fDollyIncrement  (0.),
760  fDollyTo (0.)
761{
762  G4bool omitable, currentAsDefault;
763
764  fpCommandDolly = new G4UIcmdWithADoubleAndUnit
765    ("/vis/viewer/dolly", this);
766  fpCommandDolly -> SetGuidance
767    ("Incremental dolly.");
768  fpCommandDolly -> SetGuidance
769    ("Moves the camera incrementally towards target point.");
770  fpCommandDolly -> SetParameterName("increment",
771                                     omitable=true,
772                                     currentAsDefault=true);
773  fpCommandDolly -> SetDefaultUnit("m");
774
775  fpCommandDollyTo = new G4UIcmdWithADoubleAndUnit
776    ("/vis/viewer/dollyTo", this);
777  fpCommandDollyTo -> SetGuidance
778    ("Dolly to specific coordinate.");
779  fpCommandDollyTo -> SetGuidance
780 ("Places the camera towards target point relative to standard camera point.");
781  fpCommandDollyTo -> SetParameterName("distance",
782                                       omitable=true,
783                                       currentAsDefault=true);
784  fpCommandDollyTo -> SetDefaultUnit("m");
785}
786
787G4VisCommandViewerDolly::~G4VisCommandViewerDolly () {
788  delete fpCommandDolly;
789  delete fpCommandDollyTo;
790}
791
792G4String G4VisCommandViewerDolly::GetCurrentValue (G4UIcommand* command) {
793  G4String currentValue;
794  if (command == fpCommandDolly) {
795    currentValue = fpCommandDolly->ConvertToString(fDollyIncrement, "m");
796  }
797  else if (command == fpCommandDollyTo) {
798    currentValue = fpCommandDollyTo->ConvertToString(fDollyTo, "m");
799  }
800  return currentValue;
801}
802
803void G4VisCommandViewerDolly::SetNewValue (G4UIcommand* command,
804                                           G4String newValue) {
805
806
807  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
808
809  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
810  if (!currentViewer) {
811    if (verbosity >= G4VisManager::errors) {
812      G4cout <<
813        "ERROR: G4VisCommandsViewerDolly::SetNewValue: no current viewer."
814             << G4endl;
815    }
816    return;
817  }
818
819  G4ViewParameters vp = currentViewer->GetViewParameters();
820
821  if (command == fpCommandDolly) {
822    fDollyIncrement = fpCommandDolly->GetNewDoubleValue(newValue);
823    vp.IncrementDolly(fDollyIncrement);
824  }
825  else if (command == fpCommandDollyTo) {
826    fDollyTo = fpCommandDolly->GetNewDoubleValue(newValue);
827    vp.SetDolly(fDollyTo);
828  }
829
830  if (verbosity >= G4VisManager::confirmations) {
831    G4cout << "Dolly distance changed to " << vp.GetDolly() << G4endl;
832  }
833
834  SetViewParameters(currentViewer, vp);
835}
836
837////////////// /vis/viewer/flush ///////////////////////////////////////
838
839G4VisCommandViewerFlush::G4VisCommandViewerFlush () {
840  G4bool omitable, currentAsDefault;
841  fpCommand = new G4UIcmdWithAString ("/vis/viewer/flush", this);
842  fpCommand -> SetGuidance
843    ("Compound command: \"/vis/viewer/refresh\" + \"/vis/viewer/update\".");
844  fpCommand -> SetGuidance
845    ("Useful for refreshing and initiating post-processing for graphics"
846     "\nsystems which need post-processing.  By default, acts on current"
847     "\nviewer.  \"/vis/viewer/list\" to see possible viewers.  Viewer"
848     "\nbecomes current.");
849  fpCommand -> SetParameterName ("viewer-name",
850                                 omitable = true,
851                                 currentAsDefault = true);
852}
853
854G4VisCommandViewerFlush::~G4VisCommandViewerFlush () {
855  delete fpCommand;
856}
857
858G4String G4VisCommandViewerFlush::GetCurrentValue
859(G4UIcommand*) {
860  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
861  return viewer ? viewer -> GetName () : G4String("none");
862}
863
864void G4VisCommandViewerFlush::SetNewValue (G4UIcommand*, G4String newValue) {
865
866  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
867
868  G4String& flushName = newValue;
869  G4VViewer* viewer = fpVisManager -> GetViewer (flushName);
870  if (!viewer) {
871    if (verbosity >= G4VisManager::errors) {
872      G4cout << "ERROR: Viewer \"" << flushName << "\"" <<
873        " not found - \"/vis/viewer/list\"\n  to see possibilities."
874             << G4endl;
875    }
876    return;
877  }
878
879  G4UImanager* ui = G4UImanager::GetUIpointer();
880  G4int keepVerbose = ui->GetVerboseLevel();
881  G4int newVerbose(0);
882  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
883    newVerbose = 2;
884  ui->SetVerboseLevel(newVerbose);
885  ui->ApplyCommand(G4String("/vis/viewer/refresh " + flushName));
886  ui->ApplyCommand(G4String("/vis/viewer/update " + flushName));
887  ui->SetVerboseLevel(keepVerbose);
888  if (verbosity >= G4VisManager::confirmations) {
889    G4cout << "Viewer \"" << viewer -> GetName () << "\""
890           << " flushed." << G4endl;
891  }
892}
893
894////////////// /vis/viewer/list ///////////////////////////////////////
895
896G4VisCommandViewerList::G4VisCommandViewerList () {
897  G4bool omitable;
898  fpCommand = new G4UIcommand ("/vis/viewer/list", this);
899  fpCommand -> SetGuidance ("Lists viewers(s).");
900  fpCommand -> SetGuidance
901    ("See \"/vis/verbose\" for definition of verbosity.");
902  G4UIparameter* parameter;
903  parameter = new G4UIparameter("viewer-name", 's',
904                                omitable = true);
905  parameter -> SetDefaultValue ("all");
906  fpCommand -> SetParameter (parameter);
907  parameter = new G4UIparameter ("verbosity", 's',
908                                 omitable = true);
909  parameter -> SetDefaultValue ("warnings");
910  fpCommand -> SetParameter (parameter);
911}
912
913G4VisCommandViewerList::~G4VisCommandViewerList () {
914  delete fpCommand;
915}
916
917G4String G4VisCommandViewerList::GetCurrentValue (G4UIcommand*) {
918  return "";
919}
920
921void G4VisCommandViewerList::SetNewValue (G4UIcommand*, G4String newValue) {
922  G4String name, verbosityString;
923  std::istringstream is (newValue);
924  is >> name >> verbosityString;
925  G4String shortName = fpVisManager -> ViewerShortName (name);
926  G4VisManager::Verbosity verbosity =
927    fpVisManager->GetVerbosityValue(verbosityString);
928
929  const G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
930  G4String currentViewerShortName;
931  if (currentViewer) {
932    currentViewerShortName = currentViewer -> GetShortName ();
933  }
934  else {
935    currentViewerShortName = "none";
936  }
937
938  const G4SceneHandlerList& sceneHandlerList = fpVisManager -> GetAvailableSceneHandlers ();
939  G4int nHandlers = sceneHandlerList.size ();
940  G4bool found = false;
941  G4bool foundCurrent = false;
942  for (int iHandler = 0; iHandler < nHandlers; iHandler++) {
943    G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
944    const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
945    G4cout << "Scene handler \"" << sceneHandler -> GetName ();
946    const G4Scene* pScene = sceneHandler -> GetScene ();
947    if (pScene) {
948      G4cout << "\", scene \"" << pScene -> GetName () << "\":";
949    }
950    G4int nViewers = viewerList.size ();
951    if (nViewers == 0) {
952      G4cout << "\n            No viewers for this scene handler." << G4endl;
953    }
954    else {
955      for (int iViewer = 0; iViewer < nViewers; iViewer++) {
956        const G4VViewer* thisViewer = viewerList [iViewer];
957        G4String thisName = thisViewer -> GetName ();
958        G4String thisShortName = thisViewer -> GetShortName ();
959        if (name != "all") {
960          if (thisShortName != shortName) continue;
961        }
962        found = true;
963        G4cout << "\n  ";
964        if (thisShortName == currentViewerShortName) {
965          foundCurrent = true;
966          G4cout << "(current)";
967        }
968        else {
969          G4cout << "         ";
970        }
971        G4cout << " viewer \"" << thisName << "\"";
972        if (verbosity >= G4VisManager::parameters) {
973          G4cout << "\n  " << *thisViewer;
974        }
975      }
976    }
977    G4cout << G4endl;
978  }
979
980  if (!foundCurrent) {
981    G4cout << "No valid current viewer - please create or select one."
982           << G4endl;
983  }
984
985  if (!found) {
986    G4cout << "No viewers";
987    if (name != "all") {
988      G4cout << " of name \"" << name << "\"";
989    }
990    G4cout << " found." << G4endl;
991  }
992}
993
994////////////// /vis/viewer/pan and panTo ////////////////////////////
995
996G4VisCommandViewerPan::G4VisCommandViewerPan ():
997  fPanIncrementRight  (0.),
998  fPanIncrementUp  (0.),
999  fPanToRight (0.),
1000  fPanToUp (0.)
1001{
1002  G4bool omitable;
1003
1004  fpCommandPan = new G4UIcommand
1005    ("/vis/viewer/pan", this);
1006  fpCommandPan -> SetGuidance
1007    ("Incremental pan.");
1008  fpCommandPan -> SetGuidance
1009    ("Moves the camera incrementally right and up by these amounts (as seen"
1010     "\nfrom viewpoint direction).");
1011  G4UIparameter* parameter;
1012  parameter = new G4UIparameter("right-increment", 'd', omitable = true);
1013  parameter -> SetCurrentAsDefault (true);
1014  fpCommandPan -> SetParameter (parameter);
1015  parameter = new G4UIparameter("up-increment", 'd', omitable = true);
1016  parameter -> SetCurrentAsDefault (true);
1017  fpCommandPan -> SetParameter (parameter);
1018  parameter = new G4UIparameter ("unit", 's', omitable = true);
1019  parameter -> SetDefaultValue ("m");
1020  fpCommandPan -> SetParameter (parameter);
1021
1022  fpCommandPanTo = new G4UIcommand
1023    ("/vis/viewer/panTo", this);
1024  fpCommandPanTo -> SetGuidance
1025    ("Pan to specific coordinate.");
1026  fpCommandPanTo -> SetGuidance
1027    ("Places the camera in this position right and up relative to standard"
1028     "\ntarget point (as seen from viewpoint direction).");
1029  parameter = new G4UIparameter("right", 'd', omitable = true);
1030  parameter -> SetCurrentAsDefault (true);
1031  fpCommandPanTo -> SetParameter (parameter);
1032  parameter = new G4UIparameter("up", 'd', omitable = true);
1033  parameter -> SetCurrentAsDefault (true);
1034  fpCommandPanTo -> SetParameter (parameter);
1035  parameter = new G4UIparameter ("unit", 's', omitable = true);
1036  parameter -> SetDefaultValue ("m");
1037  fpCommandPanTo -> SetParameter (parameter);
1038}
1039
1040G4VisCommandViewerPan::~G4VisCommandViewerPan () {
1041  delete fpCommandPan;
1042  delete fpCommandPanTo;
1043}
1044
1045G4String G4VisCommandViewerPan::GetCurrentValue (G4UIcommand* command) {
1046  G4String currentValue;
1047  if (command == fpCommandPan) {
1048    currentValue = ConvertToString(fPanIncrementRight, fPanIncrementUp, "m");
1049  }
1050  else if (command == fpCommandPanTo) {
1051    currentValue = ConvertToString(fPanToRight, fPanToUp, "m");
1052  }
1053  return currentValue;
1054}
1055
1056void G4VisCommandViewerPan::SetNewValue (G4UIcommand* command,
1057                                         G4String newValue) {
1058
1059
1060  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1061
1062  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1063  if (!currentViewer) {
1064    if (verbosity >= G4VisManager::errors) {
1065      G4cout <<
1066        "ERROR: G4VisCommandsViewerPan::SetNewValue: no current viewer."
1067             << G4endl;
1068    }
1069    return;
1070  }
1071
1072  G4ViewParameters vp = currentViewer->GetViewParameters();
1073
1074  if (command == fpCommandPan) {
1075    ConvertToDoublePair(newValue, fPanIncrementRight, fPanIncrementUp);
1076    vp.IncrementPan(fPanIncrementRight, fPanIncrementUp);
1077  }
1078  else if (command == fpCommandPanTo) {
1079    ConvertToDoublePair(newValue, fPanToRight, fPanToUp);
1080    vp.SetPan(fPanToRight, fPanToUp);
1081  }
1082
1083  if (verbosity >= G4VisManager::confirmations) {
1084    G4cout << "Current target point now " << vp.GetCurrentTargetPoint()
1085           << G4endl;
1086  }
1087
1088  SetViewParameters(currentViewer, vp);
1089}
1090
1091////////////// /vis/viewer/rebuild ///////////////////////////////////////
1092
1093G4VisCommandViewerRebuild::G4VisCommandViewerRebuild () {
1094  G4bool omitable, currentAsDefault;
1095  fpCommand = new G4UIcmdWithAString ("/vis/viewer/rebuild", this);
1096  fpCommand -> SetGuidance ("Forces rebuild of graphical database.");
1097  fpCommand -> SetGuidance
1098    ("By default, acts on current viewer.  \"/vis/viewer/list\""
1099     "\nto see possible viewers.  Viewer becomes current.");
1100  fpCommand -> SetParameterName ("viewer-name",
1101                                 omitable = true,
1102                                 currentAsDefault = true);
1103}
1104
1105G4VisCommandViewerRebuild::~G4VisCommandViewerRebuild () {
1106  delete fpCommand;
1107}
1108
1109G4String G4VisCommandViewerRebuild::GetCurrentValue (G4UIcommand*) {
1110  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1111  if (viewer) {
1112    return viewer -> GetName ();
1113  }
1114  else {
1115    return "none";
1116  }
1117}
1118
1119void G4VisCommandViewerRebuild::SetNewValue (G4UIcommand*, G4String newValue) {
1120
1121  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1122
1123  G4String& rebuildName = newValue;
1124  G4VViewer* viewer = fpVisManager -> GetViewer (rebuildName);
1125  if (!viewer) {
1126    if (verbosity >= G4VisManager::errors) {
1127      G4cout << "ERROR: Viewer \"" << rebuildName
1128             << "\" not found - \"/vis/viewer/list\" to see possibilities."
1129             << G4endl;
1130    }
1131    return;
1132  }
1133
1134  viewer->NeedKernelVisit();
1135
1136  // Check auto-refresh and print confirmations, but without changing
1137  // view paramters...
1138  SetViewParameters(viewer, viewer->GetViewParameters());
1139}
1140
1141////////////// /vis/viewer/refresh ///////////////////////////////////////
1142
1143G4VisCommandViewerRefresh::G4VisCommandViewerRefresh () {
1144  G4bool omitable, currentAsDefault;
1145  fpCommand = new G4UIcmdWithAString ("/vis/viewer/refresh", this);
1146  fpCommand -> SetGuidance
1147    ("Refreshes viewer.");
1148  fpCommand -> SetGuidance
1149    ("By default, acts on current viewer.  \"/vis/viewer/list\""
1150     "\nto see possible viewers.  Viewer becomes current.");
1151  fpCommand -> SetParameterName ("viewer-name",
1152                                 omitable = true,
1153                                 currentAsDefault = true);
1154}
1155
1156G4VisCommandViewerRefresh::~G4VisCommandViewerRefresh () {
1157  delete fpCommand;
1158}
1159
1160G4String G4VisCommandViewerRefresh::GetCurrentValue (G4UIcommand*) {
1161  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1162  return viewer ? viewer -> GetName () : G4String("none");
1163}
1164
1165void G4VisCommandViewerRefresh::SetNewValue (G4UIcommand*, G4String newValue) {
1166
1167  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1168  G4bool warn(verbosity >= G4VisManager::warnings);
1169
1170  G4String& refreshName = newValue;
1171  G4VViewer* viewer = fpVisManager -> GetViewer (refreshName);
1172  if (!viewer) {
1173    if (verbosity >= G4VisManager::errors) {
1174      G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
1175        " not found - \"/vis/viewer/list\"\n  to see possibilities."
1176             << G4endl;
1177    }
1178    return;
1179  }
1180
1181  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1182  if (!sceneHandler) {
1183    if (verbosity >= G4VisManager::errors) {
1184      G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
1185        " has no scene handler - report serious bug."
1186             << G4endl;
1187    }
1188    return;
1189  }
1190
1191  G4Scene* scene = sceneHandler->GetScene();
1192  if (!scene) {
1193    if (verbosity >= G4VisManager::confirmations) {
1194      G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
1195             << "\", to which viewer \"" << refreshName << "\"" <<
1196        "\n  is attached, has no scene - \"/vis/scene/create\" and"
1197        " \"/vis/sceneHandler/attach\""
1198        "\n  (or use compound command \"/vis/drawVolume\")."
1199             << G4endl;
1200    }
1201    return;
1202  }
1203  if (scene->GetRunDurationModelList().empty()) {
1204    G4bool successful = scene -> AddWorldIfEmpty (warn);
1205    if (!successful) {
1206      if (verbosity >= G4VisManager::warnings) {
1207        G4cout <<
1208          "WARNING: Scene is empty.  Perhaps no geometry exists."
1209          "\n  Try /run/initialize."
1210               << G4endl;
1211      }
1212      return;
1213    }
1214    // Scene has changed.  UpdateVisManagerScene issues
1215    // /vis/scene/notifyHandlers, which does a refresh anyway, so the
1216    // ordinary refresh becomes part of the else phrase...
1217    UpdateVisManagerScene(scene->GetName());
1218  } else {
1219    if (verbosity >= G4VisManager::confirmations) {
1220      G4cout << "Refreshing viewer \"" << viewer -> GetName () << "\"..."
1221             << G4endl;
1222    }
1223    viewer -> SetView ();
1224    viewer -> ClearView ();
1225    viewer -> DrawView ();
1226    if (verbosity >= G4VisManager::confirmations) {
1227      G4cout << "Viewer \"" << viewer -> GetName () << "\"" << " refreshed."
1228        "\n  (You might also need \"/vis/viewer/update\".)" << G4endl;
1229    }
1230  }
1231}
1232
1233////////////// /vis/viewer/reset ///////////////////////////////////////
1234
1235G4VisCommandViewerReset::G4VisCommandViewerReset () {
1236  G4bool omitable, currentAsDefault;
1237  fpCommand = new G4UIcmdWithAString ("/vis/viewer/reset", this);
1238  fpCommand -> SetGuidance ("Resets viewer.");
1239  fpCommand -> SetGuidance
1240    ("By default, acts on current viewer.  \"/vis/viewer/list\""
1241     "\nto see possible viewers.  Viewer becomes current.");
1242  fpCommand -> SetParameterName ("viewer-name",
1243                                 omitable = true,
1244                                 currentAsDefault = true);
1245}
1246
1247G4VisCommandViewerReset::~G4VisCommandViewerReset () {
1248  delete fpCommand;
1249}
1250
1251G4String G4VisCommandViewerReset::GetCurrentValue (G4UIcommand*) {
1252  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1253  if (viewer) {
1254    return viewer -> GetName ();
1255  }
1256  else {
1257    return "none";
1258  }
1259}
1260
1261void G4VisCommandViewerReset::SetNewValue (G4UIcommand*, G4String newValue) {
1262
1263  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1264
1265  G4String& resetName = newValue;
1266  G4VViewer* viewer = fpVisManager -> GetViewer (resetName);
1267  if (!viewer) {
1268    if (verbosity >= G4VisManager::errors) {
1269      G4cout << "ERROR: Viewer \"" << resetName
1270             << "\" not found - \"/vis/viewer/list\" to see possibilities."
1271             << G4endl;
1272    }
1273    return;
1274  }
1275
1276  SetViewParameters(viewer, viewer->GetDefaultViewParameters());
1277}
1278
1279////////////// /vis/viewer/scale and scaleTo ////////////////////////////
1280
1281G4VisCommandViewerScale::G4VisCommandViewerScale ():
1282  fScaleMultiplier (G4Vector3D (1., 1., 1.)),
1283  fScaleTo         (G4Vector3D (1., 1., 1.))
1284{
1285  G4bool omitable, currentAsDefault;
1286
1287  fpCommandScale = new G4UIcmdWith3Vector
1288    ("/vis/viewer/scale", this);
1289  fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling.");
1290  fpCommandScale -> SetGuidance
1291    ("Multiplies components of current scaling by components of this factor."
1292     "\n Scales (x,y,z) by corresponding components of the resulting factor.");
1293  fpCommandScale -> SetGuidance
1294    ("");
1295  fpCommandScale -> SetParameterName
1296    ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier",
1297     omitable=true, currentAsDefault=true);
1298
1299  fpCommandScaleTo = new G4UIcmdWith3Vector
1300    ("/vis/viewer/scaleTo", this);
1301  fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling.");
1302  fpCommandScaleTo -> SetGuidance
1303    ("Scales (x,y,z) by corresponding components of this factor.");
1304  fpCommandScaleTo -> SetParameterName
1305    ("x-scale-factor","y-scale-factor","z-scale-factor",
1306     omitable=true, currentAsDefault=true);
1307}
1308
1309G4VisCommandViewerScale::~G4VisCommandViewerScale () {
1310  delete fpCommandScale;
1311  delete fpCommandScaleTo;
1312}
1313
1314G4String G4VisCommandViewerScale::GetCurrentValue (G4UIcommand* command) {
1315  G4String currentValue;
1316  if (command == fpCommandScale) {
1317    currentValue = fpCommandScale->ConvertToString(G4ThreeVector(fScaleMultiplier));
1318  }
1319  else if (command == fpCommandScaleTo) {
1320    currentValue = fpCommandScaleTo->ConvertToString(G4ThreeVector(fScaleTo));
1321  }
1322  return currentValue;
1323}
1324
1325void G4VisCommandViewerScale::SetNewValue (G4UIcommand* command,
1326                                           G4String newValue) {
1327
1328
1329  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1330
1331  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1332  if (!currentViewer) {
1333    if (verbosity >= G4VisManager::errors) {
1334      G4cout <<
1335        "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer."
1336             << G4endl;
1337    }
1338    return;
1339  }
1340
1341  G4ViewParameters vp = currentViewer->GetViewParameters();
1342
1343  if (command == fpCommandScale) {
1344    fScaleMultiplier = fpCommandScale->GetNew3VectorValue(newValue);
1345    vp.MultiplyScaleFactor(fScaleMultiplier);
1346  }
1347  else if (command == fpCommandScaleTo) {
1348    fScaleTo = fpCommandScale->GetNew3VectorValue(newValue);
1349    vp.SetScaleFactor(fScaleTo);
1350  }
1351
1352  if (verbosity >= G4VisManager::confirmations) {
1353    G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl;
1354  }
1355
1356  SetViewParameters(currentViewer, vp);
1357}
1358
1359////////////// /vis/viewer/select ///////////////////////////////////////
1360
1361G4VisCommandViewerSelect::G4VisCommandViewerSelect () {
1362  G4bool omitable;
1363  fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this);
1364  fpCommand -> SetGuidance ("Selects viewer.");
1365  fpCommand -> SetGuidance
1366    ("Specify viewer by name.  \"/vis/viewer/list\" to see possible viewers.");
1367  fpCommand -> SetParameterName ("viewer-name", omitable = false);
1368}
1369
1370G4VisCommandViewerSelect::~G4VisCommandViewerSelect () {
1371  delete fpCommand;
1372}
1373
1374G4String G4VisCommandViewerSelect::GetCurrentValue (G4UIcommand*) {
1375  return "";
1376}
1377
1378void G4VisCommandViewerSelect::SetNewValue (G4UIcommand*, G4String newValue) {
1379
1380  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1381
1382  G4String& selectName = newValue;
1383  G4VViewer* viewer = fpVisManager -> GetViewer (selectName);
1384
1385  if (!viewer) {
1386    if (verbosity >= G4VisManager::errors) {
1387      G4cout << "ERROR: Viewer \"" << selectName << "\"";
1388      G4cout << " not found - \"/vis/viewer/list\""
1389        "\n  to see possibilities."
1390             << G4endl;
1391    }
1392    return;
1393  }
1394
1395  if (viewer == fpVisManager -> GetCurrentViewer ()) {
1396    if (verbosity >= G4VisManager::warnings) {
1397      G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\""
1398             << " already selected." << G4endl;
1399    }
1400    return;
1401  }
1402
1403  fpVisManager -> SetCurrentViewer (viewer);  // Prints confirmation.
1404
1405  SetViewParameters(viewer, viewer->GetViewParameters());
1406}
1407
1408////////////// /vis/viewer/update ///////////////////////////////////////
1409
1410G4VisCommandViewerUpdate::G4VisCommandViewerUpdate () {
1411  G4bool omitable, currentAsDefault;
1412  fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this);
1413  fpCommand -> SetGuidance
1414    ("Triggers graphical database post-processing for viewers"
1415     "\nusing that technique.");
1416  fpCommand -> SetGuidance
1417    ("For such viewers the view only becomes visible with this command."
1418     "\nBy default, acts on current viewer.  \"/vis/viewer/list\""
1419     "\nto see possible viewers.  Viewer becomes current.");
1420  fpCommand -> SetParameterName ("viewer-name",
1421                                 omitable = true,
1422                                 currentAsDefault = true);
1423}
1424
1425G4VisCommandViewerUpdate::~G4VisCommandViewerUpdate () {
1426  delete fpCommand;
1427}
1428
1429G4String G4VisCommandViewerUpdate::GetCurrentValue (G4UIcommand*) {
1430  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1431  if (viewer) {
1432    return viewer -> GetName ();
1433  }
1434  else {
1435    return "none";
1436  }
1437}
1438
1439void G4VisCommandViewerUpdate::SetNewValue (G4UIcommand*, G4String newValue) {
1440
1441  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1442
1443  G4String& updateName = newValue;
1444
1445  G4VViewer* viewer = fpVisManager -> GetViewer (updateName);
1446  if (!viewer) {
1447    if (verbosity >= G4VisManager::errors) {
1448      G4cout <<
1449        "ERROR: G4VisCommandsViewerUpdate::SetNewValue: no current viewer."
1450             << G4endl;
1451    }
1452    return;
1453  }
1454
1455  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1456  if (!sceneHandler) {
1457    if (verbosity >= G4VisManager::errors) {
1458      G4cout << "ERROR: Viewer \"" << updateName << "\"" <<
1459        " has no scene handler - report serious bug."
1460             << G4endl;
1461    }
1462    return;
1463  }
1464
1465  G4Scene* scene = sceneHandler->GetScene();
1466  if (!scene) {
1467    if (verbosity >= G4VisManager::confirmations) {
1468      G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
1469             << "\", to which viewer \"" << updateName << "\"" <<
1470        "\n  is attached, has no scene - \"/vis/scene/create\" and"
1471        " \"/vis/sceneHandler/attach\""
1472        "\n  (or use compound command \"/vis/drawVolume\")."
1473             << G4endl;
1474    }
1475    return;
1476  }
1477
1478  if (viewer) {
1479    if (verbosity >= G4VisManager::confirmations) {
1480      G4cout << "Viewer \"" << viewer -> GetName () << "\"";
1481      G4cout << " post-processing triggered." << G4endl;
1482    }
1483    viewer -> ShowView ();
1484    // Assume future need to "refresh" transients...
1485    sceneHandler -> SetMarkForClearingTransientStore(true);
1486  }
1487  else {
1488    if (verbosity >= G4VisManager::errors) {
1489      G4cout << "ERROR: Viewer \"" << updateName << "\"";
1490      G4cout << " not found - \"/vis/viewer/list\""
1491        "\n  to see possibilities." << G4endl;
1492    }
1493  }
1494}
1495
1496////////////// /vis/viewer/zoom and zoomTo ////////////////////////////
1497
1498G4VisCommandViewerZoom::G4VisCommandViewerZoom ():
1499  fZoomMultiplier (1.),
1500  fZoomTo         (1.)
1501{
1502  G4bool omitable, currentAsDefault;
1503
1504  fpCommandZoom = new G4UIcmdWithADouble
1505    ("/vis/viewer/zoom", this);
1506  fpCommandZoom -> SetGuidance ("Incremental zoom.");
1507  fpCommandZoom -> SetGuidance
1508    ("Multiplies current magnification by this factor.");
1509  fpCommandZoom -> SetParameterName("multiplier",
1510                                     omitable=true,
1511                                     currentAsDefault=true);
1512
1513  fpCommandZoomTo = new G4UIcmdWithADouble
1514    ("/vis/viewer/zoomTo", this);
1515  fpCommandZoomTo -> SetGuidance ("Absolute zoom.");
1516  fpCommandZoomTo -> SetGuidance
1517    ("Magnifies standard magnification by this factor.");
1518  fpCommandZoomTo -> SetParameterName("factor",
1519                                       omitable=true,
1520                                       currentAsDefault=true);
1521}
1522
1523G4VisCommandViewerZoom::~G4VisCommandViewerZoom () {
1524  delete fpCommandZoom;
1525  delete fpCommandZoomTo;
1526}
1527
1528G4String G4VisCommandViewerZoom::GetCurrentValue (G4UIcommand* command) {
1529  G4String currentValue;
1530  if (command == fpCommandZoom) {
1531    currentValue = fpCommandZoom->ConvertToString(fZoomMultiplier);
1532  }
1533  else if (command == fpCommandZoomTo) {
1534    currentValue = fpCommandZoomTo->ConvertToString(fZoomTo);
1535  }
1536  return currentValue;
1537}
1538
1539void G4VisCommandViewerZoom::SetNewValue (G4UIcommand* command,
1540                                          G4String newValue) {
1541
1542
1543  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1544
1545  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1546  if (!currentViewer) {
1547    if (verbosity >= G4VisManager::errors) {
1548      G4cout <<
1549        "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer."
1550             << G4endl;
1551    }
1552    return;
1553  }
1554
1555  G4ViewParameters vp = currentViewer->GetViewParameters();
1556
1557  if (command == fpCommandZoom) {
1558    fZoomMultiplier = fpCommandZoom->GetNewDoubleValue(newValue);
1559    vp.MultiplyZoomFactor(fZoomMultiplier);
1560  }
1561  else if (command == fpCommandZoomTo) {
1562    fZoomTo = fpCommandZoom->GetNewDoubleValue(newValue);
1563    vp.SetZoomFactor(fZoomTo);
1564  }
1565
1566  if (verbosity >= G4VisManager::confirmations) {
1567    G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl;
1568  }
1569
1570  SetViewParameters(currentViewer, vp);
1571}
1572
1573/* Keep from :
1574 * 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
1575 *
1576 *    ParseGeometry parses strings of the form
1577 *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
1578 *   width, height, xoffset, and yoffset are unsigned integers.
1579 *   Example:  "=80x24+300-49"
1580 *   The equal sign is optional.
1581 *   It returns a bitmask that indicates which of the four values
1582 *   were actually found in the string. For each value found,
1583 *   the corresponding argument is updated;  for each value
1584 *   not found, the corresponding argument is left unchanged.
1585 */
1586
1587
1588int G4VisCommandViewerCreate::ParseGeometry (
1589 const char *string,
1590 int *x,
1591 int *y,
1592 unsigned int *width,
1593 unsigned int *height)
1594{
1595
1596  int mask = NoValue;
1597  register char *strind;
1598  unsigned int tempWidth, tempHeight;
1599  int tempX, tempY;
1600  char *nextCharacter;
1601  if ( (string == NULL) || (*string == '\0')) {
1602    return(mask);
1603  }
1604  if (*string == '=')
1605    string++;  /* ignore possible '=' at beg of geometry spec */
1606  strind = (char *)string;
1607  if (*strind != '+' && *strind != '-' && *strind != 'x') {
1608    tempWidth = ReadInteger(strind, &nextCharacter);
1609    if (strind == nextCharacter)
1610      return (0);
1611    strind = nextCharacter;
1612    mask |= WidthValue;
1613  }
1614  if (*strind == 'x' || *strind == 'X') {
1615    strind++;
1616    tempHeight = ReadInteger(strind, &nextCharacter);
1617    if (strind == nextCharacter)
1618      return (0);
1619    strind = nextCharacter;
1620    mask |= HeightValue;
1621  }
1622
1623  if ((*strind == '+') || (*strind == '-')) {
1624    if (*strind == '-') {
1625      strind++;
1626      tempX = -ReadInteger(strind, &nextCharacter);
1627      if (strind == nextCharacter)
1628        return (0);
1629      strind = nextCharacter;
1630      mask |= XNegative;
1631
1632    }
1633    else
1634      { strind++;
1635        tempX = ReadInteger(strind, &nextCharacter);
1636        if (strind == nextCharacter)
1637          return(0);
1638        strind = nextCharacter;
1639      }
1640    mask |= XValue;
1641    if ((*strind == '+') || (*strind == '-')) {
1642      if (*strind == '-') {
1643        strind++;
1644        tempY = -ReadInteger(strind, &nextCharacter);
1645        if (strind == nextCharacter)
1646          return(0);
1647        strind = nextCharacter;
1648        mask |= YNegative;
1649      }
1650      else
1651        {
1652          strind++;
1653          tempY = ReadInteger(strind, &nextCharacter);
1654          if (strind == nextCharacter)
1655            return(0);
1656          strind = nextCharacter;
1657        }
1658      mask |= YValue;
1659    }
1660  }
1661  /* If strind isn't at the end of the string the it's an invalid
1662     geometry specification. */
1663  if (*strind != '\0') return (0);
1664  if (mask & XValue)
1665    *x = tempX;
1666  if (mask & YValue)
1667    *y = tempY;
1668  if (mask & WidthValue)
1669    *width = tempWidth;
1670  if (mask & HeightValue)
1671    *height = tempHeight;
1672  return (mask);
1673}
1674
1675/* Keep from :
1676 * 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
1677 *
1678 */
1679int G4VisCommandViewerCreate::ReadInteger(char *string, char **NextString)
1680{
1681    register int Result = 0;
1682    int Sign = 1;
1683
1684    if (*string == '+')
1685        string++;
1686    else if (*string == '-')
1687    {
1688        string++;
1689        Sign = -1;
1690    }
1691    for (; (*string >= '0') && (*string <= '9'); string++)
1692    {
1693        Result = (Result * 10) + (*string - '0');
1694    }
1695    *NextString = string;
1696    if (Sign >= 0)
1697        return (Result);
1698    else
1699        return (-Result);
1700}
Note: See TracBrowser for help on using the repository browser.