29#ifdef G4VIS_BUILD_OPENGL_DRIVER
48G4OpenGLViewerMessenger::fpInstance = 0;
57G4OpenGLViewerMessenger::G4OpenGLViewerMessenger()
62 fpDirectory->
SetGuidance(
"G4OpenGLViewer commands.");
65 fpDirectorySet->
SetGuidance(
"G4OpenGLViewer set commands.");
69 fpCommandDisplayHeadTime =
70 new G4UIcommand(
"/vis/ogl/set/displayHeadTime",
this);
72 (
"Display head time of range in 2D text.");
73 parameter =
new G4UIparameter (
"displayHeadTime",
'b', omitable =
false);
76 parameter =
new G4UIparameter (
"screenX",
'd', omitable =
true);
81 parameter =
new G4UIparameter (
"screenY",
'd', omitable =
true);
86 parameter =
new G4UIparameter (
"screenSize",
'd', omitable =
true);
93 parameter =
new G4UIparameter (
"green",
'd', omitable =
true);
102 fpCommandDisplayLightFront =
103 new G4UIcommand(
"/vis/ogl/set/displayLightFront",
this);
105 (
"Display the light front at head time.");
107 (
"Tip: The trajectories can appear of jump ahead of the light front"
108 "\nbecause their time range overlaps the viewer's time range. To"
109 "\naverage out this discrete time effect, advance the light front by"
110 "\nhalf the trajectories interval. E.g., if the trajectory time slice"
111 "\ninterval is 0.01 ns:"
112 "\n /vis/ogl/set/displayLightFront true -90 0 0 mm -0.005 ns"
113 "\nTo prevent them beating the light front at all:"
114 "\n /vis/ogl/set/displayLightFront true -90 0 0 mm -0.01 ns");
115 parameter =
new G4UIparameter (
"displayLightFront",
'b', omitable =
false);
118 parameter =
new G4UIparameter (
"originX",
'd', omitable =
true);
121 parameter =
new G4UIparameter (
"originY",
'd', omitable =
true);
124 parameter =
new G4UIparameter (
"originZ",
'd', omitable =
true);
127 parameter =
new G4UIparameter (
"space_unit",
's', omitable =
true);
130 parameter =
new G4UIparameter (
"originT",
'd', omitable =
true);
133 parameter =
new G4UIparameter (
"time_unit",
's', omitable =
true);
140 parameter =
new G4UIparameter (
"green",
'd', omitable =
true);
144 parameter =
new G4UIparameter (
"blue",
'd', omitable =
true);
149 fpCommandDisplayListLimit =
152 (
"Set/reset display list limit (to avoid memory exhaustion).");
155 fpCommandDisplayListLimit->
SetRange(
"limit>=10000");
159 fpCommandEndTime->
SetGuidance(
"Set end and range of track time.");
160 parameter =
new G4UIparameter (
"end-time",
'd', omitable =
false);
163 parameter =
new G4UIparameter (
"end-time-unit",
's', omitable =
false);
166 parameter =
new G4UIparameter (
"time-range",
'd', omitable =
true);
169 parameter =
new G4UIparameter (
"time-range-unit",
's', omitable =
true);
173 fpCommandEventsDrawInterval =
176 (
"Set number of events allowed in drawing pipeline - speeds drawing");
178 (
"By default, the screen is updated at the end of every event."
179 "\nAllowing OpenGL to buffer several events can make a big improvement"
180 "\nin drawing speed.");
186 (
"0: no fade; 1: maximum fade with time within range.");
188 fpCommandFade->
SetRange(
"fadefactor>=0.&&fadefactor<=1.");
193 fpCommandPrintEPS->
SetGuidance(
"Print Encapsulated PostScript file.");
195 (
"Generates files with names G4OpenGL_n.eps, where n is a sequence"
196 "\nnumber, starting at 0."
197 "\nCan be \"vectored\" or \"pixmap\" - see \"/vis/ogl/set/printMode\".");
199 fpCommandPrintFilename =
200 new G4UIcommand(
"/vis/ogl/set/printFilename",
this);
201 fpCommandPrintFilename->
SetGuidance (
"Set print filename");
202 fpCommandPrintFilename->
SetGuidance (
"Setting 'incremental' will increment filename by one at each new print, starting at 0");
204 parameterPrintFilename =
new G4UIparameter (
"name",
's', omitable =
true);
206 fpCommandPrintFilename->
SetParameter(parameterPrintFilename);
207 parameterPrintFilename =
new G4UIparameter (
"incremental",
'b', omitable =
true);
209 fpCommandPrintFilename->
SetParameter(parameterPrintFilename);
212 (
"/vis/ogl/set/printMode",
this);
220 fpCommandPrintSize->
SetGuidance (
"Set print size");
221 fpCommandPrintSize->
SetGuidance (
"Tip : -1 will mean 'print size' = 'window size'");
222 fpCommandPrintSize->
SetGuidance (
" Setting size greatter than your maximum graphic card capacity , will set the size to maximum size.");
224 parameterPrintSize =
new G4UIparameter (
"width",
'd', omitable =
false);
227 parameterPrintSize =
new G4UIparameter (
"height",
'd', omitable =
false);
233 fpCommandStartTime->
SetGuidance(
"Set start and range of track time.");
234 parameter =
new G4UIparameter (
"start-time",
'd', omitable =
false);
237 parameter =
new G4UIparameter (
"start-time-unit",
's', omitable =
false);
240 parameter =
new G4UIparameter (
"time-range",
'd', omitable =
true);
243 parameter =
new G4UIparameter (
"time-range-unit",
's', omitable =
true);
247 fpCommandTransparency =
250 (
"True/false to enable/disable rendering of transparent objects.");
252 (
"transparency-enabled", omitable =
true);
258 delete fpCommandTransparency;
259 delete fpCommandStartTime;
260 delete fpCommandPrintSize;
261 delete fpCommandPrintMode;
262 delete fpCommandPrintFilename;
263 delete fpCommandPrintEPS;
264 delete fpCommandFade;
265 delete fpCommandEventsDrawInterval;
266 delete fpCommandEndTime;
267 delete fpCommandDisplayListLimit;
268 delete fpCommandDisplayLightFront;
269 delete fpCommandDisplayHeadTime;
270 delete fpDirectorySet;
279 G4VisManager* pVisManager = G4VisManager::GetInstance();
285 "G4OpenGLViewerMessenger::SetNewValue: No current viewer."
286 "\n \"/vis/open\", or similar, to get one."
291 G4OpenGLViewer* pOGLViewer =
dynamic_cast<G4OpenGLViewer*
>(pViewer);
295 "G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type"
298 "\".)\n Use \"/vis/viewer/select\" or \"/vis/open\"."
303 if (command == fpCommandPrintEPS)
305 pOGLViewer->printEPS();
306 if (pOGLViewer->fVP.IsAutoRefresh())
311 if (command == fpCommandPrintSize)
314 std::istringstream iss(newValue);
317 pOGLViewer->setPrintSize(width,height);
321 if (command == fpCommandPrintFilename)
325 std::istringstream iss(newValue);
328 pOGLViewer->setPrintFilename(name,inc);
332 if (command == fpCommandPrintMode)
334 if (newValue ==
"vectored") pOGLViewer->fVectoredPs =
true;
335 if (newValue ==
"pixmap") pOGLViewer->fVectoredPs =
false;
339 if (command == fpCommandTransparency)
341 pOGLViewer->transparency_enabled = command->
ConvertToBool(newValue);
342 if (pOGLViewer->fVP.IsAutoRefresh())
347 G4OpenGLStoredViewer* pOGLSViewer =
348 dynamic_cast<G4OpenGLStoredViewer*
>(pViewer);
353 "G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type OGLS."
354 "\n (It is \"" << pViewer->
GetName() <<
"\".)"
355 "\n This feature is only implemented for OGL Stored viewers."
356 "\n Use \"/vis/viewer/select\" or \"/vis/open OGLS...\"."
361 if (command == fpCommandDisplayHeadTime)
364 G4double screenX, screenY, screenSize, red, green, blue;
365 std::istringstream iss(newValue);
366 iss >> display >> screenX >> screenY
367 >> screenSize >> red >> green >> blue;
368 pOGLSViewer->fDisplayHeadTime = command->
ConvertToBool(display);
369 pOGLSViewer->fDisplayHeadTimeX = screenX;
370 pOGLSViewer->fDisplayHeadTimeY = screenY;
371 pOGLSViewer->fDisplayHeadTimeSize = screenSize;
372 pOGLSViewer->fDisplayHeadTimeRed = red;
373 pOGLSViewer->fDisplayHeadTimeGreen = green;
374 pOGLSViewer->fDisplayHeadTimeBlue = blue;
378 if (command == fpCommandDisplayLightFront)
380 G4String display, originX, originY, originZ, unitS, originT, unitT;
382 std::istringstream iss(newValue);
384 >> originX >> originY >> originZ >> unitS
386 >> red >> green >> blue;
387 pOGLSViewer->fDisplayLightFront = command->
ConvertToBool(display);
388 pOGLSViewer->fDisplayLightFrontX =
390 pOGLSViewer->fDisplayLightFrontY =
392 pOGLSViewer->fDisplayLightFrontZ =
394 pOGLSViewer->fDisplayLightFrontT =
396 pOGLSViewer->fDisplayLightFrontRed = red;
397 pOGLSViewer->fDisplayLightFrontGreen = green;
398 pOGLSViewer->fDisplayLightFrontBlue = blue;
402 if (command == fpCommandEndTime)
404 G4String end_time_string, end_time_unit,
405 time_range_string, time_range_unit;
406 std::istringstream iss(newValue);
407 iss >> end_time_string >> end_time_unit
408 >> time_range_string >> time_range_unit;
410 (
G4String(end_time_string +
' ' + end_time_unit));
412 (
G4String(time_range_string +
' ' + time_range_unit));
413 if (timeRange > 0.) {
414 pOGLSViewer->fStartTime = pOGLSViewer->fEndTime - timeRange;
416 if (pOGLSViewer->fVP.IsAutoRefresh())
421 if (command == fpCommandFade)
424 if (pOGLSViewer->fVP.IsAutoRefresh())
429 if (command == fpCommandStartTime)
431 G4String start_time_string, start_time_unit,
432 time_range_string, time_range_unit;
433 std::istringstream iss(newValue);
434 iss >> start_time_string >> start_time_unit
435 >> time_range_string >> time_range_unit;
437 (
G4String(start_time_string +
' ' + start_time_unit));
439 (
G4String(time_range_string +
' ' + time_range_unit));
440 if (timeRange > 0.) {
441 pOGLSViewer->fEndTime = pOGLSViewer->fStartTime + timeRange;
443 if (pOGLSViewer->fVP.IsAutoRefresh())
450 if (!pSceneHandler) {
452 "G4OpenGLViewerMessenger::SetNewValue: This viewer has no scene handler."
453 "\n Shouldn't happen - please report circumstances."
454 "\n (Viewer is \"" << pViewer->
GetName() <<
"\".)"
455 "\n Try \"/vis/open\", or similar, to get one."
460 G4OpenGLSceneHandler* pOGLSceneHandler =
461 dynamic_cast<G4OpenGLSceneHandler*
>(pSceneHandler);
463 if (!pOGLSceneHandler) {
465 "G4OpenGLViewerMessenger::SetNewValue: Current scene handler is not of type"
466 "\n OGL. (Viewer is \"" << pViewer->
GetName() <<
"\".)"
467 "\n (Scene handler is \"" << pSceneHandler->
GetName() <<
"\".)"
468 "\n Use \"/vis/sceneHandler/list\" and \"/vis/sceneHandler/select\""
469 "\n or \"/vis/open\"."
474 if (command == fpCommandEventsDrawInterval)
476 G4int eventsDrawInterval =
478 pOGLSceneHandler->SetEventsDrawInterval(eventsDrawInterval);
482 G4OpenGLStoredSceneHandler* pOGLSSceneHandler =
485 if (!pOGLSSceneHandler) {
487 "G4OpenGLViewerMessenger::SetNewValue: Current scene handler is not of type"
488 "\n OGLS (Stored). (Viewer is \"" << pViewer->
GetName() <<
"\".)"
489 "\n (Scene handler is \"" << pSceneHandler->
GetName() <<
"\".)"
490 "\n This feature is only implemented for OGL Stored"
491 "\n scene handlers. Use \"/vis/viewer/select\" or \"/vis/open OGLS...\"."
496 if (command == fpCommandDisplayListLimit)
498 G4int displayListLimit =
500 pOGLSSceneHandler->SetDisplayListLimit(displayListLimit);
G4DLLIMPORT 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)
const G4String & GetName() const
const G4String & GetName() const
G4VSceneHandler * GetSceneHandler() const
G4VViewer * GetCurrentViewer() const