29 #ifdef G4VIS_BUILD_OPENGL_DRIVER
48 G4OpenGLViewerMessenger::fpInstance = 0;
57 G4OpenGLViewerMessenger::G4OpenGLViewerMessenger()
62 fpDirectory->
SetGuidance(
"G4OpenGLViewer commands.");
66 fpCommandExport->
SetGuidance (
"export a screenshot of current OpenGL viewer");
67 fpCommandExport->
SetGuidance (
"If name is \"\", filename and extension will have the default value");
68 fpCommandExport->
SetGuidance (
"If name is \"toto.png\", set the name to \"toto\" and the format to \"png\". No incremented suffix is added.");
69 fpCommandExport->
SetGuidance (
"If name is \"toto\", set the name to \"toto\" and the format to default (or current format if specify). Will also add an incremented suffix at the end of the file, except if name is the same as previous it will not reset incremented suffix.");
70 fpCommandExport->
SetGuidance (
"Setting size is available only on eps/pdf/svg/ps formats");
72 parameterExport =
new G4UIparameter (
"name",
's', omitable =
true);
74 parameterExport->
SetGuidance(
"by default, will take a default value or the last /vis/ogl/set/printFilename value if set");
76 parameterExport =
new G4UIparameter (
"width",
'd', omitable =
true);
77 parameterExport->
SetGuidance(
"By default, will take the current width of the viewer or /vis/ogl/set/printSize if set");
78 parameterExport->
SetGuidance(
"This parameter is only useful for eps/pdf/svg/ps formats !");
81 parameterExport =
new G4UIparameter (
"height",
'd', omitable =
true);
82 parameterExport->
SetGuidance(
"By default, will take the current height of the viewer or /vis/ogl/set/printSize if set");
83 parameterExport->
SetGuidance(
"This parameter is only useful for eps/pdf/svg/ps formats !");
87 fpCommandFlushAt =
new G4UIcommand(
"/vis/ogl/flushAt",
this);
89 (
"Controls the rate at which graphics primitives are flushed to screen.");
91 (
"Flushing to screen is an expensive operation so to speed drawing choose"
92 "\nan action suitable for your application. Note that detectors are flushed"
93 "\nto screen anyway at end of drawing, and events are flushed to screen"
94 "\nanyway depending on /vis/scene/endOfEventAction and endOfRunAction.");
96 (
"For NthPrimitive and NthEvent the second parameter N is operative.");
98 (
"For \"never\", detectors and events are still flushed as described above.");
100 parameterFlushAt =
new G4UIparameter (
"action",
's', omitable =
true);
102 (
"endOfEvent endOfRun eachPrimitive NthPrimitive NthEvent never");
105 parameterFlushAt =
new G4UIparameter (
"N",
'i', omitable =
true);
111 fpCommandPrintEPS->
SetGuidance(
"Print Encapsulated PostScript file.");
113 (
"Generates files with names G4OpenGL_n.eps, where n is a sequence"
114 "\nnumber, starting at 0."
115 "\nCan be \"vectored\" or \"pixmap\" - see \"/vis/ogl/set/printMode\".");
118 fpDirectorySet->
SetGuidance(
"G4OpenGLViewer set commands.");
122 fpCommandDisplayHeadTime =
123 new G4UIcommand(
"/vis/ogl/set/displayHeadTime",
this);
125 (
"Display head time of range in 2D text.");
126 parameter =
new G4UIparameter (
"displayHeadTime",
'b', omitable =
false);
129 parameter =
new G4UIparameter (
"screenX",
'd', omitable =
true);
134 parameter =
new G4UIparameter (
"screenY",
'd', omitable =
true);
139 parameter =
new G4UIparameter (
"screenSize",
'd', omitable =
true);
146 parameter =
new G4UIparameter (
"green",
'd', omitable =
true);
150 parameter =
new G4UIparameter (
"blue",
'd', omitable =
true);
155 fpCommandDisplayLightFront =
156 new G4UIcommand(
"/vis/ogl/set/displayLightFront",
this);
158 (
"Display the light front at head time.");
160 (
"Tip: The trajectories can appear of jump ahead of the light front"
161 "\nbecause their time range overlaps the viewer's time range. To"
162 "\naverage out this discrete time effect, advance the light front by"
163 "\nhalf the trajectories interval. E.g., if the trajectory time slice"
164 "\ninterval is 0.01 ns:"
165 "\n /vis/ogl/set/displayLightFront true -90 0 0 mm -0.005 ns"
166 "\nTo prevent them beating the light front at all:"
167 "\n /vis/ogl/set/displayLightFront true -90 0 0 mm -0.01 ns");
168 parameter =
new G4UIparameter (
"displayLightFront",
'b', omitable =
false);
171 parameter =
new G4UIparameter (
"originX",
'd', omitable =
true);
174 parameter =
new G4UIparameter (
"originY",
'd', omitable =
true);
177 parameter =
new G4UIparameter (
"originZ",
'd', omitable =
true);
180 parameter =
new G4UIparameter (
"space_unit",
's', omitable =
true);
183 parameter =
new G4UIparameter (
"originT",
'd', omitable =
true);
186 parameter =
new G4UIparameter (
"time_unit",
's', omitable =
true);
193 parameter =
new G4UIparameter (
"green",
'd', omitable =
true);
197 parameter =
new G4UIparameter (
"blue",
'd', omitable =
true);
202 fpCommandDisplayListLimit =
205 (
"Set/reset display list limit (to avoid memory exhaustion).");
208 fpCommandDisplayListLimit->
SetRange(
"limit>=10000");
212 fpCommandEndTime->
SetGuidance(
"Set end and range of track time.");
213 parameter =
new G4UIparameter (
"end-time",
'd', omitable =
false);
216 parameter =
new G4UIparameter (
"end-time-unit",
's', omitable =
false);
219 parameter =
new G4UIparameter (
"time-range",
'd', omitable =
true);
222 parameter =
new G4UIparameter (
"time-range-unit",
's', omitable =
true);
226 fpCommandEventsDrawInterval =
229 (
"Deprecated. Use /vis/ogl/flushAt.");
231 (
"(This is equivalent to \"/vis/ogl/flushAt NthPrimitive N\"");
237 (
"0: no fade; 1: maximum fade with time within range.");
239 fpCommandFade->
SetRange(
"fadefactor>=0.&&fadefactor<=1.");
242 fpCommandPrintFilename =
243 new G4UIcommand(
"/vis/ogl/set/printFilename",
this);
244 fpCommandPrintFilename->
SetGuidance (
"Set print filename");
245 fpCommandPrintFilename->
SetGuidance (
"Setting 'incremental' will increment filename by one at each new print, starting at 0");
247 parameterPrintFilename =
new G4UIparameter (
"name",
's', omitable =
true);
249 fpCommandPrintFilename->
SetParameter(parameterPrintFilename);
250 parameterPrintFilename =
new G4UIparameter (
"incremental",
'b', omitable =
true);
252 fpCommandPrintFilename->
SetParameter(parameterPrintFilename);
254 fpCommandExportFormat =
255 new G4UIcommand(
"/vis/ogl/set/exportFormat",
this);
256 fpCommandExportFormat->
SetGuidance (
"Set export format");
257 fpCommandExportFormat->
SetGuidance (
"By default, pdf/eps/svg/ps are available. Depending of viewers several other format are available.");
258 fpCommandExportFormat->
SetGuidance (
"Try /vis/ogl/set/exportFormat without parameters to see them.");
259 fpCommandExportFormat->
SetGuidance (
"Changing format will reset the incremental suffix to 0.");
261 parameterExportFormat =
new G4UIparameter (
"format",
's', omitable =
true);
263 fpCommandExportFormat->
SetParameter(parameterExportFormat);
266 (
"/vis/ogl/set/printMode",
this);
267 fpCommandPrintMode->
SetGuidance(
"Set print mode, only available for \"ps\" format");
274 fpCommandPrintSize->
SetGuidance (
"Set print size");
275 fpCommandPrintSize->
SetGuidance (
"Tip : -1 will mean 'print size' = 'window size'");
276 fpCommandPrintSize->
SetGuidance (
" Setting size greatter than your maximum graphic card capacity , will set the size to maximum size.");
278 parameterPrintSize =
new G4UIparameter (
"width",
'd', omitable =
false);
281 parameterPrintSize =
new G4UIparameter (
"height",
'd', omitable =
false);
287 fpCommandStartTime->
SetGuidance(
"Set start and range of track time.");
288 parameter =
new G4UIparameter (
"start-time",
'd', omitable =
false);
291 parameter =
new G4UIparameter (
"start-time-unit",
's', omitable =
false);
294 parameter =
new G4UIparameter (
"time-range",
'd', omitable =
true);
297 parameter =
new G4UIparameter (
"time-range-unit",
's', omitable =
true);
301 fpCommandTransparency =
304 (
"True/false to enable/disable rendering of transparent objects.");
306 (
"transparency-enabled", omitable =
true);
312 delete fpCommandTransparency;
313 delete fpCommandStartTime;
314 delete fpCommandPrintSize;
315 delete fpCommandPrintMode;
316 delete fpCommandPrintFilename;
317 delete fpCommandFade;
318 delete fpCommandExportFormat;
319 delete fpCommandEventsDrawInterval;
320 delete fpCommandEndTime;
321 delete fpCommandDisplayListLimit;
322 delete fpCommandDisplayLightFront;
323 delete fpCommandDisplayHeadTime;
324 delete fpDirectorySet;
325 delete fpCommandPrintEPS;
326 delete fpCommandFlushAt;
327 delete fpCommandExport;
341 "G4OpenGLViewerMessenger::SetNewValue: No current viewer."
342 "\n \"/vis/open\", or similar, to get one."
348 if (!pSceneHandler) {
350 "G4OpenGLViewerMessenger::SetNewValue: This viewer has no scene handler."
351 "\n Shouldn't happen - please report circumstances."
352 "\n (Viewer is \"" << pViewer->
GetName() <<
"\".)"
353 "\n Try \"/vis/open\", or similar, to get one."
358 G4OpenGLViewer* pOGLViewer =
dynamic_cast<G4OpenGLViewer*
>(pViewer);
361 "G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type"
364 "\".)\n Use \"/vis/viewer/select\" or \"/vis/open\"."
369 G4OpenGLSceneHandler* pOGLSceneHandler =
370 dynamic_cast<G4OpenGLSceneHandler*
>(pSceneHandler);
371 if (!pOGLSceneHandler) {
373 "G4OpenGLViewerMessenger::SetNewValue: Current scene handler is not of type"
374 "\n OGL. (Viewer is \"" << pViewer->
GetName() <<
"\".)"
375 "\n (Scene handler is \"" << pSceneHandler->
GetName() <<
"\".)"
376 "\n Use \"/vis/sceneHandler/list\" and \"/vis/sceneHandler/select\""
377 "\n or \"/vis/open\"."
382 if (command == fpCommandPrintEPS)
384 pOGLViewer->setExportImageFormat(
"eps",
true);
385 pOGLViewer->exportImage();
387 if (pOGLViewer->fVP.IsAutoRefresh())
392 if (command == fpCommandExportFormat)
395 std::istringstream iss(newValue);
397 pOGLViewer->setExportImageFormat(name);
402 if (command == fpCommandExport)
406 std::istringstream iss(newValue);
407 iss >> name >> width >> height;
408 pOGLViewer->exportImage(name, width, height);
410 if (pOGLViewer->fVP.IsAutoRefresh())
415 if (command == fpCommandPrintSize)
418 std::istringstream iss(newValue);
421 pOGLViewer->setExportSize(width,height);
425 if (command == fpCommandPrintFilename)
429 std::istringstream iss(newValue);
432 pOGLViewer->setExportFilename(name,inc);
436 if (command == fpCommandPrintMode)
438 if (newValue ==
"vectored") pOGLViewer->fVectoredPs =
true;
439 if (newValue ==
"pixmap") pOGLViewer->fVectoredPs =
false;
443 if (command == fpCommandTransparency)
445 pOGLViewer->transparency_enabled = command->
ConvertToBool(newValue);
446 if (pOGLViewer->fVP.IsAutoRefresh())
451 if (command == fpCommandEventsDrawInterval)
453 G4int entitiesFlushInterval =
455 pOGLSceneHandler->SetFlushAction(G4OpenGLSceneHandler::NthPrimitive);
456 pOGLSceneHandler->SetEntitiesFlushInterval(entitiesFlushInterval);
460 if (command == fpCommandFlushAt)
463 std::map<G4String,G4OpenGLSceneHandler::FlushAction> actionMap;
465 actionMap[
"endOfEvent"] = G4OpenGLSceneHandler::endOfEvent;
466 actionMap[
"endOfRun"] = G4OpenGLSceneHandler::endOfRun;
467 actionMap[
"eachPrimitive"] = G4OpenGLSceneHandler::eachPrimitive;
468 actionMap[
"NthPrimitive"] = G4OpenGLSceneHandler::NthPrimitive;
469 actionMap[
"NthEvent"] = G4OpenGLSceneHandler::NthEvent;
470 actionMap[
"never"] = G4OpenGLSceneHandler::never;
474 G4int entitiesFlushInterval;
475 std::istringstream iss(newValue);
476 iss >> action >> entitiesFlushInterval;
477 pOGLSceneHandler->SetFlushAction(actionMap[action]);
478 pOGLSceneHandler->SetEntitiesFlushInterval(entitiesFlushInterval);
482 G4OpenGLStoredViewer* pOGLSViewer =
483 dynamic_cast<G4OpenGLStoredViewer*
>(pViewer);
488 "G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type OGLS."
489 "\n (It is \"" << pViewer->
GetName() <<
"\".)"
490 "\n This feature is only implemented for OGL Stored viewers."
491 "\n Use \"/vis/viewer/select\" or \"/vis/open OGLS...\"."
496 if (command == fpCommandDisplayHeadTime)
500 std::istringstream iss(newValue);
501 iss >> display >> screenX >> screenY
502 >> screenSize >> red >> green >>
blue;
503 pOGLSViewer->fDisplayHeadTime = command->
ConvertToBool(display);
504 pOGLSViewer->fDisplayHeadTimeX = screenX;
505 pOGLSViewer->fDisplayHeadTimeY = screenY;
506 pOGLSViewer->fDisplayHeadTimeSize = screenSize;
507 pOGLSViewer->fDisplayHeadTimeRed =
red;
508 pOGLSViewer->fDisplayHeadTimeGreen = green;
509 pOGLSViewer->fDisplayHeadTimeBlue =
blue;
513 if (command == fpCommandDisplayLightFront)
515 G4String display, originX, originY, originZ, unitS, originT, unitT;
517 std::istringstream iss(newValue);
519 >> originX >> originY >> originZ >> unitS
521 >> red >> green >>
blue;
522 pOGLSViewer->fDisplayLightFront = command->
ConvertToBool(display);
523 pOGLSViewer->fDisplayLightFrontX =
525 pOGLSViewer->fDisplayLightFrontY =
527 pOGLSViewer->fDisplayLightFrontZ =
529 pOGLSViewer->fDisplayLightFrontT =
531 pOGLSViewer->fDisplayLightFrontRed =
red;
532 pOGLSViewer->fDisplayLightFrontGreen = green;
533 pOGLSViewer->fDisplayLightFrontBlue =
blue;
537 if (command == fpCommandEndTime)
539 G4String end_time_string, end_time_unit,
540 time_range_string, time_range_unit;
541 std::istringstream iss(newValue);
542 iss >> end_time_string >> end_time_unit
543 >> time_range_string >> time_range_unit;
545 (
G4String(end_time_string +
' ' + end_time_unit));
547 (
G4String(time_range_string +
' ' + time_range_unit));
548 if (timeRange > 0.) {
549 pOGLSViewer->fStartTime = pOGLSViewer->fEndTime - timeRange;
551 if (pOGLSViewer->fVP.IsAutoRefresh())
556 if (command == fpCommandFade)
559 if (pOGLSViewer->fVP.IsAutoRefresh())
564 if (command == fpCommandStartTime)
566 G4String start_time_string, start_time_unit,
567 time_range_string, time_range_unit;
568 std::istringstream iss(newValue);
569 iss >> start_time_string >> start_time_unit
570 >> time_range_string >> time_range_unit;
572 (
G4String(start_time_string +
' ' + start_time_unit));
574 (
G4String(time_range_string +
' ' + time_range_unit));
575 if (timeRange > 0.) {
576 pOGLSViewer->fEndTime = pOGLSViewer->fStartTime + timeRange;
578 if (pOGLSViewer->fVP.IsAutoRefresh())
583 G4OpenGLStoredSceneHandler* pOGLSSceneHandler =
586 if (!pOGLSSceneHandler) {
588 "G4OpenGLViewerMessenger::SetNewValue: Current scene handler is not of type"
589 "\n OGLS (Stored). (Viewer is \"" << pViewer->
GetName() <<
"\".)"
590 "\n (Scene handler is \"" << pSceneHandler->
GetName() <<
"\".)"
591 "\n This feature is only implemented for OGL Stored"
592 "\n scene handlers. Use \"/vis/viewer/select\" or \"/vis/open OGLS...\"."
597 if (command == fpCommandDisplayListLimit)
599 G4int displayListLimit =
601 pOGLSSceneHandler->SetDisplayListLimit(displayListLimit);
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
const G4String & GetName() const
void SetParameter(G4UIparameter *const newParameter)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
void SetDefaultValue(const char *theDefaultValue)
const G4String & GetName() const
void SetNewValue(G4UIcommand *, G4String)
static G4double ConvertToDimensionedDouble(const char *st)
void SetDefaultValue(G4bool defVal)
static G4UImanager * GetUIpointer()
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
~G4OpenGLViewerMessenger()
G4GLOB_DLL std::ostream G4cout
static G4OpenGLViewerMessenger * GetInstance()
static G4bool ConvertToBool(const char *st)
void SetRange(const char *rs)
void SetGuidance(const char *aGuidance)
static G4VisManager * GetInstance()
static G4double ConvertToDouble(const char *st)
void SetDefaultValue(const char *defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4VSceneHandler * GetSceneHandler() const
void SetDefaultValue(G4double defVal)
void SetCandidates(const char *candidateList)
G4VViewer * GetCurrentViewer() const
void SetDefaultValue(G4int defVal)
void SetGuidance(const char *theGuidance)
G4int ApplyCommand(const char *aCommand)