28#ifdef G4VIS_BUILD_OPENGL_DRIVER
47G4OpenGLViewerMessenger::fpInstance = 0;
56G4OpenGLViewerMessenger::G4OpenGLViewerMessenger()
61 fpDirectory->
SetGuidance(
"G4OpenGLViewer commands.");
65 fpCommandExport->
SetGuidance (
"Export a screenshot of current OpenGL viewer");
67 (
"If name is \"\", filename and extension will have the current value");
69 (
"If name is \"toto.png\", set the name to \"toto\" and the format to \"png\".");
71 (
"If name is \"toto\", set the name to \"toto\" and the format to current format.");
73 (
"Will also add an incremented suffix at the end of the name, except if name is"
74 "\nthe same as previous it will not reset the incremented suffix.");
76 (
"Setting size is available only on eps/pdf/svg/ps formats.");
78 parameterExport =
new G4UIparameter (
"name",
's', omitable =
true);
81 (
"By default, will take a default value or the last \"/vis/ogl/set/printFilename\""
84 parameterExport =
new G4UIparameter (
"width",
'd', omitable =
true);
86 (
"By default, will take the current width of the viewer or \"/vis/ogl/set/printSize\""
87 "\nif set. This parameter is only useful for eps/pdf/svg/ps formats !");
90 parameterExport =
new G4UIparameter (
"height",
'd', omitable =
true);
92 (
"By default, will take the current height of the viewer or \"/vis/ogl/set/printSize\""
93 "\nif set. This parameter is only useful for eps/pdf/svg/ps formats !");
97 fpCommandFlushAt =
new G4UIcommand(
"/vis/ogl/flushAt",
this);
99 (
"Controls the rate at which graphics primitives are flushed to screen.");
101 (
"Flushing to screen is an expensive operation so to speed drawing choose"
102 "\nan action suitable for your application. Note that detectors are flushed"
103 "\nto screen anyway at end of drawing, and events are flushed to screen"
104 "\nanyway depending on /vis/scene/endOfEventAction and endOfRunAction.");
106 (
"For NthPrimitive and NthEvent the second parameter N is operative.");
108 (
"For \"never\", detectors and events are still flushed as described above.");
110 parameterFlushAt =
new G4UIparameter (
"action",
's', omitable =
true);
112 (
"endOfEvent endOfRun eachPrimitive NthPrimitive NthEvent never");
115 parameterFlushAt =
new G4UIparameter (
"N",
'i', omitable =
true);
121 fpCommandPrintEPS->
SetGuidance(
"Print Encapsulated PostScript file.");
123 (
"See \"/vis/ogl/export\" for other file formats.");
125 (
"Generates files with names G4OpenGL_viewer-name_nnnn.eps, where nnnn is a"
126 "\nsequence number, starting at 0000."
127 "\nCan be \"vectored\" or \"pixmap\" - see \"/vis/ogl/set/printMode\".");
130 fpDirectorySet->
SetGuidance(
"G4OpenGLViewer set commands.");
134 fpCommandDisplayHeadTime =
135 new G4UIcommand(
"/vis/ogl/set/displayHeadTime",
this);
137 (
"DEPRECATED. Use /vis/viewer/set/timeWindow/displayHeadTime."
138 "\n Display head time of range in 2D text.");
139 parameter =
new G4UIparameter (
"displayHeadTime",
'b', omitable =
false);
142 parameter =
new G4UIparameter (
"screenX",
'd', omitable =
true);
147 parameter =
new G4UIparameter (
"screenY",
'd', omitable =
true);
152 parameter =
new G4UIparameter (
"screenSize",
'd', omitable =
true);
159 parameter =
new G4UIparameter (
"green",
'd', omitable =
true);
163 parameter =
new G4UIparameter (
"blue",
'd', omitable =
true);
168 fpCommandDisplayLightFront =
169 new G4UIcommand(
"/vis/ogl/set/displayLightFront",
this);
171 (
"DEPRECATED. Use /vis/viewer/set/timeWindow/displayLightFront."
172 "\n Display the light front at head time.");
174 (
"Tip: The trajectories can appear of jump ahead of the light front"
175 "\nbecause their time range overlaps the viewer's time range. To"
176 "\naverage out this discrete time effect, advance the light front by"
177 "\nhalf the trajectories interval. E.g., if the trajectory time slice"
178 "\ninterval is 0.01 ns:"
179 "\n /vis/ogl/set/displayLightFront true -90 0 0 mm -0.005 ns"
180 "\nTo prevent them beating the light front at all:"
181 "\n /vis/ogl/set/displayLightFront true -90 0 0 mm -0.01 ns");
182 parameter =
new G4UIparameter (
"displayLightFront",
'b', omitable =
false);
185 parameter =
new G4UIparameter (
"originX",
'd', omitable =
true);
188 parameter =
new G4UIparameter (
"originY",
'd', omitable =
true);
191 parameter =
new G4UIparameter (
"originZ",
'd', omitable =
true);
194 parameter =
new G4UIparameter (
"space_unit",
's', omitable =
true);
197 parameter =
new G4UIparameter (
"originT",
'd', omitable =
true);
200 parameter =
new G4UIparameter (
"time_unit",
's', omitable =
true);
207 parameter =
new G4UIparameter (
"green",
'd', omitable =
true);
211 parameter =
new G4UIparameter (
"blue",
'd', omitable =
true);
216 fpCommandDisplayListLimit =
219 (
"Set/reset display list number of primitive limit (to avoid memory exhaustion).");
222 fpCommandDisplayListLimit->
SetRange(
"limit>=10000");
227 (
"DEPRECATED. Use /vis/viewer/set/timeWindow/endTime."
228 "\n Set end and range of time window.");
229 parameter =
new G4UIparameter (
"end-time",
'd', omitable =
false);
232 parameter =
new G4UIparameter (
"end-time-unit",
's', omitable =
false);
235 parameter =
new G4UIparameter (
"time-range",
'd', omitable =
true);
238 parameter =
new G4UIparameter (
"time-range-unit",
's', omitable =
true);
242 fpCommandEventsDrawInterval =
245 (
"Deprecated. Use /vis/ogl/flushAt.");
247 (
"(This is equivalent to \"/vis/ogl/flushAt NthPrimitive N\"");
251 fpCommandExportFormat =
252 new G4UIcommand(
"/vis/ogl/set/exportFormat",
this);
253 fpCommandExportFormat->
SetGuidance (
"Set export format");
254 fpCommandExportFormat->
SetGuidance (
"By default, pdf/eps/svg/ps are available. Depending of viewers several other format are available.");
255 fpCommandExportFormat->
SetGuidance (
"Try /vis/ogl/set/exportFormat without parameters to see them.");
256 fpCommandExportFormat->
SetGuidance (
"Changing format will reset the incremental suffix to 0.");
258 parameterExportFormat =
new G4UIparameter (
"format",
's', omitable =
true);
260 fpCommandExportFormat->
SetParameter(parameterExportFormat);
264 (
"DEPRECATED. Use /vis/viewer/set/timeWindow/fadeFactor."
265 "\n 0: no fade; 1: maximum fade with time within range.");
267 fpCommandFade->
SetRange(
"fadefactor>=0.&&fadefactor<=1.");
270 fpCommandPrintFilename =
271 new G4UIcommand(
"/vis/ogl/set/printFilename",
this);
272 fpCommandPrintFilename->
SetGuidance (
"Set print filename");
273 fpCommandPrintFilename->
SetGuidance (
"Setting 'incremental' will increment filename by one at each new print, starting at 0");
275 parameterPrintFilename =
new G4UIparameter (
"name",
's', omitable =
true);
277 fpCommandPrintFilename->
SetParameter(parameterPrintFilename);
278 parameterPrintFilename =
new G4UIparameter (
"incremental",
'b', omitable =
true);
280 fpCommandPrintFilename->
SetParameter(parameterPrintFilename);
283 fpCommandPrintMode->
SetGuidance(
"Set print mode, only available for \"ps\" format");
290 fpCommandPrintSize->
SetGuidance (
"Set print size");
291 fpCommandPrintSize->
SetGuidance (
"Tip : -1 will mean 'print size' = 'window size'");
292 fpCommandPrintSize->
SetGuidance (
" Setting size greater than your maximum graphic card capacity , will set the size to maximum size.");
294 parameterPrintSize =
new G4UIparameter (
"width",
'd', omitable =
false);
297 parameterPrintSize =
new G4UIparameter (
"height",
'd', omitable =
false);
304 (
"DEPRECATED. Use /vis/viewer/set/timeWindow/startTime."
305 "\n Set start and range of time window.");
306 parameter =
new G4UIparameter (
"start-time",
'd', omitable =
false);
309 parameter =
new G4UIparameter (
"start-time-unit",
's', omitable =
false);
312 parameter =
new G4UIparameter (
"time-range",
'd', omitable =
true);
315 parameter =
new G4UIparameter (
"time-range-unit",
's', omitable =
true);
319 fpCommandTransparency =
322 (
"True/false to enable/disable rendering of transparent objects.");
324 (
"transparency-enabled", omitable =
true);
330 delete fpCommandTransparency;
331 delete fpCommandStartTime;
332 delete fpCommandPrintSize;
333 delete fpCommandPrintMode;
334 delete fpCommandPrintFilename;
335 delete fpCommandFade;
336 delete fpCommandExportFormat;
337 delete fpCommandEventsDrawInterval;
338 delete fpCommandEndTime;
339 delete fpCommandDisplayListLimit;
340 delete fpCommandDisplayLightFront;
341 delete fpCommandDisplayHeadTime;
342 delete fpDirectorySet;
343 delete fpCommandPrintEPS;
344 delete fpCommandFlushAt;
345 delete fpCommandExport;
359 "G4OpenGLViewerMessenger::SetNewValue: No current viewer."
360 "\n \"/vis/open\", or similar, to get one."
366 if (!pSceneHandler) {
368 "G4OpenGLViewerMessenger::SetNewValue: This viewer has no scene handler."
369 "\n Shouldn't happen - please report circumstances."
370 "\n (Viewer is \"" << pViewer->
GetName() <<
"\".)"
371 "\n Try \"/vis/open\", or similar, to get one."
376 G4OpenGLViewer* pOGLViewer =
dynamic_cast<G4OpenGLViewer*
>(pViewer);
379 "G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type"
382 "\".)\n Use \"/vis/viewer/select\" or \"/vis/open\"."
387 G4OpenGLSceneHandler* pOGLSceneHandler =
388 dynamic_cast<G4OpenGLSceneHandler*
>(pSceneHandler);
389 if (!pOGLSceneHandler) {
391 "G4OpenGLViewerMessenger::SetNewValue: Current scene handler is not of type"
392 "\n OGL. (Viewer is \"" << pViewer->
GetName() <<
"\".)"
393 "\n (Scene handler is \"" << pSceneHandler->
GetName() <<
"\".)"
394 "\n Use \"/vis/sceneHandler/list\" and \"/vis/sceneHandler/select\""
395 "\n or \"/vis/open\"."
400 if (command == fpCommandExport)
404 std::istringstream iss(newValue);
405 iss >>
name >> width >> height;
406 pOGLViewer->exportImage(name, width, height);
408 if (pOGLViewer->fVP.IsAutoRefresh())
413 if (command == fpCommandExportFormat)
416 std::istringstream iss(newValue);
418 pOGLViewer->setExportImageFormat(name);
423 if (command == fpCommandEventsDrawInterval)
425 G4int entitiesFlushInterval =
427 pOGLSceneHandler->SetFlushAction(G4OpenGLSceneHandler::NthPrimitive);
428 pOGLSceneHandler->SetEntitiesFlushInterval(entitiesFlushInterval);
432 if (command == fpCommandFlushAt)
434 static G4bool firstTime =
true;
435 static std::map<G4String,G4OpenGLSceneHandler::FlushAction> actionMap;
437 actionMap[
"endOfEvent"] = G4OpenGLSceneHandler::endOfEvent;
438 actionMap[
"endOfRun"] = G4OpenGLSceneHandler::endOfRun;
439 actionMap[
"eachPrimitive"] = G4OpenGLSceneHandler::eachPrimitive;
440 actionMap[
"NthPrimitive"] = G4OpenGLSceneHandler::NthPrimitive;
441 actionMap[
"NthEvent"] = G4OpenGLSceneHandler::NthEvent;
442 actionMap[
"never"] = G4OpenGLSceneHandler::never;
446 G4int entitiesFlushInterval;
447 std::istringstream iss(newValue);
448 iss >> action >> entitiesFlushInterval;
449 pOGLSceneHandler->SetFlushAction(actionMap[action]);
450 pOGLSceneHandler->SetEntitiesFlushInterval(entitiesFlushInterval);
454 if (command == fpCommandPrintEPS)
456 pOGLViewer->setExportImageFormat(
"eps",
true);
457 pOGLViewer->exportImage();
459 if (pOGLViewer->fVP.IsAutoRefresh())
464 if (command == fpCommandPrintFilename)
468 std::istringstream iss(newValue);
471 pOGLViewer->setExportFilename(name,inc);
475 if (command == fpCommandPrintMode)
477 if (newValue ==
"vectored") pOGLViewer->fVectoredPs =
true;
479 if (newValue ==
"pixmap") pOGLViewer->fVectoredPs =
false;
483 if (command == fpCommandPrintSize)
486 std::istringstream iss(newValue);
489 pOGLViewer->setExportSize(width,height);
493 if (command == fpCommandTransparency)
495 pOGLViewer->transparency_enabled = command->
ConvertToBool(newValue);
496 if (pOGLViewer->fVP.IsAutoRefresh())
502 G4OpenGLStoredViewer* pOGLSViewer =
503 dynamic_cast<G4OpenGLStoredViewer*
>(pViewer);
508 "G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type OGLS."
509 "\n (It is \"" << pViewer->
GetName() <<
"\".)"
510 "\n This feature is only implemented for OGL Stored viewers."
511 "\n Use \"/vis/viewer/select\" or \"/vis/open OGLS...\"."
516 if (command == fpCommandDisplayHeadTime)
519 G4double screenX, screenY, screenSize, red, green, blue;
520 std::istringstream iss(newValue);
521 iss >> display >> screenX >> screenY
522 >> screenSize >> red >> green >> blue;
523 pOGLSViewer->fVP.SetDisplayHeadTime(command->
ConvertToBool(display));
524 pOGLSViewer->fVP.SetDisplayHeadTimeX(screenX);
525 pOGLSViewer->fVP.SetDisplayHeadTimeY(screenY);
526 pOGLSViewer->fVP.SetDisplayHeadTimeSize(screenSize);
527 pOGLSViewer->fVP.SetDisplayHeadTimeRed(red);
528 pOGLSViewer->fVP.SetDisplayHeadTimeGreen(green);
529 pOGLSViewer->fVP.SetDisplayHeadTimeBlue(blue);
531 <<
"DEPRECATED. Use /vis/viewer/set/timeWindow/displayHeadTime."
536 if (command == fpCommandDisplayLightFront)
538 G4String display, originX, originY, originZ, unitS, originT, unitT;
540 std::istringstream iss(newValue);
542 >> originX >> originY >> originZ >> unitS
544 >> red >> green >> blue;
545 pOGLSViewer->fVP.SetDisplayLightFront(command->
ConvertToBool(display));
546 pOGLSViewer->fVP.SetDisplayLightFrontX
548 pOGLSViewer->fVP.SetDisplayLightFrontY
550 pOGLSViewer->fVP.SetDisplayLightFrontZ
552 pOGLSViewer->fVP.SetDisplayLightFrontT
554 pOGLSViewer->fVP.SetDisplayLightFrontRed(red);
555 pOGLSViewer->fVP.SetDisplayLightFrontGreen(green);
556 pOGLSViewer->fVP.SetDisplayLightFrontBlue(blue);
558 <<
"DEPRECATED. Use /vis/viewer/set/timeWindow/displayLightFront."
563 if (command == fpCommandEndTime)
565 G4String end_time_string, end_time_unit,
566 time_range_string, time_range_unit;
567 std::istringstream iss(newValue);
568 iss >> end_time_string >> end_time_unit
569 >> time_range_string >> time_range_unit;
570 pOGLSViewer->fVP.SetEndTime
572 (
G4String(end_time_string +
' ' + end_time_unit)));
574 (
G4String(time_range_string +
' ' + time_range_unit));
575 if (timeRange > 0.) {
576 pOGLSViewer->fVP.SetStartTime
577 (pOGLSViewer->fVP.GetEndTime() - timeRange);
579 if (pOGLSViewer->fVP.IsAutoRefresh())
582 <<
"DEPRECATED. Use /vis/viewer/set/timeWindow/endTime."
587 if (command == fpCommandFade)
590 if (pOGLSViewer->fVP.IsAutoRefresh())
593 <<
"DEPRECATED. Use /vis/viewer/set/timeWindow/fadeFactor."
598 if (command == fpCommandStartTime)
600 G4String start_time_string, start_time_unit,
601 time_range_string, time_range_unit;
602 std::istringstream iss(newValue);
603 iss >> start_time_string >> start_time_unit
604 >> time_range_string >> time_range_unit;
605 pOGLSViewer->fVP.SetStartTime
607 (
G4String(start_time_string +
' ' + start_time_unit)));
609 (
G4String(time_range_string +
' ' + time_range_unit));
610 if (timeRange > 0.) {
611 pOGLSViewer->fVP.SetEndTime
612 (pOGLSViewer->fVP.GetStartTime() + timeRange);
614 if (pOGLSViewer->fVP.IsAutoRefresh())
617 <<
"DEPRECATED. Use /vis/viewer/set/timeWindow/startTime."
623 G4OpenGLStoredSceneHandler* pOGLSSceneHandler =
626 if (!pOGLSSceneHandler) {
628 "G4OpenGLViewerMessenger::SetNewValue: Current scene handler is not of type"
629 "\n OGLS (Stored). (Viewer is \"" << pViewer->
GetName() <<
"\".)"
630 "\n (Scene handler is \"" << pSceneHandler->
GetName() <<
"\".)"
631 "\n This feature is only implemented for OGL Stored"
632 "\n scene handlers. Use \"/vis/viewer/select\" or \"/vis/open OGLS...\"."
637 if (command == fpCommandDisplayListLimit)
639 G4int displayListLimit =
641 pOGLSSceneHandler->SetDisplayListLimit(displayListLimit);
G4GLOB_DLL std::ostream G4cout
~G4OpenGLViewerMessenger()
static G4OpenGLViewerMessenger * GetInstance()
void SetNewValue(G4UIcommand *, G4String)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(G4bool defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(G4double defVal)
void SetCandidates(const char *candidateList)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(const char *defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetDefaultValue(G4int defVal)
void SetParameter(G4UIparameter *const newParameter)
void SetGuidance(const char *aGuidance)
static G4bool ConvertToBool(const char *st)
void SetRange(const char *rs)
static G4double ConvertToDouble(const char *st)
static G4double ConvertToDimensionedDouble(const char *st)
G4int ApplyCommand(const char *aCommand)
static G4UImanager * GetUIpointer()
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
const G4String & GetName() const
const G4String & GetName() const
G4VSceneHandler * GetSceneHandler() const
static constexpr G4double fVeryLongTime
G4VViewer * GetCurrentViewer() const
static G4VisManager * GetInstance()
const char * name(G4int ptype)