39 #include <X11/keysym.h>
44 #include <Xm/MessageB.h>
46 #include <Xm/ToggleB.h>
47 #include <Xm/CascadeB.h>
48 #include <Xm/ArrowBG.h>
50 #include <Xm/RowColumn.h>
51 #include <Xm/FileSB.h>
52 #include <Xm/SelectioB.h>
53 #include <Xm/Protocols.h>
54 #include <Xm/SeparatoG.h>
55 #include <Xm/DialogS.h>
56 #include <Xm/PanedW.h>
57 #include <Xm/LabelG.h>
59 #include <Xm/DrawingA.h>
61 #include <Inventor/Xt/SoXt.h>
63 #include <Inventor/Xt/SoXtCursor.h>
64 #include <Inventor/events/SoKeyboardEvent.h>
65 #include <Inventor/events/SoMouseButtonEvent.h>
66 #include <Inventor/events/SoLocation2Event.h>
67 #include <Inventor/nodes/SoSeparator.h>
68 #include <Inventor/nodes/SoOrthographicCamera.h>
69 #include <Inventor/nodes/SoPerspectiveCamera.h>
70 #include <Inventor/nodes/SoEventCallback.h>
71 #include <Inventor/nodes/SoLineSet.h>
72 #include <Inventor/nodes/SoMaterial.h>
73 #include <Inventor/errors/SoDebugError.h>
74 #include <Inventor/SoPickedPoint.h>
75 #include <Inventor/actions/SoWriteAction.h>
80 #include <Inventor/sensors/SoTimerSensor.h>
81 #include <Inventor/sensors/SoNodeSensor.h>
93 #include <Inventor/nodes/SoCallback.h>
94 #include <Inventor/nodes/SoSwitch.h>
95 #include <Inventor/nodes/SoScale.h>
96 #include <Inventor/nodes/SoTranslation.h>
97 #include <Inventor/actions/SoSearchAction.h>
98 #include <Inventor/actions/SoGetBoundingBoxAction.h>
100 #include <Inventor/nodes/SoCoordinate3.h>
102 #include <Inventor/nodes/SoText2.h>
103 #include <Inventor/nodes/SoFont.h>
104 #include <Inventor/nodes/SoPointSet.h>
105 #include <Inventor/nodes/SoDrawStyle.h>
106 #include <Inventor/nodes/SoBaseColor.h>
109 #include <Inventor/nodekits/SoBaseKit.h>
113 static const char* thisClassName =
"G4OpenInventorXtExaminerViewer";
115 #define MIN_SPEED 2.1 // Lower number means faster
116 #define START_STEP 0.3
117 #define SPEED_INDICATOR_STEP 0.045
118 #define MAX_SPEED_INDICATOR 0.81
124 const char *
name, SbBool embed,
125 SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type) :
126 SoXtExaminerViewer(parent, name, embed, flag, type,
FALSE)
129 this->constructor(
TRUE);
134 const char *
name, SbBool embed,
135 SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type,
137 SoXtExaminerViewer(parent, name, embed, flag, type,
FALSE)
139 this->constructor(build);
143 void G4OpenInventorXtExaminerViewer::constructor(
const SbBool build)
145 setClassName(thisClassName);
148 this->newEvents =
false;
150 fileName =
".bookmarkFile";
152 animateSensor =
new SoTimerSensor(
153 G4OpenInventorXtExaminerViewer::animateSensorCB,
this);
154 animateSensorRotation =
new SoTimerSensor(
155 G4OpenInventorXtExaminerViewer::animateSensorRotationCB,
this);
157 currentState = GENERAL;
158 myCam =
new SoPerspectiveCamera;
162 curViewPtName =
new char[MAX_VP_NAME + 1];
163 left_right = up_down = 0;
169 lshiftdown = rshiftdown =
false;
172 lctrldown = rctrldown =
false;
176 prevColorField = NULL;
179 openFileDialog = newFileDialog = listsDialog = (Widget) NULL;
180 loadRefCoordsDialog = saveRefCoordsDialog = NULL;
181 loadSceneGraphDialog = saveSceneGraphDialog = NULL;
182 myElementList = NULL;
184 newSceneGraph = NULL;
185 zcoordSetFlag =
false;
192 static const char * superimposed[] = {
193 "#Inventor V2.1 ascii",
"",
200 " OrthographicCamera ",
206 " DEF soxt->callback Callback { }",
209 " DEF soxt->translation Translation ",
211 " translation 0 0 0",
213 " DEF soxt->scale Scale ",
215 " scaleFactor 1 1 1",
217 " DEF soxt->geometry Coordinate3 ",
221 " -0.81 -0.04 0, -0.81 0 0,",
222 " -0.81 0.04 0, 0 -0.04 0,",
224 " 0.81 -0.04 0, 0.81 0 0,",
227 " 0.81 0.02 0, 0.81 -0.02 0,",
230 " 0.4 0.01 0, 0.4 -0.01 0,",
235 " DEF soxt->animSpeedOutlineSwitch Switch ",
240 " emissiveColor 0 0 0",
246 " 12, 11, 10, 9, -1",
251 " DEF soxt->axisSwitch Switch ",
270 " DEF soxt->animSpeedSwitch Switch ",
275 " emissiveColor 0 1 0",
281 " 16, 15, 14, 13, -1",
287 " DEF soxt->curInfoSwitch Switch ",
290 " DEF soxt->curInfoTrans Translation ",
292 " translation 10 20 30 ",
294 " DEF soxt->curInfoFont Font ",
296 " name defaultFont:Bold",
299 " DEF soxt->curInfoText Text2 ",
308 " DEF soxt->mouseOverTransLogName Translation ",
310 " translation 0 0 0 ",
312 " DEF soxt->mouseOverFontLogName Font ",
314 " name defaultFont:Bold",
317 " DEF soxt->mouseOverTextLogName Text2 { } ",
321 " DEF soxt->mouseOverTransSolid Translation ",
323 " translation 0 0 0 ",
325 " DEF soxt->mouseOverFontSolid Font ",
327 " name defaultFont:Bold",
330 " DEF soxt->mouseOverTextSolid Text2 { } ",
334 " DEF soxt->mouseOverTransMaterial Translation ",
336 " translation 0 0 0 ",
338 " DEF soxt->mouseOverFontMaterial Font ",
340 " name defaultFont:Bold",
343 " DEF soxt->mouseOverTextMaterial Text2 { } ",
347 " DEF soxt->mouseOverTransZPos Translation ",
349 " translation 0 0 0 ",
351 " DEF soxt->mouseOverFontZPos Font ",
353 " name defaultFont:Bold",
356 " DEF soxt->mouseOverTextZPos Text2 { } ",
362 for (i = bufsize = 0; superimposed[i]; i++)
363 bufsize += strlen(superimposed[i]) + 1;
364 char * buf =
new char[bufsize + 1];
365 for (i = bufsize = 0; superimposed[i]; i++) {
366 strcpy(buf + bufsize, superimposed[i]);
367 bufsize += strlen(superimposed[i]);
371 SoInput * input =
new SoInput;
372 input->setBuffer(buf, bufsize);
373 SbBool ok = SoDB::read(input, this->superimposition);
378 this->superimposition->ref();
380 this->sscale = (SoScale *) this->getSuperimpositionNode(
381 this->superimposition,
"soxt->scale");
382 this->stranslation = (SoTranslation *) this->getSuperimpositionNode(
383 this->superimposition,
"soxt->translation");
384 this->sgeometry = (SoCoordinate3 *) this->getSuperimpositionNode(
385 this->superimposition,
"soxt->geometry");
386 this->axisSwitch = (SoSwitch *) this->getSuperimpositionNode(
387 this->superimposition,
"soxt->axisSwitch");
388 this->animSpeedOutlineSwitch = (SoSwitch *) this->getSuperimpositionNode(
389 this->superimposition,
"soxt->animSpeedOutlineSwitch");
390 this->animSpeedSwitch = (SoSwitch *) this->getSuperimpositionNode(
391 this->superimposition,
"soxt->animSpeedSwitch");
392 this->curInfoSwitch = (SoSwitch *) this->getSuperimpositionNode(
393 this->superimposition,
"soxt->curInfoSwitch");
394 this->curInfoTrans = (SoTranslation *) this->getSuperimpositionNode(
395 this->superimposition,
"soxt->curInfoTrans");
396 this->curInfoFont = (SoFont *) this->getSuperimpositionNode(
397 this->superimposition,
"soxt->curInfoFont");
398 this->curInfoText = (SoText2 *) this->getSuperimpositionNode(
399 this->superimposition,
"soxt->curInfoText");
400 this->mouseOverTransLogName = (SoTranslation*)this->getSuperimpositionNode(
401 this->superimposition,
"soxt->mouseOverTransLogName");
402 this->mouseOverFontLogName = (SoFont *) this->getSuperimpositionNode(
403 this->superimposition,
"soxt->mouseOverFontLogName");
404 this->mouseOverTextLogName = (SoText2 *) this->getSuperimpositionNode(
405 this->superimposition,
"soxt->mouseOverTextLogName");
406 this->mouseOverTransSolid = (SoTranslation *) this->getSuperimpositionNode(
407 this->superimposition,
"soxt->mouseOverTransSolid");
408 this->mouseOverFontSolid = (SoFont *) this->getSuperimpositionNode(
409 this->superimposition,
"soxt->mouseOverFontSolid");
410 this->mouseOverTextSolid = (SoText2 *) this->getSuperimpositionNode(
411 this->superimposition,
"soxt->mouseOverTextSolid");
412 this->mouseOverTransMaterial = (SoTranslation*)this->getSuperimpositionNode(
413 this->superimposition,
"soxt->mouseOverTransMaterial");
414 this->mouseOverFontMaterial = (SoFont *) this->getSuperimpositionNode(
415 this->superimposition,
"soxt->mouseOverFontMaterial");
416 this->mouseOverTextMaterial = (SoText2 *) this->getSuperimpositionNode(
417 this->superimposition,
"soxt->mouseOverTextMaterial");
418 this->mouseOverTransZPos = (SoTranslation *) this->getSuperimpositionNode(
419 this->superimposition,
"soxt->mouseOverTransZPos");
420 this->mouseOverFontZPos = (SoFont *) this->getSuperimpositionNode(
421 this->superimposition,
"soxt->mouseOverFontZPos");
422 this->mouseOverTextZPos = (SoText2 *) this->getSuperimpositionNode(
423 this->superimposition,
"soxt->mouseOverTextZPos");
425 SoCallback * cb = (SoCallback *) this->getSuperimpositionNode(
426 this->superimposition,
"soxt->callback");
427 cb->setCallback(superimpositionCB,
this);
429 this->addSuperimposition(this->superimposition);
430 this->setSuperimpositionEnabled(this->superimposition,
FALSE);
431 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
432 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
433 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
461 G4OpenInventorXtExaminerViewer::getSuperimpositionNode(SoNode *root,
465 this->searcher =
new SoSearchAction;
467 searcher->setName(SbName(name));
468 searcher->setInterest(SoSearchAction::FIRST);
469 searcher->setSearchingAll(
TRUE);
470 searcher->apply(root);
471 assert(searcher->getPath());
472 return searcher->getPath()->getTail();
476 void G4OpenInventorXtExaminerViewer::superimpositionCB(
void * closure,
486 void G4OpenInventorXtExaminerViewer::superimpositionEvent(SoAction * action)
489 if (!action->isOfType(SoGLRenderAction::getClassTypeId()))
491 SbViewportRegion vpRegion =
492 ((SoGLRenderAction *) action)->getViewportRegion();
493 SbVec2s viewportSize = vpRegion.getViewportSizePixels();
495 float aspect = float(viewportSize[0]) / float(viewportSize[1]);
496 float factorx = 1.0f / float(viewportSize[1]) * 220.0f;
497 float factory = factorx;
500 this->stranslation->translation.setValue(SbVec3f(0.0
f, -0.4
f, 0.0
f));
502 this->stranslation->translation.setValue(
503 SbVec3f(0.0
f, -0.4
f / aspect, 0.0
f));
507 if (viewportSize[0] > 500)
508 factorx *= 500.0f / 400.0f;
510 factorx *= float(viewportSize[0]) / 400.0f;
511 this->sscale->scaleFactor.setValue(SbVec3f(factorx, factory, 1.0
f));
513 float xInfo, yInfo, xMouseLogName, yMouseLogName, xMouseSolid, yMouseSolid,
514 xMouseMaterial, yMouseMaterial, xMouseZPos, yMouseZPos;
518 yMouseLogName = -.75;
521 xMouseMaterial = 0.0;
522 yMouseMaterial = -.81;
528 xMouseSolid *= aspect;
529 xMouseMaterial *= aspect;
530 this->curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
531 this->mouseOverTransLogName->translation.setValue(
532 SbVec3f(xMouseLogName, yMouseLogName, 0.0));
533 this->mouseOverTransSolid->translation.setValue(
534 SbVec3f(xMouseSolid, yMouseSolid, 0.0));
535 this->mouseOverTransMaterial->translation.setValue(
536 SbVec3f(xMouseMaterial, yMouseMaterial, 0.0));
537 this->mouseOverTransZPos->translation.setValue(
538 SbVec3f(xMouseZPos, yMouseZPos, 0.0));
541 yMouseSolid /= aspect;
542 yMouseMaterial /= aspect;
543 this->curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
544 this->mouseOverTransLogName->translation.setValue(
545 SbVec3f(xMouseLogName, yMouseLogName, 0.0));
546 this->mouseOverTransSolid->translation.setValue(
547 SbVec3f(xMouseSolid, yMouseSolid, 0.0));
548 this->mouseOverTransMaterial->translation.setValue(
549 SbVec3f(xMouseMaterial, yMouseMaterial, 0.0));
550 this->mouseOverTransZPos->translation.setValue(
551 SbVec3f(xMouseZPos, yMouseZPos, 0.0));
554 if (currentState == VIEWPOINT) {
555 this->curInfoFont->size.setValue(15);
556 this->curInfoFont->name.setValue(
"defaultFont:Italic");
557 this->curInfoText->string.setValue(SbString(curViewPtName));
559 else if(currentState == GENERAL) {
560 this->curInfoFont->size.setValue(16);
561 this->curInfoFont->name.setValue(
"defaultFont:Bold");
562 this->curInfoText->string.setValue(SbString(
""));
565 if (refParticleIdx < (
int) refParticleTrajectory.size() - 1) {
566 this->curInfoFont->size.setValue(16);
567 this->curInfoFont->name.setValue(
"defaultFont:Bold");
569 sprintf(zPos,
"%7.2f [m]", refZPositions[refParticleIdx] / 1000);
570 this->curInfoText->string.setValue(SbString(zPos));
578 if (superimposition != NULL) {
579 removeSuperimposition(superimposition);
580 superimposition->unref();
581 superimposition = NULL;
583 if (animateSensor->isScheduled())
584 animateSensor->unschedule();
585 delete animateSensor;
586 delete sceneChangeSensor;
588 delete[] curViewPtName;
599 Atom WM_DELETE_WINDOW;
602 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::buildWidget",
"Error: Parent is null.");
605 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
606 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
607 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
608 XtSetArg(args[3], XmNbottomAttachment, XmATTACH_FORM);
609 Widget form = XmCreateForm(parent, (
char *)
"Form", args, 4);
612 shell = XtParent(form);
613 WM_DELETE_WINDOW = XInternAtom(XtDisplay(parent),
"WM_DELETE_WINDOW",
615 XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW,
616 (XtCallbackProc)closeMainWindowCB,
this);
618 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
619 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
620 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
621 menuBar = XmCreateMenuBar(form, (
char *)
"MenuBar", args, 3);
622 XtManageChild(menuBar);
625 this->
addButton(fileMenu,
"Open Viewpoint File...", openViewPtFileCB);
626 addButton(fileMenu,
"New Viewpoint File", newViewPtFileCB);
627 addButton(fileMenu,
"Load Ref. Coords", loadRefCoordsDialogCB);
628 addButton(fileMenu,
"Save Ref. Coords", saveRefCoordsDialogCB);
629 addButton(fileMenu,
"Load Scene Graph", loadSceneGraphDialogCB);
630 addButton(fileMenu,
"Save Scene Graph", saveSceneGraphDialogCB);
632 XmCreateSeparatorGadget(fileMenu, (
char *)
"Separator", NULL, 0));
634 Widget menu =
addMenu(
"Tools");
635 addButton(menu,
"Animate Ref. Particle", animateRefParticleCB);
636 addButton(menu,
"Go to start of Ref path", gotoRefPathStartCB);
637 addButton(menu,
"Invert Ref path", invertRefPathCB);
639 Widget viewerBase = SoXtFullViewer::buildWidget(form);
641 XtSetArg(args[0], XmNtopAttachment, XmATTACH_WIDGET);
642 XtSetArg(args[1], XmNtopWidget, menuBar);
643 XtSetArg(args[2], XmNleftAttachment, XmATTACH_FORM);
644 XtSetArg(args[3], XmNrightAttachment, XmATTACH_FORM);
645 XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM);
646 XtSetValues(viewerBase, args, 5);
656 Widget menu = XmCreatePulldownMenu(menuBar, (
char *) name.c_str(), NULL, 0);
658 XtSetArg(args[0], XmNsubMenuId, menu);
659 Widget w = XmCreateCascadeButton(menuBar, (
char *) name.c_str(), args, 1);
670 Widget button = XmCreatePushButton(menu, (
char *) name.c_str(), NULL, 0);
671 XtManageChild(button);
672 XtAddCallback(button, XmNactivateCallback, cb,
this);
678 SbPList * buttonlist)
682 Widget saveViewPtButton, abbrOutputButton, pickRefPathButton;
685 SoXtExaminerViewer::createViewerButtons(parent, buttonlist);
688 Widget emptyButton = XtVaCreateManagedWidget(
"", xmPushButtonWidgetClass,
690 buttonlist->append(emptyButton);
694 XtSetArg(args[n], XmNtopPosition, 1); n++;
695 XtSetArg(args[n], XmNbottomPosition, 2); n++;
696 XtSetArg(args[n], XmNleftPosition, 0); n++;
697 XtSetArg(args[n], XmNrightPosition, 1); n++;
698 XtSetArg(args[n], XmNarrowDirection, XmARROW_LEFT); n++;
699 XtSetArg(args[n], XmNsensitive, False); n++;
700 prevViewPtButton = XmCreateArrowButtonGadget(parent, (
char *)
"ArrowL",
702 XtManageChild(prevViewPtButton);
703 XtAddCallback(prevViewPtButton, XmNactivateCallback,
704 G4OpenInventorXtExaminerViewer::prevViewPtCB,
this);
705 buttonlist->append(prevViewPtButton);
709 XtSetArg(args[n], XmNtopPosition, 1); n++;
710 XtSetArg(args[n], XmNbottomPosition, 2); n++;
711 XtSetArg(args[n], XmNleftPosition, 0); n++;
712 XtSetArg(args[n], XmNrightPosition, 1); n++;
713 XtSetArg(args[n], XmNarrowDirection, XmARROW_RIGHT); n++;
714 XtSetArg(args[n], XmNsensitive, False); n++;
715 nextViewPtButton = XmCreateArrowButtonGadget(parent, (
char *)
"ArrowR",
717 XtManageChild(nextViewPtButton);
718 XtAddCallback(nextViewPtButton, XmNactivateCallback,
719 G4OpenInventorXtExaminerViewer::nextViewPtCB,
this);
720 buttonlist->append(nextViewPtButton);
723 saveViewPtButton = XtVaCreateManagedWidget(
"Save", xmPushButtonWidgetClass,
725 XtAddCallback(saveViewPtButton, XmNactivateCallback,
726 G4OpenInventorXtExaminerViewer::saveViewPtCB,
this);
727 Pixmap saveVP, saveVP_ins;
731 saveViewPt_xpm,
TRUE);
732 XtVaSetValues(saveViewPtButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
733 saveVP, XmNselectPixmap, saveVP, XmNlabelInsensitivePixmap,
734 saveVP_ins, XmNselectInsensitivePixmap, saveVP_ins, NULL);
735 buttonlist->append(saveViewPtButton);
738 abbrOutputButton = XtVaCreateManagedWidget(
"Abbr",
739 xmToggleButtonWidgetClass, parent, XmNindicatorOn, False, NULL);
740 XtAddCallback(abbrOutputButton, XmNdisarmCallback, G4OpenInventorXtExaminerViewer::abbrOutputCB,
742 Pixmap consolexpm, consolexpm_ins;
747 XtVaSetValues(abbrOutputButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
748 consolexpm, XmNselectPixmap, consolexpm, XmNlabelInsensitivePixmap,
749 consolexpm_ins, XmNselectInsensitivePixmap, consolexpm_ins, NULL);
750 buttonlist->append(abbrOutputButton);
753 pickRefPathButton = XtVaCreateManagedWidget(
"Refpath", xmPushButtonWidgetClass,
755 XtAddCallback(pickRefPathButton, XmNactivateCallback,
756 G4OpenInventorXtExaminerViewer::pickRefPathCB,
this);
757 Pixmap favoritesxpm, favoritesxpm_ins;
761 favorites_xpm,
TRUE);
762 XtVaSetValues(pickRefPathButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
763 favoritesxpm, XmNselectPixmap, favoritesxpm, XmNlabelInsensitivePixmap,
764 favoritesxpm_ins, XmNselectInsensitivePixmap, favoritesxpm_ins, NULL);
765 buttonlist->append(pickRefPathButton);
774 SoXtExaminerViewer::afterRealizeHook();
778 SoCamera *cam = getCamera();
780 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
782 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
785 ((SoOrthographicCamera *) cam)->height.getValue();
789 ((SoOrthographicCamera *) cam)->height.getValue();
792 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
794 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
800 fileIn.open(fileName.c_str());
801 if (!fileIn.fail()) {
803 String dialogName = (
char *)
"Error Loading File";
804 std::string msg =
"Wrong or corrupted input file.";
809 fileOut.seekp(0, std::ios::end);
810 constructListsDialog(getParentWidget(),
this, NULL);
812 if (viewPtList.size()) {
816 XtSetSensitive(nextViewPtButton, True);
817 XtSetSensitive(prevViewPtButton, True);
824 fileOut.open(fileName.c_str());
825 constructListsDialog(getParentWidget(),
this, NULL);
830 SoSeparator *root = (SoSeparator *) (getSceneManager()->getSceneGraph());
832 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::afterRealizeHook",
"Root is null.");
834 root->addChild(myCam);
837 sceneChangeSensor =
new SoNodeSensor;
838 sceneChangeSensor->setFunction(sceneChangeCB);
839 sceneChangeSensor->attach(root);
840 sceneChangeSensor->setData(
this);
846 SoEventCallback *moCB =
new SoEventCallback;
847 moCB->addEventCallback(
848 SoLocation2Event::getClassTypeId(),
849 mouseoverCB, static_cast<void *>(
this));
850 root->addChild(moCB);
854 SoEventCallback *pickCB =
new SoEventCallback;
855 pickCB->addEventCallback(
856 SoMouseButtonEvent::getClassTypeId(),
857 pickingCB, static_cast<void *>(
this));
858 root->addChild(pickCB);
867 SoCamera *cam = getCamera();
873 SbVec3f camPosNew = prevPt - (
camDir*distance);
874 cam->position = camPosNew;
876 cam->focalDistance = (prevPt - camPosNew).length();
880 if (animateSensorRotation->isScheduled()) {
881 animateSensorRotation->unschedule();
884 animateSensorRotation->setBaseTime(SbTime::getTimeOfDay());
885 animateSensorRotation->setInterval(SbTime(0.02));
886 animateSensorRotation->schedule();
895 SoCamera *cam = getCamera();
900 if(refParticleTrajectory.size() == 0) {
905 distance = (cam->position.getValue() - center).length();
907 cam->position.setValue(center + offsetFromCenter*distance);
908 cam->focalDistance = (cam->position.getValue() - center).length();
909 cam->pointAt(center, upVector);
915 if (refParticleIdx >= (
int) refParticleTrajectory.size() - 1) {
916 prevPt = refParticleTrajectory[refParticleIdx - step];
917 dist = (prevPt - cam->position.getValue()).length();
922 if (refParticleIdx < 0) {
923 prevPt = refParticleTrajectory[refParticleIdx + step];
924 dist = (prevPt - cam->position.getValue()).length();
925 refParticleIdx = refParticleTrajectory.size() - 2;
929 p1 = refParticleTrajectory[refParticleIdx];
930 p2 = refParticleTrajectory[refParticleIdx + step];
933 particleDir = p2 - p1;
934 particleDir.normalize();
936 if(prevParticleDir == SbVec3f(0,0,0)){
947 SbRotation rot(SbVec3f(0,0,1), particleDir);
952 else if(particleDir != prevParticleDir) {
955 SbRotation rot(prevParticleDir, particleDir);
961 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
963 distance = (prevPt - cam->position.getValue()).length();
968 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
970 distance = (prevPt - cam->position.getValue()).length();
977 prevPt.getValue(x,y,z);
980 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
981 camPosNew = p2 - (
camDir*distance);
983 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
984 camPosNew = p2 - (
camDir);
987 cam->position = camPosNew;
994 camPosNew.getValue(x,y,z);
996 prevParticleDir = particleDir;
1004 void G4OpenInventorXtExaminerViewer::pickingCB(
void *aThis,
1005 SoEventCallback *eventCB)
1007 SoHandleEventAction* action = eventCB->getAction();
1008 const SoPickedPoint *
pp = action->getPickedPoint();
1013 SoPath* path = pp->getPath();
1014 SoNode* node = ((SoFullPath*)path)->getTail();
1016 if(node->getTypeId() == SoLineSet::getClassTypeId()){
1026 SoLineSet * trajectory = (SoLineSet *)node;
1032 SoSeparator * grpNode =
1033 (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1038 int nodeIndex = grpNode->findChild(trajectory);
1041 SoCoordinate3 * coords = 0;
1045 for(
int i = 0; i < 100; ++i) {
1048 tmpNode = grpNode->getChild(nodeIndex);
1049 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()){
1051 coords = (SoCoordinate3 *)tmpNode;
1057 String dialogName = (
char *)
"No coordinates";
1058 std::string msg =
"Could not find the coordinates node"
1059 " for the picked trajectory."
1060 " Reference trajectory not set";
1066 if ((This->lshiftdown) || (This->rshiftdown))
1067 This->setReferencePath(trajectory, coords,
true);
1069 This->setReferencePath(trajectory, coords,
false);
1077 if(attHolder && attHolder->
GetAttDefs().size()) {
1079 std::string strTrajPoint =
"G4TrajectoryPoint:";
1080 std::ostringstream oss;
1081 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1086 if(oss.str().find(strTrajPoint) != std::string::npos) {
1101 G4String cls((
char*)node->getTypeId().getName().getString());
1102 G4cout <<
"SoNode : " << node
1103 <<
" SoType : " << cls
1104 <<
" name : " << name
1121 if(attHolder && attHolder->
GetAttDefs().size()) {
1122 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1128 G4String cls((
char*)node->getTypeId().getName().getString());
1129 G4cout <<
"SoNode : " << node
1130 <<
" SoType : " << cls
1131 <<
" name : " << name
1137 eventCB->setHandled();
1142 void G4OpenInventorXtExaminerViewer::mouseoverCB(
void *aThis, SoEventCallback *eventCB)
1144 SoHandleEventAction* action = eventCB->getAction();
1145 const SoPickedPoint *pp = action->getPickedPoint();
1153 const SbViewportRegion & viewportRegion = action->getViewportRegion();
1155 std::string sLogName;
1157 std::stringstream ssZPos;
1158 std::stringstream ssSolids;
1159 std::stringstream ssMaterials;
1160 SoPath * path = pp->getPath();
1161 SoNode* node = ((SoFullPath*)path)->getTail();
1163 if(node->getTypeId() == Geant4_SoPolyhedron::getClassTypeId()) {
1165 sLogName =
"Logical Volume: ";
1168 SoGetBoundingBoxAction bAction(viewportRegion);
1169 bAction.apply((SoFullPath*)path);
1170 SbBox3f bBox = bAction.getBoundingBox();
1171 SbVec3f center = bBox.getCenter();
1172 center.getValue(x,y,z);
1173 ssZPos <<
"Pos: " << x <<
" " << y <<
" " <<
z;
1176 if(attHolder && attHolder->
GetAttDefs().size()) {
1178 std::vector<const std::map<G4String,G4AttDef>*> vecDefs =
1180 std::vector<const std::vector<G4AttValue>*> vecVals =
1182 for (
size_t i = 0; i < vecDefs.size(); ++i) {
1183 const std::vector<G4AttValue> * vals = vecVals[i];
1185 std::vector<G4AttValue>::const_iterator iValue;
1187 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1188 const G4String& valueName = iValue->GetName();
1191 if(valueName ==
"Solid") {
1192 if(ssSolids.str() ==
"")
1193 ssSolids <<
"Solid Name: " << value;
1195 ssSolids <<
", " <<
value;
1198 if(valueName ==
"Material") {
1199 if(ssMaterials.str() ==
"")
1200 ssMaterials <<
"Material Name: " << value;
1202 ssMaterials <<
", " <<
value;
1209 bool redraw =
false;
1210 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) != sLogName) {
1211 This->mouseOverTextLogName->string.setValue(SbString(sLogName.c_str()));
1214 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) != ssSolids.str()) {
1215 This->mouseOverTextSolid->string.setValue(SbString(ssSolids.str().c_str()));
1218 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) != ssMaterials.str()){
1219 This->mouseOverTextMaterial->string.setValue(SbString(ssMaterials.str().c_str()));
1222 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) != ssZPos.str()) {
1223 This->mouseOverTextZPos->string.setValue(SbString(ssZPos.str().c_str()));
1228 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
1229 This->scheduleRedraw();
1232 eventCB->setHandled();
1235 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) !=
"") {
1236 This->mouseOverTextLogName->string.setValue(SbString(
""));
1237 This->scheduleRedraw();
1239 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) !=
"") {
1240 This->mouseOverTextSolid->string.setValue(SbString(
""));
1241 This->scheduleRedraw();
1243 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) !=
"") {
1244 This->mouseOverTextMaterial->string.setValue(SbString(
""));
1245 This->scheduleRedraw();
1247 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) !=
"") {
1248 This->mouseOverTextZPos->string.setValue(SbString(
""));
1249 This->scheduleRedraw();
1256 SoCamera *cam = getCamera();
1257 const SoType type(ev->getTypeId());
1259 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
1260 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
1262 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1263 || currentState == PAUSED_ANIMATION) {
1264 switch (me->getButton()) {
1265 case SoMouseButtonEvent::BUTTON4:
1266 if (me->getState() == SoButtonEvent::DOWN) {
1267 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1269 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1270 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1273 }
else if (cam->isOfType(
1274 SoOrthographicCamera::getClassTypeId())) {
1276 ((SoOrthographicCamera *) cam)->height.getValue();
1277 ((SoOrthographicCamera *) cam)->height = height + 5;
1282 case SoMouseButtonEvent::BUTTON5:
1283 if (me->getState() == SoButtonEvent::DOWN) {
1284 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1286 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1288 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1291 }
else if (cam->isOfType(
1292 SoOrthographicCamera::getClassTypeId())) {
1294 ((SoOrthographicCamera *) cam)->height.getValue();
1296 ((SoOrthographicCamera *) cam)->height = height - 5;
1305 if (currentState == GENERAL) {
1310 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
1311 SoKeyboardEvent * ke = (SoKeyboardEvent *) ev;
1313 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
1314 switch (ke->getKey()) {
1315 case SoKeyboardEvent::LEFT_SHIFT:
1316 this->lshiftdown =
true;
1318 case SoKeyboardEvent::RIGHT_SHIFT:
1319 this->rshiftdown =
true;
1321 case SoKeyboardEvent::LEFT_CONTROL:
1322 this->lctrldown =
true;
1324 case SoKeyboardEvent::RIGHT_CONTROL:
1325 this->rctrldown =
true;
1327 case SoKeyboardEvent::SPACE:
1328 if (currentState == ANIMATION
1329 || currentState == REVERSED_ANIMATION) {
1330 beforePausing = currentState;
1331 currentState = PAUSED_ANIMATION;
1332 if (animateSensor->isScheduled())
1333 animateSensor->unschedule();
1335 }
else if (currentState == PAUSED_ANIMATION) {
1337 if ((beforePausing == ANIMATION
1339 < (
int) refParticleTrajectory.size() - 1)
1340 || (beforePausing == REVERSED_ANIMATION
1341 && refParticleIdx > 0)) {
1342 currentState = beforePausing;
1343 animateRefParticle();
1349 case SoKeyboardEvent::ESCAPE:
1350 if (currentState == ANIMATION
1351 || currentState == REVERSED_ANIMATION
1352 || currentState == PAUSED_ANIMATION) {
1354 if (animateSensor->isScheduled())
1355 animateSensor->unschedule();
1356 currentState = prevState;
1357 refParticleIdx = prevRefIdx;
1358 setSuperimpositionEnabled(superimposition,
FALSE);
1363 if (currentState == VIEWPOINT) {
1364 setSuperimpositionEnabled(superimposition,
TRUE);
1365 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
1366 animSpeedOutlineSwitch->whichChild.setValue(
1368 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1376 case SoKeyboardEvent::DELETE:
1377 if (viewPtList.size()
1378 && (currentState != ANIMATION
1379 || currentState != REVERSED_ANIMATION
1380 || currentState != PAUSED_ANIMATION)) {
1381 String dialogName = (
char *)
"Delete Viewpoint";
1382 std::string msg =
"Are you sure you want to delete current viewpoint?";
1387 case SoKeyboardEvent::LEFT_ARROW:
1388 switch (currentState) {
1390 if ((this->lshiftdown) || (this->rshiftdown)){
1391 refParticleIdx -= step;
1394 else if ((this->lctrldown) || (this->rctrldown)){
1395 if (SoXtExaminerViewer::isAnimating())
1397 prevState = currentState;
1398 currentState = ROTATING;
1399 animateBtwPtsPeriod = 0.08f;
1411 if (SoXtExaminerViewer::isAnimating())
1413 prevState = currentState;
1414 currentState = ROTATING;
1415 animateBtwPtsPeriod = 0.08f;
1430 case REVERSED_ANIMATION:
1433 case PAUSED_ANIMATION:
1435 setStartingPtForAnimation();
1436 cam->position = myCam->position;
1440 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1443 this->bottomWheelMotion(
1444 this->getBottomWheelValue() + 0.1
f);
1454 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1455 "Unhandled viewer state");
1460 case SoKeyboardEvent::RIGHT_ARROW:
1461 switch(currentState){
1463 if ((this->lshiftdown) || (this->rshiftdown)){
1464 refParticleIdx += step;
1467 else if ((this->lctrldown) || (this->rctrldown)){
1468 if (SoXtExaminerViewer::isAnimating())
1470 prevState = currentState;
1471 currentState = ROTATING;
1472 animateBtwPtsPeriod = 0.08f;
1482 if (SoXtExaminerViewer::isAnimating())
1484 prevState = currentState;
1485 currentState = ROTATING;
1486 animateBtwPtsPeriod = 0.08f;
1498 case REVERSED_ANIMATION:
1501 case PAUSED_ANIMATION:
1503 setStartingPtForAnimation();
1504 cam->position = myCam->position;
1508 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1511 this->bottomWheelMotion(
1512 this->getBottomWheelValue() - 0.1
f);
1521 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1522 "Unhandled viewer state");
1527 case SoKeyboardEvent::DOWN_ARROW:
1528 switch(currentState){
1531 if ((this->lshiftdown) || (this->rshiftdown)){
1532 refParticleIdx -= step;
1536 if (SoXtExaminerViewer::isAnimating())
1538 prevState = currentState;
1539 currentState = ROTATING;
1540 animateBtwPtsPeriod = 0.08f;
1553 case REVERSED_ANIMATION:
1556 case PAUSED_ANIMATION:
1558 setStartingPtForAnimation();
1559 cam->position = myCam->position;
1565 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1566 this->leftWheelMotion(this->getLeftWheelValue() - 0.1
f);
1575 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1576 "Unhandled viewer state");
1581 case SoKeyboardEvent::UP_ARROW:
1582 switch(currentState){
1584 if ((this->lshiftdown) || (this->rshiftdown)){
1585 refParticleIdx -= step;
1589 if (SoXtExaminerViewer::isAnimating())
1591 prevState = currentState;
1592 currentState = ROTATING;
1593 animateBtwPtsPeriod = 0.08f;
1606 case REVERSED_ANIMATION:
1609 case PAUSED_ANIMATION:
1611 setStartingPtForAnimation();
1612 cam->position = myCam->position;
1618 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1619 this->leftWheelMotion(this->getLeftWheelValue() + 0.1
f);
1628 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1629 "Unhandled viewer state");
1634 case SoKeyboardEvent::PAGE_UP:
1635 switch(currentState){
1637 if (step < (
int) refParticleTrajectory.size() / 5)
1648 case REVERSED_ANIMATION:
1649 if(!animateSensor->isScheduled()){
1650 currentState = ANIMATION;
1652 < (
int) refParticleTrajectory.size() - 1) {
1656 animateRefParticle();
1665 case PAUSED_ANIMATION:
1670 if (beforePausing == ANIMATION) {
1675 beforePausing = ANIMATION;
1685 case SoKeyboardEvent::PAGE_DOWN:
1686 switch(currentState){
1692 if(!animateSensor->isScheduled()){
1693 currentState = REVERSED_ANIMATION;
1694 if (refParticleIdx > 1) {
1698 animateRefParticle();
1707 case REVERSED_ANIMATION:
1710 if (maxSpeed < -0.8)
1714 case PAUSED_ANIMATION:
1716 if (maxSpeed < -0.8)
1718 if (beforePausing == REVERSED_ANIMATION) {
1723 beforePausing = REVERSED_ANIMATION;
1733 case SoKeyboardEvent::E:
1734 this->escapeCallback(this->examinerObject);
1741 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
1742 switch (ke->getKey()) {
1743 case SoKeyboardEvent::LEFT_SHIFT:
1744 this->lshiftdown =
false;
1746 case SoKeyboardEvent::RIGHT_SHIFT:
1747 this->rshiftdown =
false;
1749 case SoKeyboardEvent::LEFT_CONTROL:
1750 this->lctrldown =
false;
1752 case SoKeyboardEvent::RIGHT_CONTROL:
1753 this->rctrldown =
false;
1761 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1762 || currentState == ROTATING)
1765 return SoXtExaminerViewer::processSoEvent(ev);
1769 void G4OpenInventorXtExaminerViewer::incSpeed() {
1770 if (std::ceil(animateBtwPtsPeriod * 100) >= 4) {
1771 if (speedStep > 0.08)
1775 animateBtwPtsPeriod -= speedStep;
1777 animateBtwPtsPeriod = 0.0;
1779 if (currentState != PAUSED_ANIMATION) {
1780 int lastIdx = refParticleTrajectory.size() - 1;
1781 if (refParticleIdx < lastIdx && !animateSensor->isScheduled())
1782 animateRefParticle();
1787 void G4OpenInventorXtExaminerViewer::decSpeed() {
1788 animateBtwPtsPeriod += speedStep;
1790 if (std::floor(animateBtwPtsPeriod * 100) == 12) {
1792 }
else if (animateBtwPtsPeriod > 0.12)
1798 if (animateSensor->isScheduled())
1799 animateSensor->unschedule();
1804 void G4OpenInventorXtExaminerViewer::updateSpeedIndicator(
void) {
1805 assert(this->sgeometry != NULL);
1807 SbVec3f * points = this->sgeometry->point.startEditing();
1809 if (points[10][0] == 0.0
f)
1810 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
1811 if (points[14][0] == 0.0
f)
1812 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
1813 points[10][0] = this->maxSpeed;
1814 points[11][0] = this->maxSpeed;
1815 points[14][0] = this->maxSpeed;
1816 points[15][0] = this->maxSpeed;
1817 this->sgeometry->point.finishEditing();
1819 if (this->maxSpeed == 0.0
f) {
1820 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
1821 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1825 void G4OpenInventorXtExaminerViewer::actualRedraw(
void) {
1826 switch (currentState) {
1828 case REVERSED_ANIMATION:
1829 case PAUSED_ANIMATION:
1830 updateSpeedIndicator();
1831 SoXtExaminerViewer::actualRedraw();
1834 SoXtExaminerViewer::actualRedraw();
1839 void G4OpenInventorXtExaminerViewer::setReferencePath(SoLineSet *lineset, SoCoordinate3 *coords,
bool append)
1880 SbVec3f refParticlePt;
1883 this->refParticleTrajectory.clear();
1885 for(
int i = 0; i < lineset->numVertices.getNum(); ++i){
1886 for(
int j = 0; j < lineset->numVertices[i]; ++j){
1887 refParticlePt = coords->point[j];
1888 this->refParticleTrajectory.push_back(refParticlePt);
1892 this->evenOutRefParticlePts();
1893 this->setReferencePathZPos();
1894 this->sortElements();
1898 void G4OpenInventorXtExaminerViewer::setReferencePathZPos()
1900 refZPositions.clear();
1901 refZPositions.push_back(0);
1903 for(
unsigned int i=0; i < this->refParticleTrajectory.size() - 1; ++i){
1904 dist = (refParticleTrajectory[i] -
1905 refParticleTrajectory[i + 1]).length();
1906 refZPositions.push_back(refZPositions[i] + dist);
1911 void G4OpenInventorXtExaminerViewer::findAndSetRefPath()
1913 SoSearchAction action;
1914 action.setType(SoLineSet::getClassTypeId(),
false);
1916 action.apply(this->getSceneGraph());
1918 SoPathList &pathList = action.getPaths();
1920 if(pathList.getLength() != 0){
1922 SoCoordinate3 * coords = NULL;
1923 std::vector<SoCoordinate3 *> coordvec;
1924 std::vector<SoLineSet *> linevec;
1926 bool refPathFound =
false;
1927 for(
int i = 0; i < pathList.getLength(); ++i) {
1928 SoFullPath *path = (SoFullPath *)pathList[i];
1931 for (
size_t j = 0; j < attHolder->
GetAttDefs().size(); ++j) {
1932 std::ostringstream oss;
1935 std::string findStr =
"Type of trajectory (Type): ";
1936 std::string compareValue =
"REFERENCE";
1937 size_t idx = oss.str().find(findStr);
1939 if(idx != std::string::npos) {
1940 if(oss.str().substr(idx + findStr.size(), compareValue.size()) == compareValue) {
1941 coords = this->getCoordsNode(path);
1943 refPathFound =
true;
1944 coordvec.push_back(coords);
1945 linevec.push_back((SoLineSet *)path->getTail());
1951 findStr =
"Track ID (ID): ";
1952 idx = oss.str().find(findStr);
1953 if(idx != std::string::npos) {
1955 std::string tmpstr = oss.str().substr(idx + findStr.size(),1);
1956 std::istringstream
buffer(tmpstr);
1963 const char * nextChar =
1964 oss.str().substr(idx + findStr.size() + 1,1).c_str();
1965 if(std::isdigit(nextChar[0]))
1968 coords = this->getCoordsNode(path);
1970 coordvec.push_back(coords);
1971 linevec.push_back((SoLineSet *)path->getTail());
1987 if(coordvec.empty())
1992 this->setReferencePath(linevec.back(), coordvec.back());
1998 float longestLength = 0.0;
2000 for(
unsigned int i=0;i < linevec.size(); ++i){
2003 std::vector<SbVec3f> trajectory;
2005 for(
int j=0; j < linevec[i]->numVertices.getNum(); ++j){
2007 for(
int k=0; k < linevec[i]->numVertices[j]; ++k){
2008 trajectory.push_back(coordvec[i]->point[k]);
2013 float tmpLength=0.0;
2014 for(
unsigned int j=0; j < trajectory.size() - 1; ++j){
2015 tmpLength += (trajectory[j] - trajectory[j + 1]).length();
2018 if(tmpLength > longestLength){
2020 longestLength = tmpLength;
2025 this->setReferencePath(linevec[longestIdx], coordvec[longestIdx]);
2030 SoCoordinate3 * G4OpenInventorXtExaminerViewer::getCoordsNode(SoFullPath *path)
2032 SoLineSet *trajectory = (SoLineSet *)path->getTail();
2033 SoSeparator * grpNode = (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
2034 int nodeIndex = grpNode->findChild(trajectory);
2039 for(
int i = 0; i < 100; ++i){
2042 tmpNode = grpNode->getChild(nodeIndex);
2043 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()){
2045 return (SoCoordinate3 *)tmpNode;
2054 void G4OpenInventorXtExaminerViewer::getSceneElements()
2056 std::string field, eltName;
2058 std::map<std::string, int> duplicates;
2059 std::map<std::string, int> sceneElts;
2060 SoSearchAction search;
2062 SoGroup *root = (SoGroup *)getSceneManager()->getSceneGraph();
2064 SoBaseKit::setSearchingChildren(
TRUE);
2067 search.setSearchingAll(
TRUE);
2069 search.setType(Geant4_SoPolyhedron::getClassTypeId(), 0);
2072 SoPathList &
pl = search.getPaths();
2076 for(
int i = 0; i < pl.getLength(); i++) {
2077 SoFullPath *path = (SoFullPath *)pl[i];
2079 eltName = node->getName();
2080 if(duplicates.count(eltName))
2081 duplicates[eltName]++;
2083 duplicates[eltName] = 1;
2086 for(
int i = 0; i < pl.getLength(); i++) {
2088 std::stringstream ssCount;
2089 SoFullPath *path = (SoFullPath *)pl[i];
2091 eltName = node->getName();
2093 if(duplicates[eltName] == 1)
2096 if(sceneElts.count(eltName))
2097 sceneElts[eltName]++;
2099 sceneElts[eltName] = 1;
2101 ssCount << sceneElts[eltName];
2105 field += ssCount.str();
2107 SoGetBoundingBoxAction bAction(getViewportRegion());
2108 bAction.apply(path);
2109 SbBox3f bBox = bAction.getBoundingBox();
2111 SbVec3f centr = bBox.getCenter();
2112 centr.getValue(x,y,z);
2115 sceneElement el = { field, path, centr, 0.0 };
2116 this->sceneElements.push_back(el);
2121 float G4OpenInventorXtExaminerViewer::sqrlen(
const SbVec3f &
a)
2125 return x*x + y*y + z*
z;
2129 void G4OpenInventorXtExaminerViewer::distanceToTrajectory(
const SbVec3f &q,
2131 SbVec3f &closestPoint,
2166 const size_t count = this->refParticleTrajectory.size();
2169 SbVec3f
b = this->refParticleTrajectory[0];
2170 SbVec3f dbq = b - q;
2171 float sqrDist = sqrlen(dbq);
2174 for (
size_t i = 1; i < count; ++i) {
2175 const SbVec3f a =
b;
2176 const SbVec3f daq = dbq;
2177 b = this->refParticleTrajectory[i];
2179 const SbVec3f dab = a -
b;
2181 float dab_x, dab_y, dab_z;
2182 dab.getValue(dab_x,dab_y,dab_z);
2183 float daq_x, daq_y, daq_z;
2184 daq.getValue(daq_x, daq_y, daq_z);
2185 float dbq_x, dbq_y, dbq_z;
2186 dbq.getValue(dbq_x, dbq_y, dbq_z);
2188 const float inv_sqrlen = 1./sqrlen(dab);
2189 const float t = (dab_x*daq_x + dab_y*daq_y + dab_z*daq_z)*inv_sqrlen;
2200 current_dist = daq_x*daq_x + daq_y*daq_y + daq_z*daq_z
2201 - t*(daq_x*dab_x + daq_y*dab_y + daq_z*dab_z)
2202 + t*t*(dab_x*dab_x + dab_y*dab_y + dab_z*dab_z);
2207 current_dist = sqrlen(dbq);
2210 if (current_dist < sqrDist){
2211 sqrDist = current_dist;
2212 closestPoint = a + t*(b-
a);
2217 dist = std::sqrt(sqrDist);
2221 void G4OpenInventorXtExaminerViewer::sortElements()
2223 if(this->refParticleTrajectory.empty())
2226 float * trajLength =
new float[this->refParticleTrajectory.size()];
2227 typedef std::map<elementForSorting, sceneElement> sortedMap;
2233 std::vector<SbVec3f>::iterator itRef = this->refParticleTrajectory.begin();
2236 trajLength[trajIndex] = 0.0;
2239 for(; itRef != this->refParticleTrajectory.end(); ++itRef, ++trajIndex){
2240 trajLength[trajIndex] = trajLength[trajIndex-1] + (*itRef - prevPoint).length();
2248 SoGetBoundingBoxAction bAction(this->getViewportRegion());
2249 SbVec3f elementCoord;
2250 std::vector<sceneElement>::iterator itEl;
2252 elementForSorting el;
2253 for(itEl = this->sceneElements.begin(), elementIndex = 0;
2254 itEl != this->sceneElements.end(); ++itEl, ++elementIndex){
2255 bAction.apply(itEl->path);
2256 elementCoord = bAction.getBoundingBox().getCenter();
2259 distanceToTrajectory(elementCoord, el.smallestDistance, el.closestPoint, index);
2260 itEl->closestPointZCoord = el.closestPointZCoord = trajLength[
index];
2261 el.distanceToBeamlineStart = (itEl->center - this->refParticleTrajectory[0]).length();
2268 sorted.insert(std::make_pair(el,*itEl));
2272 this->sceneElements.clear();
2274 sortedMap::iterator itSorted = sorted.begin();
2275 for(; itSorted != sorted.end(); itSorted++)
2276 this->sceneElements.push_back(itSorted->second);
2278 this->zcoordSetFlag =
true;
2281 Widget formTop = XtNameToWidget(this->listsDialog,
"FormTop");
2282 Widget formTopRight = XtNameToWidget(formTop,
"FormTopRight");
2284 this->createElementsList(formTopRight);
2286 delete[] trajLength;
2290 void G4OpenInventorXtExaminerViewer::createElementsList(Widget formTopRight)
2292 if(this->myElementList != NULL)
2293 XtUnmanageChild(this->myElementList);
2295 int size = this->sceneElements.size();
2296 XmString *elements = (XmString *) XtMalloc(size *
sizeof(XmString));
2298 std::vector<sceneElement>::const_iterator it;
2300 std::stringstream ss;
2301 for(it=this->sceneElements.begin(); it!=this->sceneElements.end(); ++it) {
2304 ss <<
" [" << it->closestPointZCoord <<
"]";
2305 elements[count] = XmStringCreateLocalized((
char *)ss.str().c_str());
2316 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2318 labelRight = XmCreateLabelGadget(formTopRight, (
char*)
"Element [S mm]",
2320 XtManageChild(labelRight);
2324 XtSetArg(args[n], XmNvisibleItemCount, 7); n++;
2325 XtSetArg(args[n], XmNitemCount, size); n++;
2326 XtSetArg(args[n], XmNitems, elements); n++;
2327 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2328 XtSetArg(args[n], XmNtopWidget, labelRight); n++;
2329 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2330 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2331 XtSetArg(args[n], XmNwidth, 280); n++;
2334 this->myElementList = XmCreateScrolledList(formTopRight, (
char *)
"ListRight", args, n);
2336 XtAddCallback(this->myElementList, XmNbrowseSelectionCallback,
2337 (XtCallbackProc) lookAtSceneElementCB,
this);
2339 XtManageChild(this->myElementList);
2341 if (elements != NULL) {
2342 for (
int i = 0; i < size; i++)
2343 XmStringFree(elements[i]);
2344 XtFree((
char *) elements);
2352 void G4OpenInventorXtExaminerViewer::constructListsDialog(Widget w,
2353 XtPointer client_data,
2357 if (This->listsDialog) {
2361 if (This->currentState == ANIMATION || This->currentState == PAUSED_ANIMATION) {
2362 if (This->animateSensor->isScheduled())
2363 This->animateSensor->unschedule();
2364 This->refParticleIdx = This->prevRefIdx;
2365 This->restoreCamera();
2366 This->currentState = This->prevState;
2370 This->refParticleIdx = 0;
2371 if (This->refParticleTrajectory.size()){
2372 This->prevPt = This->refParticleTrajectory[0];
2375 This->getSceneElements();
2379 Atom WM_DELETE_WINDOW;
2384 topShell = SoXt::getShellWidget(This->getParentWidget());
2387 std::string dialogNameStr = This->fileName.substr(This->fileName.rfind(
'/') + 1);
2388 const int nDialog = dialogNameStr.size() + 1;
2389 char *dialogName =
new char[nDialog];
2390 strncpy(dialogName, dialogNameStr.c_str(), nDialog);
2393 XtSetArg(args[n], XmNx, 610); n++;
2394 This->myShellDialog = XmCreateDialogShell(topShell, dialogName, args, n);
2396 delete[] dialogName;
2397 WM_DELETE_WINDOW = XInternAtom(XtDisplay(w),
"WM_DELETE_WINDOW", False);
2398 XmAddWMProtocolCallback(This->myShellDialog, WM_DELETE_WINDOW,
2399 (XtCallbackProc)closeListsDialogCB, This);
2403 XtSetArg(args[n], XmNsashWidth, 1); n++;
2404 XtSetArg(args[n], XmNsashHeight, 1); n++;
2405 XtSetArg(args[n], XmNseparatorOn, False); n++;
2406 This->listsDialog = XmCreatePanedWindow(This->myShellDialog, (
char *)
"MainPane",
2412 Widget formTop = XmCreateForm(This->listsDialog, (
char *)
"FormTop", args, n);
2415 XtSetArg(args[n], XmNmarginWidth, 8); n++;
2416 XtSetArg(args[n], XmNmarginHeight, 8); n++;
2417 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2418 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2419 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2420 Widget formTopRight = XmCreateForm(formTop, (
char *)
"FormTopRight", args,
2424 XtSetArg(args[n], XmNmarginWidth, 8); n++;
2425 XtSetArg(args[n], XmNmarginHeight, 8); n++;
2426 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2427 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2428 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
2429 XtSetArg(args[n], XmNrightWidget, formTopRight); n++;
2430 XtSetArg(args[n], XmNrightOffset, 10); n++;
2431 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2432 Widget formTopLeft = XmCreateForm(formTop, (
char *)
"FormTopLeft", args, n);
2436 This->createElementsList(formTopRight);
2437 XtManageChild(formTopRight);
2443 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2444 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2445 Widget labelLeft = XmCreateLabelGadget(formTopLeft, (
char *)
"ViewPoints",
2447 XtManageChild(labelLeft);
2451 XtSetArg(args[n], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE); n++;
2452 XtSetArg(args[n], XmNvisibleItemCount, 7); n++;
2454 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2455 XtSetArg(args[n], XmNtopWidget, labelLeft); n++;
2456 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
2457 XtSetArg(args[n], XmNrightWidget, This->myElementList); n++;
2458 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2459 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2460 XtSetArg(args[n], XmNwidth, 200); n++;
2462 This->myViewPtList = XmCreateScrolledList(formTopLeft, (
char *)
"ListLeft",
2464 if (This->viewPtList.size())
2465 This->addViewPoints();
2466 XtAddCallback(This->myViewPtList, XmNbrowseSelectionCallback,
2467 (XtCallbackProc) loadBookmarkCB, This);
2470 XtManageChild(This->myViewPtList);
2472 XtManageChild(formTopLeft);
2474 XtManageChild(formTop);
2478 XtSetArg(args[n], XmNmarginWidth, 6); n++;
2479 Widget formMiddle = XmCreateForm(This->listsDialog, (
char *)
"MiddleForm", args,
2484 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2485 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2486 XtSetArg(args[n], XmNtopWidget, This->myViewPtList); n++;
2487 Widget label = XmCreateLabelGadget(formMiddle, (
char *)
"Selection", args,
2489 XtManageChild(label);
2493 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2494 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2495 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2496 XtSetArg(args[n], XmNtopWidget, label); n++;
2497 XtSetArg(args[n], XmNtopOffset, 3); n++;
2498 XtSetArg(args[n], XmNmaxLength, This->MAX_VP_NAME); n++;
2499 This->viewPtSelection = XmCreateText(formMiddle, (
char *)
"Txt", args, n);
2500 XtManageChild(This->viewPtSelection);
2502 Dimension
h1,
h2, h;
2503 XtVaGetValues(label, XmNheight, &h1, NULL);
2504 XtVaGetValues(This->viewPtSelection, XmNheight, &h2, NULL);
2506 h = (Dimension) (1.1 * (h1 + h2));
2508 XtVaSetValues(formMiddle, XmNpaneMaximum, h, XmNpaneMinimum, h, NULL);
2509 XtManageChild(formMiddle);
2514 XtSetArg(args[n], XmNfractionBase, 4); n++;
2515 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2516 XtSetArg(args[n], XmNtopWidget, This->viewPtSelection); n++;
2517 Widget formAction = XmCreateForm(This->listsDialog, (
char *)
"ActionForm", args,
2521 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2522 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2523 XtSetArg(args[n], XmNtopOffset, 3); n++;
2524 XtSetArg(args[n], XmNbottomOffset, 5); n++;
2525 Widget separator = XmCreateSeparatorGadget(formAction, (
char *)
"Sep", args, n);
2527 XtManageChild(separator);
2529 Widget button = XmCreatePushButton(formAction, (
char *)
"Delete", NULL, 0);
2530 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2531 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2532 XmATTACH_POSITION, XmNleftPosition, 0, XmNrightAttachment,
2533 XmATTACH_POSITION, XmNrightPosition, 1,
2534 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2537 XtAddCallback(button, XmNactivateCallback,
2538 (XtCallbackProc) deleteBookmarkCB, This);
2539 XtManageChild(button);
2541 button = XmCreatePushButton(formAction, (
char *)
"Rename", NULL, 0);
2542 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2543 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2544 XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment,
2545 XmATTACH_POSITION, XmNrightPosition, 2,
2546 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2549 XtAddCallback(button, XmNactivateCallback,
2550 (XtCallbackProc) renameBookmarkCB, This);
2551 XtManageChild(button);
2553 button = XmCreatePushButton(formAction, (
char *)
"Sort", NULL, 0);
2554 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2555 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2556 XmATTACH_POSITION, XmNleftPosition, 2, XmNrightAttachment,
2557 XmATTACH_POSITION, XmNrightPosition, 3,
2558 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2561 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc) sortBookmarksCB, This);
2562 XtManageChild(button);
2564 button = XmCreatePushButton(formAction, (
char *)
"Close", NULL, 0);
2565 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2566 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2567 XmATTACH_POSITION, XmNleftPosition, 3, XmNrightAttachment,
2568 XmATTACH_POSITION, XmNrightPosition, 4,
2569 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2572 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc) closeListsDialogCB, This);
2573 XtManageChild(button);
2575 XtManageChild(formAction);
2576 XtVaGetValues(button, XmNheight, &h1, NULL);
2577 XtVaSetValues(formAction, XmNpaneMaximum, h1, XmNpaneMinimum, h1, NULL);
2579 XtManageChild(This->listsDialog);
2587 void G4OpenInventorXtExaminerViewer::lookAtSceneElementCB(Widget,
2588 XtPointer client_data,
2589 XtPointer call_data)
2592 std::string elementField;
2594 SoCamera * cam = This->getCamera();
2596 if (This->SoXtExaminerViewer::isAnimating())
2597 This->stopAnimating();
2599 XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
2601 value = (
char *) XmStringUnparse(cbs->item, XmFONTLIST_DEFAULT_TAG,
2602 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
2603 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
2604 || This->currentState == PAUSED_ANIMATION ) {
2605 if (This->animateSensor->isScheduled())
2606 This->animateSensor->unschedule();
2607 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
2608 This->maxSpeed = 0.0f;
2609 This->scheduleRedraw();
2610 This->restoreCamera();
2611 This->currentState = This->prevState;
2612 }
else if (This->currentState == VIEWPOINT)
2613 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
2615 elementField =
value;
2617 int idx = elementField.find_last_of(
"[");
2619 idx = elementField.size();
2625 SoSearchAction search;
2626 SoNode *root = This->getSceneManager()->getSceneGraph();
2627 int counter, idxUnderscore = elementField.find_last_of(
"_");
2629 This->
parseString<
int>(counter, elementField.substr(idxUnderscore + 1, idx), error);
2631 SoBaseKit::setSearchingChildren(
TRUE);
2633 search.setSearchingAll(
TRUE);
2636 This->
curEltName = elementField.substr(0, idx);
2640 path = (SoFullPath *)search.getPath();
2643 This->
curEltName = elementField.substr(0, idxUnderscore);
2648 SoPathList &pl = search.getPaths();
2649 path = (SoFullPath *)pl[counter - 1];
2654 if ((idx > 0) && (path)) {
2656 if(!This->refParticleTrajectory.empty()){
2658 SoGetBoundingBoxAction bAction(This->getViewportRegion());
2659 bAction.apply(path);
2660 SbBox3f bBox = bAction.getBoundingBox();
2661 SbVec3f elementCoord = bBox.getCenter();
2663 This->refParticleIdx = 0;
2666 float absLengthNow, absLengthMin;
2667 int maxIdx = This->refParticleTrajectory.size() - 2;
2671 p = This->refParticleTrajectory[This->refParticleIdx];
2672 absLengthMin = (p - elementCoord).length();
2673 This->refParticleIdx++;
2676 while (This->refParticleIdx < maxIdx) {
2677 p = This->refParticleTrajectory[This->refParticleIdx];
2678 absLengthNow = (p - elementCoord).length();
2680 if (absLengthNow < absLengthMin) {
2681 absLengthMin = absLengthNow;
2682 targetIdx = This->refParticleIdx;
2684 This->refParticleIdx++;
2687 if (This->currentState != BEAMLINE) {
2689 This->currentState = BEAMLINE;
2690 This->prevParticleDir = SbVec3f(0,0,0);
2692 p1 = This->prevPt = This->refParticleTrajectory[0];
2693 pN = This->refParticleTrajectory[This->refParticleTrajectory.size() - 1];
2694 This->distance = (pN - p1).length() / 10;
2697 if (cam->isOfType(SoOrthographicCamera::getClassTypeId()))
2698 ((SoOrthographicCamera *) cam)->height.setValue(This->defaultHeight);
2700 else if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2701 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2702 This->defaultHeightAngle);
2704 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2705 This->distance = (This->prevPt - cam->position.getValue()).length();
2707 This->refParticleIdx = targetIdx;
2710 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
2711 This->axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2712 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2713 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2714 This->scheduleRedraw();
2722 This->offsetFromCenter.setValue(0, 0, 1);
2723 This->distance = 50;
2724 This->upVector.setValue(0, 1, 0);
2727 cam->viewAll(path, This->getViewportRegion());
2731 XmTextSetString(This->viewPtSelection, NULL);
2737 void G4OpenInventorXtExaminerViewer::closeListsDialogCB(Widget,
2738 XtPointer client_data,
2743 This->sceneElements.clear();
2744 This->refParticleTrajectory.clear();
2746 This->currentState = GENERAL;
2747 XtDestroyWidget(This->myShellDialog);
2748 This->listsDialog = NULL;
2752 void G4OpenInventorXtExaminerViewer::prevViewPtCB(Widget, XtPointer client_data,
2756 if (This->viewPtIdx == 0)
2757 This->viewPtIdx = This->viewPtList.size() - 1;
2761 This->writeViewPtIdx();
2766 void G4OpenInventorXtExaminerViewer::nextViewPtCB(Widget, XtPointer client_data,
2770 if (This->viewPtIdx >= (
int) This->viewPtList.size() - 1)
2771 This->viewPtIdx = 0;
2775 This->writeViewPtIdx();
2782 void G4OpenInventorXtExaminerViewer::writeViewPtIdx()
2785 std::stringstream out;
2788 fileOut.seekp(0, std::ios::beg);
2790 while ((
int) idxStr.length() < MAX_VP_IDX) {
2794 fileOut << idxStr <<
"\n";
2796 fileOut.seekp(0, std::ios::end);
2802 void G4OpenInventorXtExaminerViewer::setViewPt()
2804 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
2805 || currentState == ROTATING) {
2807 if (animateSensor->isScheduled())
2808 animateSensor->unschedule();
2809 setSuperimpositionEnabled(superimposition,
FALSE);
2814 SoCamera * camera = getCamera();
2815 if (camera == NULL) {
2816 String dialogName = (
char *)
"Missing Camera Node";
2817 std::string msg =
"Camera is null. Unable to set the viewpoint.";
2822 if (!viewPtList.size()) {
2823 String dialogName = (
char *)
"Missing Viewpoints";
2824 std::string msg =
"There are no viewpoints to load.";
2829 if (SoXtExaminerViewer::isAnimating())
2832 if (currentState != VIEWPOINT) {
2833 currentState = VIEWPOINT;
2835 setSuperimpositionEnabled(superimposition,
TRUE);
2836 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2837 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2838 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2844 curViewPtName = viewPtList[viewPtIdx].viewPtName;
2845 camera->viewportMapping = viewPtList[viewPtIdx].viewportMapping;
2846 camera->position = viewPtList[viewPtIdx].position;
2847 camera->orientation = viewPtList[viewPtIdx].orientation;
2848 camera->aspectRatio = viewPtList[viewPtIdx].aspectRatio;
2849 camera->nearDistance = viewPtList[viewPtIdx].nearDistance;
2850 camera->farDistance = viewPtList[viewPtIdx].farDistance;
2851 camera->focalDistance = viewPtList[viewPtIdx].focalDistance;
2854 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2855 if (viewPtList[viewPtIdx].camType == ORTHOGRAPHIC) {
2857 camera = getCamera();
2858 ((SoOrthographicCamera *) camera)->height.setValue(
2859 viewPtList[viewPtIdx].height);
2861 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
2862 viewPtList[viewPtIdx].height);
2863 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
2864 if (viewPtList[viewPtIdx].camType == PERSPECTIVE) {
2866 camera = getCamera();
2867 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
2868 viewPtList[viewPtIdx].height);
2870 ((SoOrthographicCamera *) camera)->height.setValue(
2871 viewPtList[viewPtIdx].height);
2873 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::setViewPt",
2874 "Only Perspective and Orthographic cameras are supported.");
2883 void G4OpenInventorXtExaminerViewer::saveViewPtCB(Widget w,
2884 XtPointer client_data,
2889 if (This->fileName.empty()) {
2890 newViewPtFileCB(w, This, NULL);
2891 This->returnToSaveVP =
true;
2897 Widget nameViewPtDialog;
2898 Widget parent = This->getParentWidget();
2899 XmString label = XmStringCreateLocalized((
char *)
"Name the viewpoint:");
2901 XtSetArg(args[n], XmNselectionLabelString, label); n++;
2902 XtSetArg(args[n], XmNautoUnmanage, False); n++;
2906 nameViewPtDialog = XmCreatePromptDialog(parent, (
char *)
"Save Viewpoint",
2909 XmStringFree(label);
2910 XtAddCallback(nameViewPtDialog, XmNokCallback, getViewPtNameCB, This);
2911 XtAddCallback(nameViewPtDialog, XmNcancelCallback,
2912 (XtCallbackProc) XtDestroyWidget, NULL);
2914 Widget text = XtNameToWidget(nameViewPtDialog,
"Text");
2915 XtVaSetValues(text, XmNmaxLength, This->MAX_VP_NAME, NULL);
2916 std::string autoName =
"";
2918 autoName = This->viewPtAutoName();
2921 XmTextSetString(text, (
char *) autoName.c_str());
2922 XmTextSetInsertionPosition(text, autoName.length());
2924 XtUnmanageChild(XtNameToWidget(nameViewPtDialog,
"Help"));
2925 XtManageChild(nameViewPtDialog);
2929 std::string G4OpenInventorXtExaminerViewer::viewPtAutoName()
2932 std::stringstream sstream;
2933 std::vector<int> existingViewPts;
2937 for (
unsigned int i = 0; i < this->viewPtList.size(); ++i) {
2938 viewPt = this->viewPtList[i].viewPtName;
2939 if (viewPt.find(
"viewpoint_") != std::string::npos) {
2940 tmp = atoi(viewPt.substr(10).c_str());
2943 if (!viewPt.compare(
"viewpoint_0"))
2944 existingViewPts.push_back(0);
2946 existingViewPts.push_back(tmp);
2954 if (existingViewPts.size() > 0) {
2957 if (std::find(existingViewPts.begin(), existingViewPts.end(), vpNum)
2958 == existingViewPts.end()) {
2959 sstream <<
"viewpoint_" << vpNum;
2960 return sstream.str();
2965 return "viewpoint_0";
2971 void G4OpenInventorXtExaminerViewer::abbrOutputCB(Widget,
2972 XtPointer client_data,
2981 void G4OpenInventorXtExaminerViewer::pickRefPathCB(Widget,
2982 XtPointer client_data,
2989 if(This->isViewing())
2990 This->setViewing(
false);
2991 This->setComponentCursor(SoXtCursor(SoXtCursor::CROSSHAIR));
2998 void G4OpenInventorXtExaminerViewer::getViewPtNameCB(Widget w,
2999 XtPointer client_data,
3000 XtPointer call_data)
3003 std::string strName;
3005 XmSelectionBoxCallbackStruct *cbs =
3006 (XmSelectionBoxCallbackStruct *) call_data;
3007 XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &name);
3020 int beg = strName.find_first_not_of(
' ');
3021 int end = strName.find_last_not_of(
' ');
3022 strName = strName.substr(beg, end - beg + 1);
3024 bool nameExists =
false;
3025 int size = This->viewPtList.size();
3026 for (
int i = 0; i < size; i++) {
3027 if (!strcmp(This->viewPtList[i].viewPtName, strName.c_str())) {
3034 const int nVPName = This->MAX_VP_NAME + 1;
3035 name =
new char[nVPName];
3036 strncpy(name, strName.c_str(), nVPName);
3037 if (This->viewPtIdx == -1)
3038 This->viewPtIdx = 0;
3039 This->saveViewPt(name);
3040 if (This->listsDialog) {
3041 XmListAddItemUnselected(This->myViewPtList, cbs->value, 0);
3046 String dialogName = (
char *)
"Existing Viewpoint";
3047 std::string msg =
"The viewpoint already exists.";
3056 void G4OpenInventorXtExaminerViewer::saveViewPt(
char *name)
3060 float x,
y,
z, angle;
3061 SoCamera * camera = getCamera();
3063 if (viewPtList.size() == 0) {
3065 XtSetSensitive(nextViewPtButton, True);
3066 XtSetSensitive(prevViewPtButton, True);
3069 tmp.viewPtName =
name;
3070 tmp.viewportMapping = camera->viewportMapping.getValue();
3071 tmp.position = camera->position.getValue();
3072 tmp.orientation = camera->orientation.getValue();
3073 tmp.aspectRatio = camera->aspectRatio.getValue();
3074 tmp.nearDistance = camera->nearDistance.getValue();
3075 tmp.farDistance = camera->farDistance.getValue();
3076 tmp.focalDistance = camera->focalDistance.getValue();
3079 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3080 tmp.height = ((SoPerspectiveCamera *) camera)->heightAngle.getValue();
3081 tmp.camType = PERSPECTIVE;
3082 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3083 tmp.height = ((SoOrthographicCamera *) camera)->height.getValue();
3084 tmp.camType = ORTHOGRAPHIC;
3086 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::saveViewPtCB",
3087 "Only Perspective and Orthographic cameras are supported.");
3091 viewPtList.push_back(tmp);
3094 std::string vpName =
name;
3096 while ((
int) vpName.size() <= MAX_VP_NAME)
3099 fileOut << vpName << std::endl;
3100 tmp.position.getValue(x, y, z);
3101 fileOut << x <<
" " << y <<
" " << z << std::endl;
3104 tmp.orientation.getValue(axis, angle);
3105 axis.getValue(x, y, z);
3106 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3108 fileOut << tmp.camType <<
" " << tmp.height << std::endl;
3109 fileOut << tmp.focalDistance <<
" ";
3110 fileOut << tmp.nearDistance <<
" ";
3111 fileOut << tmp.farDistance << std::endl;
3112 fileOut << tmp.viewportMapping <<
" ";
3113 fileOut << tmp.aspectRatio <<
"\n" << std::endl;
3119 void G4OpenInventorXtExaminerViewer::deleteViewPtCB(Widget,
3120 XtPointer client_data,
3125 This->deleteViewPt();
3132 void G4OpenInventorXtExaminerViewer::deleteViewPt(
char *vpName)
3136 fileIn.open(fileName.c_str());
3137 std::ofstream out(
"temporaryFile.txt");
3140 vpName = viewPtList[viewPtIdx].viewPtName;
3143 XmString vpNameStr = XmStringCreateLocalized(vpName);
3145 XmListDeleteItem(myViewPtList, vpNameStr);
3146 XmStringFree(vpNameStr);
3149 getline(fileIn, line);
3150 out << line <<
"\n";
3152 while (getline(fileIn, line)) {
3153 end = line.find_last_not_of(
' ');
3154 line = line.substr(0, end + 1);
3155 if (!strcmp(line.c_str(), vpName)) {
3156 while (line.size()) {
3157 getline(fileIn, line);
3160 while (getline(fileIn, line))
3161 out << line <<
"\n";
3163 while (line.size()) {
3164 out << line <<
"\n";
3165 getline(fileIn, line);
3172 int size = viewPtList.size();
3173 while (idx < size) {
3174 if (!strcmp(viewPtList[idx].viewPtName, vpName)) {
3175 viewPtList.erase(viewPtList.begin() + idx);
3186 remove(fileName.c_str());
3187 rename(
"temporaryFile.txt", fileName.c_str());
3190 fileOut.seekp(0, std::ios::end);
3192 if (!viewPtList.size()) {
3193 curViewPtName = (
char *)
"";
3195 XtSetSensitive(nextViewPtButton, False);
3196 XtSetSensitive(prevViewPtButton, False);
3198 if (viewPtIdx >= (
int) viewPtList.size())
3208 void G4OpenInventorXtExaminerViewer::renameViewPt(
char *vpName)
3210 int idx = 0, end,
pos;
3211 int size = viewPtList.size();
3212 std::string line, newName;
3213 fileIn.open(fileName.c_str());
3216 while ((
int) newName.size() < MAX_VP_NAME)
3219 getline(fileIn, line);
3220 pos = fileIn.tellg();
3221 while (getline(fileIn, line)) {
3222 end = line.find_last_not_of(
' ');
3223 line = line.substr(0, end + 1);
3224 if (!strcmp(line.c_str(), curViewPtName)) {
3227 fileOut.seekp(0, std::ios::end);
3231 getline(fileIn, line);
3232 pos = fileIn.tellg();
3238 while (idx < size) {
3239 if (!strcmp(viewPtList[idx].viewPtName, curViewPtName)) {
3240 strcpy(viewPtList[idx].viewPtName, vpName);
3250 void G4OpenInventorXtExaminerViewer::sortViewPts(std::vector<std::string> sortedViewPts)
3253 float x,
y,
z, angle;
3254 int sortIdx = 0, unsortIdx = 0;
3256 if (fileOut.is_open())
3259 fileOut.open(fileName.c_str());
3263 int size = sortedViewPts.size();
3264 while (sortIdx < size) {
3265 while (strcmp(sortedViewPts[sortIdx].c_str(),
3266 viewPtList[unsortIdx].viewPtName))
3269 std::string vpName = viewPtList[unsortIdx].viewPtName;
3271 while ((
int) vpName.size() < MAX_VP_NAME)
3273 fileOut << vpName << std::endl;
3274 viewPtList[unsortIdx].position.getValue(x, y, z);
3275 fileOut << x <<
" " << y <<
" " << z << std::endl;
3278 viewPtList[unsortIdx].orientation.getValue(axis, angle);
3279 axis.getValue(x, y, z);
3280 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3282 fileOut << viewPtList[unsortIdx].camType <<
" "
3283 << viewPtList[unsortIdx].height << std::endl;
3284 fileOut << viewPtList[unsortIdx].focalDistance <<
" ";
3286 fileOut << viewPtList[unsortIdx].nearDistance <<
" ";
3288 fileOut << viewPtList[unsortIdx].farDistance << std::endl;
3290 fileOut << viewPtList[unsortIdx].viewportMapping <<
" ";
3291 fileOut << viewPtList[unsortIdx].aspectRatio <<
"\n" << std::endl;
3309 float x,
y,
z, angle;
3313 parseString<int>(viewPtIdx, token, error);
3314 getline(fileIn, token);
3316 while (getline(fileIn, token)) {
3318 int end = token.find_last_not_of(
' ');
3319 token = token.substr(0, end + 1);
3321 char *vpName =
new char[token.size() + 1];
3322 strcpy(vpName, token.c_str());
3323 tmp.viewPtName = vpName;
3326 parseString<float>(
x, token, error);
3328 parseString<float>(
y, token, error);
3330 parseString<float>(
z, token, error);
3332 tmp.position = axis.setValue(x, y, z);
3334 parseString<float>(
x, token, error);
3336 parseString<float>(
y, token, error);
3338 parseString<float>(
z, token, error);
3340 parseString<float>(angle, token, error);
3342 orient.setValue(axis.setValue(x, y, z), angle);
3343 tmp.orientation = orient.getValue();
3346 parseString<int>(camType, token, error);
3348 tmp.camType = (CameraType) camType;
3350 parseString<float>(tmp.height, token, error);
3352 parseString<float>(tmp.focalDistance, token, error);
3354 parseString<float>(tmp.nearDistance, token, error);
3356 parseString<float>(tmp.farDistance, token, error);
3358 parseString<int>(tmp.viewportMapping, token, error);
3360 parseString<float>(tmp.aspectRatio, token, error);
3362 getline(fileIn, token);
3363 getline(fileIn, token);
3370 viewPtList.push_back(tmp);
3383 std::istringstream str(s);
3384 if ((str >> t).fail())
3391 void G4OpenInventorXtExaminerViewer::popUpFileSelDialog(Widget &dialog,
3392 std::string dialogName,
3393 std::string buttonLabel,
3394 XtCallbackProc cbOK)
3398 Widget parent, scrollWidget;
3399 parent = SoXt::getShellWidget(getParentWidget());
3401 if (dialog == NULL) {
3404 XmString str = XmStringCreateLocalized((
char *) buttonLabel.c_str());
3407 XtSetArg(args[n], XmNokLabelString, str); n++;
3408 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
3410 dialog = XmCreateFileSelectionDialog(parent,
3411 (
char *) dialogName.c_str(), args,
n);
3413 XtAddCallback(dialog, XmNokCallback, cbOK,
this);
3414 XtAddCallback(dialog, XmNcancelCallback, cancelFileSelDialogCB,
this);
3417 scrollWidget = XmFileSelectionBoxGetChild(dialog, XmDIALOG_DIR_LIST);
3420 scrollWidget = XmFileSelectionBoxGetChild(dialog, XmDIALOG_LIST);
3424 XtUnmanageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
3427 XtManageChild(dialog);
3433 void G4OpenInventorXtExaminerViewer::cancelFileSelDialogCB(Widget w,
3443 void G4OpenInventorXtExaminerViewer::openViewPtFileCB(Widget,
3444 XtPointer client_data,
3449 This->popUpFileSelDialog(This->openFileDialog,
"Open File",
"Load",
3450 viewPtFileSelectedCB);
3454 void G4OpenInventorXtExaminerViewer::viewPtFileSelectedCB(Widget w,
3455 XtPointer client_data,
3456 XtPointer call_data)
3460 XmFileSelectionBoxCallbackStruct *cbs =
3461 (XmFileSelectionBoxCallbackStruct *) call_data;
3465 if (!(file = (
char *) XmStringUnparse(cbs->value,
3466 XmFONTLIST_DEFAULT_TAG, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0,
3468 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::fileSelectedCB",
3469 "Internal error during file opening");
3473 This->fileIn.open(file);
3474 if (!This->fileIn.fail()) {
3476 This->cleanUpAfterPrevFile();
3478 String dialogName = (
char *)
"Error Loading File";
3479 std::string msg =
"Wrong or corrupted input file.";
3482 This->fileName =
file;
3483 This->fileOut.open(This->fileName.c_str(),
std::ios::in);
3484 This->fileOut.seekp(0, std::ios::end);
3486 if (!This->listsDialog)
3487 constructListsDialog(w, This, NULL);
3489 This->addViewPoints();
3491 std::string newDialogName = This->fileName.substr(
3492 This->fileName.rfind(
'/') + 1);
3493 XtVaSetValues(This->myShellDialog, XmNtitle,
3494 (
char *) newDialogName.c_str(), NULL);
3496 if (This->viewPtList.size()) {
3498 XmTextSetString(This->viewPtSelection, NULL);
3499 XtSetSensitive(This->nextViewPtButton, True);
3500 XtSetSensitive(This->prevViewPtButton, True);
3502 XtSetSensitive(This->nextViewPtButton, False);
3503 XtSetSensitive(This->prevViewPtButton, False);
3509 This->fileIn.close();
3511 String dialogName = (
char *)
"Nonexistent File";
3512 std::string msg =
"Unable to open file.";
3517 This->fileIn.clear();
3524 void G4OpenInventorXtExaminerViewer::addViewPoints()
3526 int size = viewPtList.size();
3532 viewPts = (XmString *) XtMalloc(size *
sizeof(XmString));
3533 for (
int i = 0; i < size; i++)
3534 viewPts[i] = XmStringCreateLocalized(viewPtList[i].viewPtName);
3536 XmListAddItemsUnselected(myViewPtList, viewPts, size, 1);
3538 if (viewPts != NULL) {
3539 for (
int i = 0; i < size; i++)
3540 XmStringFree(viewPts[i]);
3541 XtFree((
char *) viewPts);
3549 void G4OpenInventorXtExaminerViewer::cleanUpAfterPrevFile()
3553 setSuperimpositionEnabled(superimposition,
FALSE);
3555 currentState = GENERAL;
3556 if (fileOut.is_open())
3559 XmListDeleteAllItems(myViewPtList);
3571 XmString warningMsg;
3573 warningMsg = XmStringCreateLocalized((
char *)msg.c_str());
3576 XtSetArg(args[n], XmNmessageString, warningMsg); n++;
3577 Widget warningDialog = XmCreateWarningDialog(getParentWidget(), dialogName, args, n);
3579 XtAddCallback(warningDialog, XmNokCallback, cb,
this);
3581 XmStringFree(warningMsg);
3583 XtVaSetValues (warningDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
3584 XtUnmanageChild(XtNameToWidget(warningDialog,
"Help"));
3585 XtUnmanageChild(XtNameToWidget(warningDialog,
"Cancel"));
3587 XtManageChild(warningDialog);
3591 void G4OpenInventorXtExaminerViewer::newViewPtFileCB(Widget,
3592 XtPointer client_data,
3597 This->popUpFileSelDialog(This->newFileDialog,
"New File",
"Save",
3602 void G4OpenInventorXtExaminerViewer::createNewVPFileCB(Widget w,
3603 XtPointer client_data,
3604 XtPointer call_data)
3609 XmFileSelectionBoxCallbackStruct *cbs =
3610 (XmFileSelectionBoxCallbackStruct *) call_data;
3614 if (!(file = (
char *) XmStringUnparse(cbs->value,
3615 XmFONTLIST_DEFAULT_TAG, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0,
3617 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::createNewVPFileCB",
3618 "Internal error during file opening");
3622 This->fileName =
file;
3623 fName = This->fileName.substr(This->fileName.rfind(
'/') + 1);
3624 This->fileIn.open(file);
3625 if (This->fileIn.fail()) {
3626 This->cleanUpAfterPrevFile();
3627 This->fileOut.open(file);
3628 XtSetSensitive(This->nextViewPtButton, False);
3629 XtSetSensitive(This->prevViewPtButton, False);
3630 if (This->listsDialog)
3631 closeListsDialogCB(w, This, NULL);
3632 constructListsDialog(w, This, NULL);
3634 if (This->returnToSaveVP) {
3635 This->returnToSaveVP =
false;
3636 saveViewPtCB(NULL, This, NULL);
3639 String dialogName = (
char *)
"Existing File";
3640 std::string msg =
"'" + fName +
"' already exists. Do you want to overwrite it?";
3642 This->fileIn.close();
3644 This->fileIn.clear();
3650 void G4OpenInventorXtExaminerViewer::overwriteFileCB(Widget,
3651 XtPointer client_data,
3655 This->cleanUpAfterPrevFile();
3656 XtSetSensitive(This->nextViewPtButton, False);
3657 XtSetSensitive(This->prevViewPtButton, False);
3659 XtUnmanageChild(This->newFileDialog);
3661 This->fileOut.open(This->fileName.c_str());
3663 if (This->returnToSaveVP) {
3664 This->returnToSaveVP =
false;
3665 saveViewPtCB(NULL, This, NULL);
3670 void G4OpenInventorXtExaminerViewer::loadRefCoordsDialogCB(Widget,
3671 XtPointer client_data,
3676 This->popUpFileSelDialog(This->loadRefCoordsDialog,
"Load Ref Coords",
3677 "Load", loadRefCoordsCB);
3681 void G4OpenInventorXtExaminerViewer::loadRefCoordsCB(Widget w,
3682 XtPointer client_data,
3683 XtPointer call_data)
3687 XmFileSelectionBoxCallbackStruct *cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
3692 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3693 XmCHARSET_TEXT, XmCHARSET_TEXT,
3694 NULL, 0, XmOUTPUT_ALL);
3696 std::ifstream ifs(file);
3698 This->refParticleTrajectory.clear();
3700 while(ifs >> x >> y >> z){
3701 This->refParticleTrajectory.push_back(SbVec3f(x,y,z));
3707 String dialogName = (
char *)
"Problem reading file";
3708 std::string msg =
"Problem reading file";
3719 void G4OpenInventorXtExaminerViewer::saveRefCoordsDialogCB(Widget,
3720 XtPointer client_data,
3725 if (!This->refParticleTrajectory.size()) {
3726 String dialogName = (
char *)
"No Reference Trajectory";
3727 std::string msg =
"You need to start a run or load a reference trajectory from a file";
3734 Widget parent, scrollWidget;
3735 parent = SoXt::getShellWidget(This->getParentWidget());
3737 if (This->saveRefCoordsDialog == NULL) {
3740 XmString str = XmStringCreateLocalized((
char *)
"Save");
3743 XtSetArg(args[n], XmNokLabelString, str); n++;
3744 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
3746 This->saveRefCoordsDialog = XmCreateFileSelectionDialog(parent,(
char *)
"Save Ref Coords", args, n);
3748 XtAddCallback(This->saveRefCoordsDialog, XmNokCallback, saveRefCoordsCB, This);
3749 XtAddCallback(This->saveRefCoordsDialog, XmNcancelCallback, cancelFileSelDialogCB, This);
3752 scrollWidget = XmFileSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_DIR_LIST);
3755 scrollWidget = XmFileSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_LIST);
3759 XtUnmanageChild(XmSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_HELP_BUTTON));
3765 XtManageChild(This->saveRefCoordsDialog);
3770 void G4OpenInventorXtExaminerViewer::saveRefCoordsCB(Widget w,
3771 XtPointer client_data,
3772 XtPointer call_data)
3776 XmFileSelectionBoxCallbackStruct *cbs =
3777 (XmFileSelectionBoxCallbackStruct *) call_data;
3782 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3783 XmCHARSET_TEXT, XmCHARSET_TEXT,
3784 NULL, 0, XmOUTPUT_ALL);
3786 std::ifstream ifile(file);
3791 Widget parent = This->getParentWidget();
3792 Widget confirmOverwriteDialog;
3795 confirmOverwriteDialog = XmCreateQuestionDialog (parent, (
char *)
"Confirm overwrite", args, 0);
3796 msg = XmStringCreateLocalized ((
char *)
"File exists. Overwrite?");
3797 XtVaSetValues (confirmOverwriteDialog, XmNmessageString, msg, NULL);
3802 XtVaSetValues (confirmOverwriteDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
3803 XtAddCallback (confirmOverwriteDialog, XmNokCallback, saveRefCoordsOverWriteCB, client_data);
3804 XtAddCallback (confirmOverwriteDialog, XmNcancelCallback, saveRefCoordsOverWriteCB, client_data);
3812 XtUnmanageChild(XtNameToWidget(confirmOverwriteDialog,
"Help"));
3813 XtManageChild(confirmOverwriteDialog);
3819 std::ofstream ofs(file);
3822 for(
unsigned int i=0; i < This->refParticleTrajectory.size(); ++i){
3823 This->refParticleTrajectory[i].getValue(x,y,z);
3824 ofs << x <<
" " << y <<
" " << z <<
"\n";
3830 String dialogName = (
char *)
"Error opening file";
3831 std::string msg =
"There was a problem trying to open the file '";
3844 void G4OpenInventorXtExaminerViewer::saveRefCoordsOverWriteCB(Widget w,
3845 XtPointer client_data,
3846 XtPointer call_data)
3848 XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
3851 switch (cbs->reason) {
3859 for(
unsigned int i=0; i < This->refParticleTrajectory.size(); ++i){
3860 This->refParticleTrajectory[i].getValue(x,y,z);
3861 ofs << x <<
" " << y <<
" " << z <<
"\n";
3868 String dialogName = (
char *)
"Error opening file";
3869 std::string msg =
"There was a problem trying to open the file '";
3883 XmProcessTraversal(XtNameToWidget(This->
saveRefCoordsWidget,
"Text"), XmTRAVERSE_CURRENT);
3896 void G4OpenInventorXtExaminerViewer::loadSceneGraphDialogCB(Widget,
3897 XtPointer client_data,
3902 This->popUpFileSelDialog(This->loadSceneGraphDialog,
"Load Scene Graph",
3903 "Load", loadSceneGraphCB);
3908 void G4OpenInventorXtExaminerViewer::loadSceneGraphCB(Widget w,
3909 XtPointer client_data,
3910 XtPointer call_data)
3914 XmFileSelectionBoxCallbackStruct *cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
3918 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3919 XmCHARSET_TEXT, XmCHARSET_TEXT,
3920 NULL, 0, XmOUTPUT_ALL);
3923 if (!sceneInput.openFile(file)) {
3924 String dialogName = (
char *)
"Problem opening file";
3925 std::string msg =
"Cannot open file ";
3929 sceneInput.closeFile();
3933 This->newSceneGraph = SoDB::readAll(&sceneInput);
3934 if (This->newSceneGraph == NULL) {
3935 String dialogName = (
char *)
"Problem reading file";
3936 std::string msg =
"Problem reading file";
3942 This->setSceneGraph(This->newSceneGraph);
3949 void G4OpenInventorXtExaminerViewer::saveSceneGraphDialogCB(Widget,
3950 XtPointer client_data,
3957 Widget parent, scrollWidget;
3958 parent = SoXt::getShellWidget(This->getParentWidget());
3960 if (This->saveSceneGraphDialog == NULL) {
3963 XmString str = XmStringCreateLocalized((
char *)
"Save");
3966 XtSetArg(args[n], XmNokLabelString, str); n++;
3967 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
3969 This->saveSceneGraphDialog = XmCreateFileSelectionDialog(parent,(
char *)
"Save Scene Graph", args, n);
3971 XtAddCallback(This->saveSceneGraphDialog, XmNokCallback, saveSceneGraphCB, This);
3972 XtAddCallback(This->saveSceneGraphDialog, XmNcancelCallback, cancelFileSelDialogCB, This);
3975 scrollWidget = XmFileSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_DIR_LIST);
3978 scrollWidget = XmFileSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_LIST);
3982 XtUnmanageChild(XmSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_HELP_BUTTON));
3988 XtManageChild(This->saveSceneGraphDialog);
3994 void G4OpenInventorXtExaminerViewer::saveSceneGraphCB(Widget w,
3995 XtPointer client_data,
3996 XtPointer call_data)
4000 XmFileSelectionBoxCallbackStruct *cbs =
4001 (XmFileSelectionBoxCallbackStruct *) call_data;
4005 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
4006 XmCHARSET_TEXT, XmCHARSET_TEXT,
4007 NULL, 0, XmOUTPUT_ALL);
4009 std::ifstream ifile(file);
4014 Widget parent = This->getParentWidget();
4015 Widget confirmOverwriteDialog;
4018 confirmOverwriteDialog = XmCreateQuestionDialog (parent, (
char *)
"Confirm overwrite", args, 0);
4019 msg = XmStringCreateLocalized ((
char *)
"File exists. Overwrite?");
4020 XtVaSetValues (confirmOverwriteDialog, XmNmessageString, msg, NULL);
4025 XtVaSetValues (confirmOverwriteDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
4026 XtAddCallback (confirmOverwriteDialog, XmNokCallback, saveSceneGraphOverWriteCB, client_data);
4027 XtAddCallback (confirmOverwriteDialog, XmNcancelCallback, saveSceneGraphOverWriteCB, client_data);
4035 XtUnmanageChild(XtNameToWidget(confirmOverwriteDialog,
"Help"));
4036 XtManageChild(confirmOverwriteDialog);
4042 SoWriteAction writeAction;
4043 SoSeparator *root = (SoSeparator *) (This->getSceneGraph());
4045 SoOutput * out = writeAction.getOutput();
4047 if(out->openFile(file)){
4048 out->setBinary(
FALSE);
4049 writeAction.apply(root);
4055 String dialogName = (
char *)
"Error opening file";
4056 std::string msg =
"There was a problem trying to open the file '";
4071 void G4OpenInventorXtExaminerViewer::saveSceneGraphOverWriteCB(Widget w,
4072 XtPointer client_data,
4073 XtPointer call_data)
4075 XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
4078 switch (cbs->reason) {
4083 SoWriteAction writeAction;
4084 SoSeparator *root = (SoSeparator *) (This->getSceneGraph());
4086 SoOutput * out = writeAction.getOutput();
4088 out->setBinary(
FALSE);
4089 writeAction.apply(root);
4098 String dialogName = (
char *)
"Error opening file";
4099 std::string msg =
"There was a problem trying to open the file '";
4130 void G4OpenInventorXtExaminerViewer::loadBookmarkCB(Widget,
4131 XtPointer client_data,
4132 XtPointer call_data)
4136 XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
4138 vpName = (
char *) XmStringUnparse(cbs->item, XmFONTLIST_DEFAULT_TAG,
4139 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
4141 for (
int i = 0; i < (
int) This->viewPtList.size(); i++) {
4142 if (!strcmp(This->viewPtList[i].viewPtName, vpName)) {
4143 This->viewPtIdx = i;
4147 XmTextSetString(This->viewPtSelection, vpName);
4149 This->writeViewPtIdx();
4156 void G4OpenInventorXtExaminerViewer::deleteBookmarkCB(Widget,
4157 XtPointer client_data,
4163 vpName = XmTextGetString(This->viewPtSelection);
4165 XmString vpNameStr = XmStringCreateLocalized(vpName);
4167 if (XmListItemExists(This->myViewPtList, vpNameStr)) {
4168 XmListDeleteItem(This->myViewPtList, vpNameStr);
4169 This->deleteViewPt(vpName);
4172 XmStringFree(vpNameStr);
4173 XmTextSetString(This->viewPtSelection, NULL);
4178 void G4OpenInventorXtExaminerViewer::renameBookmarkCB(Widget,
4179 XtPointer client_data,
4182 std::string vpNameStr;
4184 int *pos_list, pos_cnt;
4187 vpName = XmTextGetString(This->viewPtSelection);
4189 if (!strlen(vpName) || !strcmp(This->curViewPtName, vpName)) {
4196 int beg = vpNameStr.find_first_not_of(
' ');
4197 int end = vpNameStr.find_last_not_of(
' ');
4198 vpNameStr = vpNameStr.substr(beg, end - beg + 1);
4199 const int nVPName = vpNameStr.size() + 1;
4200 vpName =
new char[nVPName];
4201 strncpy(vpName, vpNameStr.c_str(), nVPName);
4203 int size = This->viewPtList.size();
4204 for (
int i = 0; i < size; i++) {
4205 if (!strcmp(vpName, This->viewPtList[i].viewPtName)) {
4207 String dialogName = (
char *)
"Existing Viewpoint";
4208 std::string msg =
"'";
4210 msg +=
"' already exists. Choose a different name";
4217 XmString vpNameXmStr = XmStringCreateLocalized(vpName);
4219 if (XmListGetSelectedPos(This->myViewPtList, &pos_list, &pos_cnt)) {
4220 XmListReplaceItemsPos(This->myViewPtList, &vpNameXmStr, 1, pos_list[0]);
4221 This->renameViewPt(vpName);
4222 XtFree((
char *) pos_list);
4225 if (This->currentState == VIEWPOINT)
4226 This->scheduleRedraw();
4228 XmStringFree(vpNameXmStr);
4232 void G4OpenInventorXtExaminerViewer::sortBookmarksCB(Widget,
4233 XtPointer client_data,
4238 XmString *strList, *newStrList;
4239 std::vector<std::string> charList;
4242 if (This->viewPtList.size() < 2)
4246 XtVaGetValues(This->myViewPtList, XmNitemCount, &size, XmNitems, &strList,
4249 for (
int i = 0; i < size; i++) {
4250 vpName = (
char *) XmStringUnparse(strList[i], XmFONTLIST_DEFAULT_TAG,
4251 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
4252 charList.push_back(vpName);
4256 std::sort(charList.begin(), charList.end());
4258 newStrList = (XmString *) XtMalloc(size *
sizeof(XmString));
4259 for (
int i = 0; i < size; i++) {
4261 if (!strcmp(charList[i].c_str(), This->curViewPtName))
4262 This->viewPtIdx = i;
4263 const int nVPName = charList[i].size() + 1;
4264 char *vpName2 =
new char[nVPName];
4265 strncpy(vpName2, charList[i].c_str(), nVPName);
4266 newStrList[i] = XmStringCreateLocalized(vpName2);
4270 XmListDeleteAllItems(This->myViewPtList);
4271 XmListAddItemsUnselected(This->myViewPtList, newStrList, size, 1);
4273 This->sortViewPts(charList);
4275 if (newStrList != NULL) {
4276 for (
int i = 0; i < size; i++)
4277 XmStringFree(newStrList[i]);
4278 XtFree((
char *) newStrList);
4283 void G4OpenInventorXtExaminerViewer::evenOutRefParticlePts()
4285 if(this->refParticleTrajectory.empty())
4288 SbVec3f p1, p2, p3, dirNow, dirNxt,
dir, p2_tmp, p_start, p_corner, p_nxt;
4289 float avgDistBtwPts = 0;
4290 float totalDistBtwPts = 0;
4291 std::vector<SbVec3f> newRefParticleTrajectory;
4293 int size = refParticleTrajectory.size() - 1;
4295 for (
int i = 0; i < size; i++) {
4296 p1 = refParticleTrajectory[i];
4297 p2 = refParticleTrajectory[i + 1];
4301 totalDistBtwPts += (p2 - p1).length();
4304 avgDistBtwPts = totalDistBtwPts / numOfPts;
4305 float minDistAllowed = 0.75 * avgDistBtwPts;
4311 p1 = refParticleTrajectory[i];
4312 p2 = refParticleTrajectory[i + 1];
4315 p1.getValue(x, y, z);
4317 newRefParticleTrajectory.push_back(refPoint);
4320 while ((p2 - p1).length() < minDistAllowed && j < (size - 1)) {
4323 p1 = refParticleTrajectory[j];
4324 p2 = refParticleTrajectory[j + 1];
4332 refParticleTrajectory.clear();
4333 refParticleTrajectory = newRefParticleTrajectory;
4339 void G4OpenInventorXtExaminerViewer::closeMainWindowCB(Widget,
4340 XtPointer client_data,
4346 if (This->openFileDialog)
4347 XtUnmanageChild(This->openFileDialog);
4349 if (This->newFileDialog)
4350 XtUnmanageChild(This->newFileDialog);
4352 if (This->listsDialog)
4353 closeListsDialogCB(NULL, This, NULL);
4357 void G4OpenInventorXtExaminerViewer::saveCurCamera()
4359 SoCamera *cam = getCamera();
4360 camB4Animation.viewportMapping = cam->viewportMapping.getValue();
4361 camB4Animation.position = cam->position.getValue();
4362 camB4Animation.orientation = cam->orientation.getValue();
4363 camB4Animation.aspectRatio = cam->aspectRatio.getValue();
4364 camB4Animation.nearDistance = cam->nearDistance.getValue();
4365 camB4Animation.farDistance = cam->farDistance.getValue();
4366 camB4Animation.focalDistance = cam->focalDistance.getValue();
4368 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
4369 camB4Animation.height =
4370 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
4371 camB4Animation.camType = PERSPECTIVE;
4372 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4373 camB4Animation.height =
4374 ((SoOrthographicCamera *) cam)->height.getValue();
4375 camB4Animation.camType = ORTHOGRAPHIC;
4380 void G4OpenInventorXtExaminerViewer::restoreCamera()
4382 SoCamera *cam = getCamera();
4384 cam->viewportMapping = camB4Animation.viewportMapping;
4385 cam->position = camB4Animation.position;
4386 cam->orientation = camB4Animation.orientation;
4387 cam->aspectRatio = camB4Animation.aspectRatio;
4388 cam->nearDistance = camB4Animation.nearDistance;
4389 cam->farDistance = camB4Animation.farDistance;
4390 cam->focalDistance = camB4Animation.focalDistance;
4392 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
4393 if (camB4Animation.camType == ORTHOGRAPHIC) {
4396 ((SoOrthographicCamera *) cam)->height.setValue(
4397 camB4Animation.height);
4399 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
4400 camB4Animation.height);
4401 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4402 if (camB4Animation.camType == PERSPECTIVE) {
4405 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
4406 camB4Animation.height);
4408 ((SoOrthographicCamera *) cam)->height.setValue(
4409 camB4Animation.height);
4414 void G4OpenInventorXtExaminerViewer::animateSensorRotationCB(
void *
data,
4417 SbTime curTime = SbTime::getTimeOfDay();
4419 SoTimerSensor *
s = (SoTimerSensor *) sensor;
4421 float t = float((curTime - s->getBaseTime()).getValue())
4422 / This->animateBtwPtsPeriod;
4424 if ((t > 1.0
f) || (t + s->getInterval().getValue() > 1.0f))
4426 SbBool end = (t == 1.0f);
4429 This->animateSensorRotation->unschedule();
4436 This->currentState = This->prevState;
4446 void G4OpenInventorXtExaminerViewer::animateSensorCB(
void *data,
4449 SbTime curTime = SbTime::getTimeOfDay();
4451 SoCamera *cam = This->getCamera();
4452 SoTimerSensor *s = (SoTimerSensor *) sensor;
4454 float t = float((curTime - s->getBaseTime()).getValue())
4455 / This->animateBtwPtsPeriod;
4457 if ((t > 1.0
f) || (t + s->getInterval().getValue() > 1.0f))
4459 SbBool end = (t == 1.0f);
4461 cam->orientation = SbRotation::slerp(This->camStartOrient, This->camEndOrient, t);
4462 cam->position = This->camStartPos + (This->camEndPos - This->camStartPos) * t;
4465 This->animateSensor->unschedule();
4467 if (This->currentState == ANIMATION) {
4468 if (This->refParticleIdx < (
int) (This->refParticleTrajectory.size() - 1))
4469 This->animateRefParticle();
4475 if (This->currentState == REVERSED_ANIMATION) {
4476 if (This->refParticleIdx >= 1)
4477 This->animateRefParticle();
4487 void G4OpenInventorXtExaminerViewer::setStartingPtForAnimation()
4489 if (SoXtExaminerViewer::isAnimating())
4493 SbVec3f p1, p2, p2_tmp, camUpV, camD, camD_tmp, leftRightAxis;
4496 if (currentState == ANIMATION) {
4497 p1 = refParticleTrajectory[refParticleIdx];
4498 p2 = refParticleTrajectory[++(refParticleIdx)];
4499 }
else if (currentState == REVERSED_ANIMATION) {
4500 p2 = refParticleTrajectory[refParticleIdx];
4501 p1 = refParticleTrajectory[--(refParticleIdx)];
4502 }
else if (currentState == PAUSED_ANIMATION) {
4503 if (refParticleIdx < (
int) refParticleTrajectory.size()) {
4504 p1 = refParticleTrajectory[refParticleIdx];
4505 p2 = refParticleTrajectory[refParticleIdx + 1];
4507 p1 = refParticleTrajectory[refParticleIdx - 1];
4508 p2 = refParticleTrajectory[refParticleIdx];
4511 p1.getValue(x1, y1, z1);
4512 p2.getValue(x2, y2, z2);
4517 p2_tmp.setValue(x2, y1, z2);
4518 camD_tmp = p2_tmp - p1;
4519 camD_tmp.normalize();
4521 camUpV.setValue(0, 1, 0);
4522 rot.setValue(camD_tmp, camD);
4523 rot.multVec(camUpV, camUpV);
4525 leftRightAxis = camD.cross(camUpV);
4527 myCam->position = p1;
4528 myCam->pointAt(p2, camUpV);
4531 p1 = p1 + (up_down * camUpV) + (left_right * leftRightAxis);
4532 myCam->position = p1;
4536 void G4OpenInventorXtExaminerViewer::gotoRefPathStart()
4538 G4OpenInventorXtExaminerViewer::gotoRefPathStartCB(NULL, (
void *)
this,
4543 void G4OpenInventorXtExaminerViewer::gotoRefPathStartCB(Widget,
4544 XtPointer client_data,
4549 if (!This->refParticleTrajectory.size()) {
4550 String dialogName = (
char *)
"No Reference Trajectory";
4551 std::string msg =
"You need to start a run or load a reference trajectory from a file";
4556 if (This->currentState == ROTATING)
4558 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
4559 || This->currentState == PAUSED_ANIMATION) {
4560 if (This->animateSensor->isScheduled())
4561 This->animateSensor->unschedule();
4562 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
4563 This->maxSpeed = 0.0f;
4564 This->scheduleRedraw();
4566 This->saveCurCamera();
4567 This->prevState = This->currentState;
4568 This->prevRefIdx = This->refParticleIdx;
4571 if (This->SoXtExaminerViewer::isAnimating())
4572 This->stopAnimating();
4575 This->left_right = 0;
4578 This->refParticleIdx = 0;
4579 This->currentState = BEAMLINE;
4580 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
4581 This->axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
4582 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
4583 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
4584 This->scheduleRedraw();
4591 This->prevParticleDir = SbVec3f(0,0,0);
4594 SbVec3f p1 = This->refParticleTrajectory[0];
4595 SbVec3f pN = This->refParticleTrajectory[This->refParticleTrajectory.size() - 1];
4596 This->distance = (pN - p1).length() / 10;
4602 void G4OpenInventorXtExaminerViewer::invertRefPathCB(Widget,
4603 XtPointer client_data,
4608 This->invertRefPath();
4612 void G4OpenInventorXtExaminerViewer::invertRefPath()
4615 this->refParticleTrajectory.end());
4616 this->setReferencePathZPos();
4617 this->sortElements();
4621 void G4OpenInventorXtExaminerViewer::animateRefParticleCB(Widget,
4622 XtPointer client_data,
4627 if (!This->refParticleTrajectory.size()) {
4628 This->returnToAnim =
true;
4629 String dialogName = (
char *)
"No Reference Trajectory";
4630 std::string msg =
"You need to start a run or load a reference trajectory from a file";
4635 if (!This->refParticleTrajectory.size())
4639 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
4641 This->axisSwitch->whichChild.setValue(SO_SWITCH_ALL);
4642 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
4643 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
4644 This->scheduleRedraw();
4647 SoCamera *cam = This->getCamera();
4650 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
4651 || This->currentState == ROTATING)
4654 if (This->currentState != PAUSED_ANIMATION) {
4656 This->saveCurCamera();
4657 This->prevState = This->currentState;
4658 This->prevRefIdx = This->refParticleIdx;
4660 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4661 This->toggleCameraType();
4662 cam = This->getCamera();
4665 This->refParticleIdx = 0;
4668 This->left_right = This->up_down = 0;
4670 cam->focalDistance = 0.1f;
4671 ((SoPerspectiveCamera *) cam)->heightAngle = 0.50f;
4674 This->currentState = ANIMATION;
4675 This->setStartingPtForAnimation();
4677 cam->position = (This->myCam)->
position.getValue();
4678 cam->orientation = (This->myCam)->orientation.getValue();
4679 This->animateRefParticle();
4683 void G4OpenInventorXtExaminerViewer::animateRefParticle()
4685 SoCamera *cam = getCamera();
4687 camStartPos = cam->position.getValue();
4688 camStartOrient = cam->orientation.getValue();
4690 if (currentState != BEAMLINE)
4691 setStartingPtForAnimation();
4693 camEndPos = myCam->position.getValue();
4694 camEndOrient = myCam->orientation.getValue();
4696 if (animateSensor->isScheduled())
4697 animateSensor->unschedule();
4699 animateSensor->setBaseTime(SbTime::getTimeOfDay());
4700 animateSensor->setInterval(SbTime(0.02));
4702 animateSensor->schedule();
4707 void (*callback)(
void *),
void *
object)
4709 this->escapeCallback = callback;
4710 this->examinerObject = object;
4714 void G4OpenInventorXtExaminerViewer::sceneChangeCB(
void *
userData, SoSensor *)
4718 if(This->newEvents){
4719 This->findAndSetRefPath();
4720 This->newEvents =
false;
4738 this->viewer->newEvents =
true;
#define SPEED_INDICATOR_STEP
void xmAddMouseEventHandler(Widget w)
~G4OpenInventorXtExaminerViewer()
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
friend class HookEventProcState
const std::vector< const std::vector< G4AttValue > * > & GetAttValues() const
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
bool viewingBeforePickRef
std::string saveScenegraphFileName
Widget addMenu(std::string name)
void parseString(T &t, const std::string &s, bool &error)
void moveCamera(float dist=0, bool lookdown=false)
virtual G4bool Notify(G4ApplicationState requiredState)
G4OpenInventorXtExaminerViewer(Widget parent=NULL, const char *name=NULL, SbBool embed=TRUE, SoXtFullViewer::BuildFlag flag=BUILD_ALL, SoXtViewer::Type type=BROWSER)
G4GLOB_DLL std::ostream G4cout
void warningMsgDialog(std::string, String, XtCallbackProc)
HookEventProcState(G4OpenInventorXtExaminerViewer *)
void addButton(Widget menu, std::string name, XtCallbackProc)
static Pixmap createPixmapFromXpm(Widget button, const char **xpm, SbBool ghost=FALSE)
const XML_Char int const XML_Char * value
Widget buildWidget(Widget parent)
virtual SbBool processSoEvent(const SoEvent *const event)
virtual void afterRealizeHook()
#define MAX_SPEED_INDICATOR
void addEscapeCallback(void(*cb)(void *), void *)
Widget saveRefCoordsWidget
const XML_Char const XML_Char * data
const std::vector< const std::map< G4String, G4AttDef > * > & GetAttDefs() const
std::string saveRefCoordsFileName
Widget saveScenegraphWidget
virtual void createViewerButtons(Widget parent, SbPList *buttonlist)