Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VtkMessenger.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25
26#include "G4VtkMessenger.hh"
27#include "G4VtkViewer.hh"
28
29#include "G4UIdirectory.hh"
30#include "G4UIcmdWithABool.hh"
31#include "G4UIcmdWithAString.hh"
33#include "G4UIcommand.hh"
34#include "G4Tokenizer.hh"
35
36#include "G4VisManager.hh"
37
38#include "vtkObject.h"
39
40G4VtkMessenger* G4VtkMessenger::fpInstance = nullptr;
41
43{
44 if (!fpInstance) fpInstance = new G4VtkMessenger;
45 return fpInstance;
46}
47
48G4VtkMessenger::G4VtkMessenger() {
49 G4bool omitable;
50
51 fpDirectory = new G4UIdirectory("/vis/vtk/");
52 fpDirectory->SetGuidance("G4VtkViewer commands.");
53
54 // Export command
55 fpCommandExport = new G4UIcommand("/vis/vtk/export", this);
56 fpCommandExport->SetGuidance ("Export a screenshot or OBJ file of current Vtk viewer");
57
58 // File type for export
59 auto parameterExport = new G4UIparameter ("name", 's', omitable = true);
60 fpCommandExport->SetGuidance ("File type (jpg,tiff,eps,ps,obj,vrml)");
61 fpCommandExport->SetParameter(parameterExport);
62
63 // File name for export
64 parameterExport = new G4UIparameter ("name", 's', omitable = true);
65 fpCommandExport->SetGuidance ("File name");
66 fpCommandExport->SetParameter(parameterExport);
67
68 // Vtk warnings output
69 fpCommandWarnings = new G4UIcmdWithABool("/vis/vtk/warnings", this);
70 fpCommandExport->SetGuidance ("Enable (True) or disable (False) VTK warnings");
71}
72
74{
75 delete fpDirectory;
76 delete fpCommandExport;
77 delete fpCommandWarnings;
78}
80 return G4String();
81}
82
84{
85
87
88 G4VViewer* pViewer = pVisManager->GetCurrentViewer();
89 if (!pViewer) {
90 G4cout << "G4VtkMessenger::SetNewValue: No current viewer.\n"
91 << "\"/vis/open\", or similar, to get one."
92 << G4endl;
93 return;
94 }
95
96 auto* pVtkViewer = dynamic_cast<G4VtkViewer*>(pViewer);
97 if (!pVtkViewer) {
98 G4cout << "G4VtkMessenger::SetNewValue: Current viewer is not of type VTK. \n"
99 << "(It is \""
100 << pViewer->GetName()
101 << "\".)\n"
102 << "Use \"/vis/viewer/select\" or \"/vis/open\"."
103 << G4endl;
104 return;
105 }
106
107 if (command == fpCommandExport)
108 {
109 G4String format, name;
110
111 std::istringstream iss(newValue);
112 iss >> format >> name;
113
114 if(format == "jpg" || format == "tiff" ||
115 format == "png" || format == "bmp" ||
116 format == "pnm" || format == "ps")
117 pVtkViewer->ExportScreenShot(name, format);
118 else if(format == "obj")
119 pVtkViewer->ExportOBJScene(name);
120 else if(format == "vrml")
121 pVtkViewer->ExportVRMLScene(name);
122 else if(format == "vtp")
123 pVtkViewer->ExportVTPScene(name);
124 else
125 G4cout << "Unknown /vis/vtk/export file format" << G4endl;
126 }
127 else if (command == fpCommandWarnings)
128 {
129 vtkObject::GlobalWarningDisplayOff();
130 }
131}
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:157
const G4String & GetName() const
G4VViewer * GetCurrentViewer() const
static G4VisManager * GetInstance()
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
virtual G4String GetCurrentValue(G4UIcommand *command)
static G4VtkMessenger * GetInstance()
virtual ~G4VtkMessenger()