Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenGLViewerMessenger Class Reference

#include <G4OpenGLViewerMessenger.hh>

+ Inheritance diagram for G4OpenGLViewerMessenger:

Public Member Functions

 ~G4OpenGLViewerMessenger ()
 
void SetNewValue (G4UIcommand *, G4String)
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()=default
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
G4bool CommandsShouldBeInMaster () const
 

Static Public Member Functions

static G4OpenGLViewerMessengerGetInstance ()
 

Additional Inherited Members

- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String LtoS (G4long l)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (const G4String &s)
 
G4long StoL (const G4String &s)
 
G4double StoD (const G4String &s)
 
G4bool StoB (G4String s)
 
void AddUIcommand (G4UIcommand *newCommand)
 
void CreateDirectory (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
template<typename T >
T * CreateCommand (const G4String &cname, const G4String &dsc)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir = nullptr
 
G4String baseDirName = ""
 
G4bool commandsShouldBeInMaster = false
 

Detailed Description

Definition at line 43 of file G4OpenGLViewerMessenger.hh.

Constructor & Destructor Documentation

◆ ~G4OpenGLViewerMessenger()

G4OpenGLViewerMessenger::~G4OpenGLViewerMessenger ( )

Definition at line 178 of file G4OpenGLViewerMessenger.cc.

179{
180 delete fpCommandTransparency;
181 delete fpCommandPrintSize;
182 delete fpCommandPrintMode;
183 delete fpCommandPrintFilename;
184 delete fpCommandExportFormat;
185 delete fpCommandDisplayListLimit;
186 delete fpDirectorySet;
187 delete fpCommandFlushAt;
188 delete fpCommandExport;
189 delete fpDirectory;
190
191 delete fpInstance;
192}

Member Function Documentation

◆ GetInstance()

◆ SetNewValue()

void G4OpenGLViewerMessenger::SetNewValue ( G4UIcommand * command,
G4String newValue )
virtual

Reimplemented from G4UImessenger.

Definition at line 194 of file G4OpenGLViewerMessenger.cc.

196{
198
199 G4VViewer* pViewer = pVisManager->GetCurrentViewer();
200 if (!pViewer) {
201 G4cout <<
202 "G4OpenGLViewerMessenger::SetNewValue: No current viewer."
203 "\n \"/vis/open\", or similar, to get one."
204 << G4endl;
205 return;
206 }
207
208 G4VSceneHandler* pSceneHandler = pViewer->GetSceneHandler();
209 if (!pSceneHandler) {
210 G4cout <<
211 "G4OpenGLViewerMessenger::SetNewValue: This viewer has no scene handler."
212 "\n Shouldn't happen - please report circumstances."
213 "\n (Viewer is \"" << pViewer->GetName() << "\".)"
214 "\n Try \"/vis/open\", or similar, to get one."
215 << G4endl;
216 return;
217 }
218
219 G4OpenGLViewer* pOGLViewer = dynamic_cast<G4OpenGLViewer*>(pViewer);
220 if (!pOGLViewer) {
221 G4cout <<
222 "G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type"
223 "\n OGL. (It is \""
224 << pViewer->GetName() <<
225 "\".)\n Use \"/vis/viewer/select\" or \"/vis/open\"."
226 << G4endl;
227 return;
228 }
229
230 G4OpenGLSceneHandler* pOGLSceneHandler =
231 dynamic_cast<G4OpenGLSceneHandler*>(pSceneHandler);
232 if (!pOGLSceneHandler) {
233 G4cout <<
234 "G4OpenGLViewerMessenger::SetNewValue: Current scene handler is not of type"
235 "\n OGL. (Viewer is \"" << pViewer->GetName() << "\".)"
236 "\n (Scene handler is \"" << pSceneHandler->GetName() << "\".)"
237 "\n Use \"/vis/sceneHandler/list\" and \"/vis/sceneHandler/select\""
238 "\n or \"/vis/open\"."
239 << G4endl;
240 return;
241 }
242
243 if (command == fpCommandExport)
244 {
246 G4int width,height;
247 std::istringstream iss(newValue);
248 iss >> name >> width >> height;
249 pOGLViewer->exportImage(name, width, height);
250
251 if (pOGLViewer->fVP.IsAutoRefresh())
252 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
253 return;
254 }
255
256 if (command == fpCommandExportFormat)
257 {
259 std::istringstream iss(newValue);
260 iss >> name;
261 pOGLViewer->setExportImageFormat(name);
262
263 return;
264 }
265
266 if (command == fpCommandFlushAt)
267 {
268 static G4bool firstTime = true;
269 static std::map<G4String,G4OpenGLSceneHandler::FlushAction> actionMap;
270 if (firstTime) {
271 actionMap["endOfEvent"] = G4OpenGLSceneHandler::endOfEvent;
272 actionMap["endOfRun"] = G4OpenGLSceneHandler::endOfRun;
273 actionMap["eachPrimitive"] = G4OpenGLSceneHandler::eachPrimitive;
274 actionMap["NthPrimitive"] = G4OpenGLSceneHandler::NthPrimitive;
275 actionMap["NthEvent"] = G4OpenGLSceneHandler::NthEvent;
276 actionMap["never"] = G4OpenGLSceneHandler::never;
277 firstTime = false;
278 }
279 G4String action;
280 G4int entitiesFlushInterval;
281 std::istringstream iss(newValue);
282 iss >> action >> entitiesFlushInterval;
283 pOGLSceneHandler->SetFlushAction(actionMap[action]);
284 pOGLSceneHandler->SetEntitiesFlushInterval(entitiesFlushInterval);
285 return;
286 }
287
288 if (command == fpCommandPrintFilename)
289 {
291 G4bool inc;
292 std::istringstream iss(newValue);
293 iss >> name
294 >> inc;
295 pOGLViewer->setExportFilename(name,inc);
296 return;
297 }
298
299 if (command == fpCommandPrintMode)
300 {
301 if (newValue == "vectored") pOGLViewer->fVectoredPs = true;
302
303 if (newValue == "pixmap") pOGLViewer->fVectoredPs = false;
304 return;
305 }
306
307 if (command == fpCommandPrintSize)
308 {
309 G4int width,height;
310 std::istringstream iss(newValue);
311 iss >> width
312 >> height;
313 pOGLViewer->setExportSize(width,height);
314 return;
315 }
316
317 if (command == fpCommandTransparency)
318 {
319 pOGLViewer->transparency_enabled = command->ConvertToBool(newValue);
320 if (pOGLViewer->fVP.IsAutoRefresh())
321 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
322 return;
323 }
324
325 // Stored viewer commands
326 G4OpenGLStoredViewer* pOGLSViewer =
327 dynamic_cast<G4OpenGLStoredViewer*>(pViewer);
328
329 if (!pOGLSViewer)
330 {
331 G4cout <<
332 "G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type OGLS."
333 "\n (It is \"" << pViewer->GetName() << "\".)"
334 "\n This feature is only implemented for OGL Stored viewers."
335 "\n Use \"/vis/viewer/select\" or \"/vis/open OGLS...\"."
336 << G4endl;
337 return;
338 }
339
340 // Scene handler commands
341 G4OpenGLStoredSceneHandler* pOGLSSceneHandler =
342 dynamic_cast<G4OpenGLStoredSceneHandler*>(pViewer->GetSceneHandler());
343
344 if (!pOGLSSceneHandler) {
345 G4cout <<
346 "G4OpenGLViewerMessenger::SetNewValue: Current scene handler is not of type"
347 "\n OGLS (Stored). (Viewer is \"" << pViewer->GetName() << "\".)"
348 "\n (Scene handler is \"" << pSceneHandler->GetName() << "\".)"
349 "\n This feature is only implemented for OGL Stored"
350 "\n scene handlers. Use \"/vis/viewer/select\" or \"/vis/open OGLS...\"."
351 << G4endl;
352 return;
353 }
354
355 if (command == fpCommandDisplayListLimit)
356 {
357 G4cerr << command->GetGuidanceLine(0) << G4endl;
358 return;
359 }
360}
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static void SetFlushAction(FlushAction action)
static void SetEntitiesFlushInterval(G4int interval)
bool setExportImageFormat(std::string format, bool quiet=false)
bool setExportFilename(G4String name, G4bool inc=true)
void setExportSize(G4int, G4int)
G4bool transparency_enabled
virtual bool exportImage(std::string name="", int width=-1, int height=-1)
const G4String & GetGuidanceLine(G4int i) const
static G4bool ConvertToBool(const char *st)
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
const G4String & GetName() const
const G4String & GetName() const
G4ViewParameters fVP
Definition G4VViewer.hh:257
G4VSceneHandler * GetSceneHandler() const
G4bool IsAutoRefresh() const
G4VViewer * GetCurrentViewer() const
static G4VisManager * GetInstance()
const char * name(G4int ptype)

The documentation for this class was generated from the following files: