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>
72 #include <Inventor/nodes/SoLineSet.h>
73 #include <Inventor/nodes/SoMaterial.h>
74 #include <Inventor/errors/SoDebugError.h>
75 #include <Inventor/SoPickedPoint.h>
76 #include <Inventor/actions/SoWriteAction.h>
81 #include <Inventor/sensors/SoTimerSensor.h>
82 #include <Inventor/sensors/SoNodeSensor.h>
97 #include <Inventor/nodes/SoCallback.h>
98 #include <Inventor/nodes/SoSwitch.h>
99 #include <Inventor/nodes/SoScale.h>
100 #include <Inventor/nodes/SoTranslation.h>
101 #include <Inventor/actions/SoSearchAction.h>
102 #include <Inventor/actions/SoGetBoundingBoxAction.h>
104 #include <Inventor/nodes/SoCoordinate3.h>
106 #include <Inventor/nodes/SoText2.h>
107 #include <Inventor/nodes/SoFont.h>
108 #include <Inventor/nodes/SoPointSet.h>
109 #include <Inventor/nodes/SoDrawStyle.h>
110 #include <Inventor/nodes/SoBaseColor.h>
113 #include <Inventor/nodekits/SoBaseKit.h>
116 #include <Inventor/SbVec3f.h>
122 #define MIN_SPEED 2.1 // Lower number means faster
123 #define START_STEP 0.3
124 #define SPEED_INDICATOR_STEP 0.045
125 #define MAX_SPEED_INDICATOR 0.81
131 const char *
name, SbBool embed,
132 SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type) :
133 SoXtExaminerViewer(parent, name, embed, flag, type,
FALSE)
136 this->constructor(
TRUE);
141 const char *
name, SbBool embed,
142 SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type,
144 SoXtExaminerViewer(parent, name, embed, flag, type,
FALSE)
146 this->constructor(build);
150 void G4OpenInventorXtExaminerViewer::constructor(
const SbBool build)
155 this->newEvents =
false;
157 fileName =
".bookmarkFile";
159 animateSensor =
new SoTimerSensor(
160 G4OpenInventorXtExaminerViewer::animateSensorCB,
this);
161 animateSensorRotation =
new SoTimerSensor(
162 G4OpenInventorXtExaminerViewer::animateSensorRotationCB,
this);
164 currentState = GENERAL;
165 myCam =
new SoPerspectiveCamera;
169 curViewPtName =
new char[MAX_VP_NAME + 1];
170 left_right = up_down = 0;
176 lshiftdown = rshiftdown =
false;
179 lctrldown = rctrldown =
false;
183 prevColorField = NULL;
186 openFileDialog = newFileDialog = listsDialog = (Widget) NULL;
187 loadRefCoordsDialog = saveRefCoordsDialog = NULL;
188 loadSceneGraphDialog = saveSceneGraphDialog = NULL;
189 myElementList = NULL;
193 newSceneGraph = NULL;
194 zcoordSetFlag =
false;
201 static const char * superimposed[] = {
202 "#Inventor V2.1 ascii",
"",
209 " OrthographicCamera ",
215 " DEF soxt->callback Callback { }",
218 " DEF soxt->translation Translation ",
220 " translation 0 0 0",
222 " DEF soxt->scale Scale ",
224 " scaleFactor 1 1 1",
226 " DEF soxt->geometry Coordinate3 ",
230 " -0.81 -0.04 0, -0.81 0 0,",
231 " -0.81 0.04 0, 0 -0.04 0,",
233 " 0.81 -0.04 0, 0.81 0 0,",
236 " 0.81 0.02 0, 0.81 -0.02 0,",
239 " 0.4 0.01 0, 0.4 -0.01 0,",
244 " DEF soxt->animSpeedOutlineSwitch Switch ",
249 " emissiveColor 0 0 0",
255 " 12, 11, 10, 9, -1",
260 " DEF soxt->axisSwitch Switch ",
279 " DEF soxt->animSpeedSwitch Switch ",
284 " emissiveColor 0 1 0",
290 " 16, 15, 14, 13, -1",
296 " DEF soxt->curInfoSwitch Switch ",
299 " DEF soxt->curInfoTrans Translation ",
301 " translation 10 20 30 ",
303 " DEF soxt->curInfoFont Font ",
305 " name defaultFont:Bold",
308 " DEF soxt->curInfoText Text2 ",
317 " DEF soxt->mouseOverTransLogName Translation ",
319 " translation 0 0 0 ",
321 " DEF soxt->mouseOverFontLogName Font ",
323 " name defaultFont:Bold",
326 " DEF soxt->mouseOverTextLogName Text2 { } ",
330 " DEF soxt->mouseOverTransSolid Translation ",
332 " translation 0 0 0 ",
334 " DEF soxt->mouseOverFontSolid Font ",
336 " name defaultFont:Bold",
339 " DEF soxt->mouseOverTextSolid Text2 { } ",
343 " DEF soxt->mouseOverTransMaterial Translation ",
345 " translation 0 0 0 ",
347 " DEF soxt->mouseOverFontMaterial Font ",
349 " name defaultFont:Bold",
352 " DEF soxt->mouseOverTextMaterial Text2 { } ",
356 " DEF soxt->mouseOverTransZPos Translation ",
358 " translation 0 0 0 ",
360 " DEF soxt->mouseOverFontZPos Font ",
362 " name defaultFont:Bold",
365 " DEF soxt->mouseOverTextZPos Text2 { } ",
371 for (i = bufsize = 0; superimposed[i]; i++)
372 bufsize += strlen(superimposed[i]) + 1;
373 char * buf =
new char[bufsize + 1];
374 for (i = bufsize = 0; superimposed[i]; i++) {
375 strcpy(buf + bufsize, superimposed[i]);
376 bufsize += strlen(superimposed[i]);
380 SoInput * input =
new SoInput;
381 input->setBuffer(buf, bufsize);
382 SbBool ok = SoDB::read(input, this->superimposition);
387 this->superimposition->ref();
389 this->sscale = (SoScale *) this->getSuperimpositionNode(
390 this->superimposition,
"soxt->scale");
391 this->stranslation = (SoTranslation *) this->getSuperimpositionNode(
392 this->superimposition,
"soxt->translation");
393 this->sgeometry = (SoCoordinate3 *) this->getSuperimpositionNode(
394 this->superimposition,
"soxt->geometry");
395 this->axisSwitch = (SoSwitch *) this->getSuperimpositionNode(
396 this->superimposition,
"soxt->axisSwitch");
397 this->animSpeedOutlineSwitch = (SoSwitch *) this->getSuperimpositionNode(
398 this->superimposition,
"soxt->animSpeedOutlineSwitch");
399 this->animSpeedSwitch = (SoSwitch *) this->getSuperimpositionNode(
400 this->superimposition,
"soxt->animSpeedSwitch");
401 this->curInfoSwitch = (SoSwitch *) this->getSuperimpositionNode(
402 this->superimposition,
"soxt->curInfoSwitch");
403 this->curInfoTrans = (SoTranslation *) this->getSuperimpositionNode(
404 this->superimposition,
"soxt->curInfoTrans");
405 this->curInfoFont = (SoFont *) this->getSuperimpositionNode(
406 this->superimposition,
"soxt->curInfoFont");
407 this->curInfoText = (SoText2 *) this->getSuperimpositionNode(
408 this->superimposition,
"soxt->curInfoText");
409 this->mouseOverTransLogName = (SoTranslation*)this->getSuperimpositionNode(
410 this->superimposition,
"soxt->mouseOverTransLogName");
411 this->mouseOverFontLogName = (SoFont *) this->getSuperimpositionNode(
412 this->superimposition,
"soxt->mouseOverFontLogName");
413 this->mouseOverTextLogName = (SoText2 *) this->getSuperimpositionNode(
414 this->superimposition,
"soxt->mouseOverTextLogName");
415 this->mouseOverTransSolid = (SoTranslation *) this->getSuperimpositionNode(
416 this->superimposition,
"soxt->mouseOverTransSolid");
417 this->mouseOverFontSolid = (SoFont *) this->getSuperimpositionNode(
418 this->superimposition,
"soxt->mouseOverFontSolid");
419 this->mouseOverTextSolid = (SoText2 *) this->getSuperimpositionNode(
420 this->superimposition,
"soxt->mouseOverTextSolid");
421 this->mouseOverTransMaterial = (SoTranslation*)this->getSuperimpositionNode(
422 this->superimposition,
"soxt->mouseOverTransMaterial");
423 this->mouseOverFontMaterial = (SoFont *) this->getSuperimpositionNode(
424 this->superimposition,
"soxt->mouseOverFontMaterial");
425 this->mouseOverTextMaterial = (SoText2 *) this->getSuperimpositionNode(
426 this->superimposition,
"soxt->mouseOverTextMaterial");
427 this->mouseOverTransZPos = (SoTranslation *) this->getSuperimpositionNode(
428 this->superimposition,
"soxt->mouseOverTransZPos");
429 this->mouseOverFontZPos = (SoFont *) this->getSuperimpositionNode(
430 this->superimposition,
"soxt->mouseOverFontZPos");
431 this->mouseOverTextZPos = (SoText2 *) this->getSuperimpositionNode(
432 this->superimposition,
"soxt->mouseOverTextZPos");
434 SoCallback * cb = (SoCallback *) this->getSuperimpositionNode(
435 this->superimposition,
"soxt->callback");
436 cb->setCallback(superimpositionCB,
this);
438 this->addSuperimposition(this->superimposition);
439 this->setSuperimpositionEnabled(this->superimposition,
FALSE);
440 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
441 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
442 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
471 G4OpenInventorXtExaminerViewer::getSuperimpositionNode(SoNode *root,
475 this->searcher =
new SoSearchAction;
477 searcher->setName(SbName(name));
478 searcher->setInterest(SoSearchAction::FIRST);
479 searcher->setSearchingAll(
TRUE);
480 searcher->apply(root);
481 assert(searcher->getPath());
482 return searcher->getPath()->getTail();
486 void G4OpenInventorXtExaminerViewer::superimpositionCB(
void * closure,
496 void G4OpenInventorXtExaminerViewer::superimpositionEvent(SoAction * action)
499 if (!action->isOfType(SoGLRenderAction::getClassTypeId()))
501 SbViewportRegion vpRegion =
502 ((SoGLRenderAction *) action)->getViewportRegion();
503 SbVec2s viewportSize = vpRegion.getViewportSizePixels();
505 float aspect = float(viewportSize[0]) / float(viewportSize[1]);
506 float factorx = 1.0f / float(viewportSize[1]) * 220.0f;
507 float factory = factorx;
510 this->stranslation->translation.setValue(SbVec3f(0.0f, -0.4f, 0.0f));
512 this->stranslation->translation.setValue(
513 SbVec3f(0.0f, -0.4f / aspect, 0.0f));
517 if (viewportSize[0] > 500)
518 factorx *= 500.0f / 400.0f;
520 factorx *= float(viewportSize[0]) / 400.0f;
521 this->sscale->scaleFactor.setValue(SbVec3f(factorx, factory, 1.0f));
523 float xInfo, yInfo, xMouseLogName, yMouseLogName, xMouseSolid, yMouseSolid,
524 xMouseMaterial, yMouseMaterial, xMouseZPos, yMouseZPos;
528 yMouseLogName = -.75;
531 xMouseMaterial = 0.0;
532 yMouseMaterial = -.81;
538 xMouseSolid *= aspect;
539 xMouseMaterial *= aspect;
540 this->curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
541 this->mouseOverTransLogName->translation.setValue(
542 SbVec3f(xMouseLogName, yMouseLogName, 0.0));
543 this->mouseOverTransSolid->translation.setValue(
544 SbVec3f(xMouseSolid, yMouseSolid, 0.0));
545 this->mouseOverTransMaterial->translation.setValue(
546 SbVec3f(xMouseMaterial, yMouseMaterial, 0.0));
547 this->mouseOverTransZPos->translation.setValue(
548 SbVec3f(xMouseZPos, yMouseZPos, 0.0));
551 yMouseSolid /= aspect;
552 yMouseMaterial /= aspect;
553 this->curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
554 this->mouseOverTransLogName->translation.setValue(
555 SbVec3f(xMouseLogName, yMouseLogName, 0.0));
556 this->mouseOverTransSolid->translation.setValue(
557 SbVec3f(xMouseSolid, yMouseSolid, 0.0));
558 this->mouseOverTransMaterial->translation.setValue(
559 SbVec3f(xMouseMaterial, yMouseMaterial, 0.0));
560 this->mouseOverTransZPos->translation.setValue(
561 SbVec3f(xMouseZPos, yMouseZPos, 0.0));
564 if (currentState == VIEWPOINT) {
565 this->curInfoFont->size.setValue(15);
566 this->curInfoFont->name.setValue(
"defaultFont:Italic");
567 this->curInfoText->string.setValue(SbString(curViewPtName));
569 else if(currentState == GENERAL) {
570 this->curInfoFont->size.setValue(16);
571 this->curInfoFont->name.setValue(
"defaultFont:Bold");
572 this->curInfoText->string.setValue(SbString(
""));
575 if (refParticleIdx < (
int) refParticleTrajectory.size() - 1) {
576 this->curInfoFont->size.setValue(16);
577 this->curInfoFont->name.setValue(
"defaultFont:Bold");
579 sprintf(zPos,
"%7.2f [m]", refZPositions[refParticleIdx] / 1000);
580 this->curInfoText->string.setValue(SbString(zPos));
588 if (superimposition != NULL) {
589 removeSuperimposition(superimposition);
590 superimposition->unref();
591 superimposition = NULL;
593 if (animateSensor->isScheduled())
594 animateSensor->unschedule();
595 delete animateSensor;
596 delete sceneChangeSensor;
598 delete[] curViewPtName;
609 Atom WM_DELETE_WINDOW;
612 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::buildWidget",
"Error: Parent is null.");
615 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
616 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
617 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
618 XtSetArg(args[3], XmNbottomAttachment, XmATTACH_FORM);
619 Widget form = XmCreateForm(parent, (
char *)
"Form", args, 4);
622 shell = XtParent(form);
623 WM_DELETE_WINDOW = XInternAtom(XtDisplay(parent),
"WM_DELETE_WINDOW",
625 XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW,
626 (XtCallbackProc)closeMainWindowCB,
this);
628 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
629 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
630 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
631 menuBar = XmCreateMenuBar(form, (
char *)
"MenuBar", args, 3);
632 XtManageChild(menuBar);
635 this->
addButton(fileMenu,
"Open Viewpoint File...", openViewPtFileCB);
636 addButton(fileMenu,
"New Viewpoint File", newViewPtFileCB);
637 addButton(fileMenu,
"Load Ref. Coords", loadRefCoordsDialogCB);
638 addButton(fileMenu,
"Save Ref. Coords", saveRefCoordsDialogCB);
639 addButton(fileMenu,
"Load Scene Graph", loadSceneGraphDialogCB);
640 addButton(fileMenu,
"Save Scene Graph", saveSceneGraphDialogCB);
642 XmCreateSeparatorGadget(fileMenu, (
char *)
"Separator", NULL, 0));
644 Widget menu =
addMenu(
"Tools");
645 addButton(menu,
"Animate Ref. Particle", animateRefParticleCB);
646 addButton(menu,
"Go to start of Ref path", gotoRefPathStartCB);
647 addButton(menu,
"Invert Ref path", invertRefPathCB);
649 Widget viewerBase = SoXtFullViewer::buildWidget(form);
651 XtSetArg(args[0], XmNtopAttachment, XmATTACH_WIDGET);
652 XtSetArg(args[1], XmNtopWidget, menuBar);
653 XtSetArg(args[2], XmNleftAttachment, XmATTACH_FORM);
654 XtSetArg(args[3], XmNrightAttachment, XmATTACH_FORM);
655 XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM);
656 XtSetValues(viewerBase, args, 5);
666 Widget menu = XmCreatePulldownMenu(menuBar, (
char *) name.c_str(), NULL, 0);
668 XtSetArg(args[0], XmNsubMenuId, menu);
669 Widget w = XmCreateCascadeButton(menuBar, (
char *) name.c_str(), args, 1);
680 Widget button = XmCreatePushButton(menu, (
char *) name.c_str(), NULL, 0);
681 XtManageChild(button);
682 XtAddCallback(button, XmNactivateCallback, cb,
this);
688 SbPList * buttonlist)
692 Widget saveViewPtButton, abbrOutputButton, pickRefPathButton;
693 Widget switchWireFrameButton;
696 SoXtExaminerViewer::createViewerButtons(parent, buttonlist);
699 Widget emptyButton = XtVaCreateManagedWidget(
"", xmPushButtonWidgetClass,
701 buttonlist->append(emptyButton);
705 XtSetArg(args[n], XmNtopPosition, 1); n++;
706 XtSetArg(args[n], XmNbottomPosition, 2); n++;
707 XtSetArg(args[n], XmNleftPosition, 0); n++;
708 XtSetArg(args[n], XmNrightPosition, 1); n++;
709 XtSetArg(args[n], XmNarrowDirection, XmARROW_LEFT); n++;
710 XtSetArg(args[n], XmNsensitive, False); n++;
711 prevViewPtButton = XmCreateArrowButtonGadget(parent, (
char *)
"ArrowL",
713 XtManageChild(prevViewPtButton);
714 XtAddCallback(prevViewPtButton, XmNactivateCallback,
715 G4OpenInventorXtExaminerViewer::prevViewPtCB,
this);
716 buttonlist->append(prevViewPtButton);
720 XtSetArg(args[n], XmNtopPosition, 1); n++;
721 XtSetArg(args[n], XmNbottomPosition, 2); n++;
722 XtSetArg(args[n], XmNleftPosition, 0); n++;
723 XtSetArg(args[n], XmNrightPosition, 1); n++;
724 XtSetArg(args[n], XmNarrowDirection, XmARROW_RIGHT); n++;
725 XtSetArg(args[n], XmNsensitive, False); n++;
726 nextViewPtButton = XmCreateArrowButtonGadget(parent, (
char *)
"ArrowR",
728 XtManageChild(nextViewPtButton);
729 XtAddCallback(nextViewPtButton, XmNactivateCallback,
730 G4OpenInventorXtExaminerViewer::nextViewPtCB,
this);
731 buttonlist->append(nextViewPtButton);
734 saveViewPtButton = XtVaCreateManagedWidget(
"Save", xmPushButtonWidgetClass,
736 XtAddCallback(saveViewPtButton, XmNactivateCallback,
737 G4OpenInventorXtExaminerViewer::saveViewPtCB,
this);
738 Pixmap saveVP, saveVP_ins;
743 XtVaSetValues(saveViewPtButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
744 saveVP, XmNselectPixmap, saveVP, XmNlabelInsensitivePixmap,
745 saveVP_ins, XmNselectInsensitivePixmap, saveVP_ins, NULL);
746 buttonlist->append(saveViewPtButton);
749 abbrOutputButton = XtVaCreateManagedWidget(
"Abbr",
750 xmToggleButtonWidgetClass, parent, XmNindicatorOn, False, NULL);
751 XtAddCallback(abbrOutputButton, XmNdisarmCallback, G4OpenInventorXtExaminerViewer::abbrOutputCB,
753 Pixmap pickextxpm, pickextxpm_ins;
758 XtVaSetValues(abbrOutputButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
759 pickextxpm, XmNselectPixmap, pickextxpm, XmNlabelInsensitivePixmap,
760 pickextxpm_ins, XmNselectInsensitivePixmap, pickextxpm_ins, NULL);
769 buttonlist->append(abbrOutputButton);
772 pickRefPathButton = XtVaCreateManagedWidget(
"Refpath", xmPushButtonWidgetClass,
774 XtAddCallback(pickRefPathButton, XmNactivateCallback,
775 G4OpenInventorXtExaminerViewer::pickRefPathCB,
this);
776 Pixmap pickrefxpm, pickrefxpm_ins;
781 XtVaSetValues(pickRefPathButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
782 pickrefxpm, XmNselectPixmap, pickrefxpm, XmNlabelInsensitivePixmap,
783 pickrefxpm_ins, XmNselectInsensitivePixmap, pickrefxpm_ins, NULL);
785 buttonlist->append(pickRefPathButton);
788 switchWireFrameButton = XtVaCreateManagedWidget(
"Wireframe",
789 xmToggleButtonWidgetClass, parent, XmNindicatorOn, False, NULL);
790 XtAddCallback(switchWireFrameButton, XmNvalueChangedCallback,
791 G4OpenInventorXtExaminerViewer::switchWireFrameCB,
this);
792 Pixmap wireframe, wireframe_ins;
797 XtVaSetValues(switchWireFrameButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
798 wireframe, XmNselectPixmap, wireframe, XmNlabelInsensitivePixmap,
799 wireframe_ins, XmNselectInsensitivePixmap, wireframe_ins, NULL);
800 buttonlist->append(switchWireFrameButton);
808 SoXtExaminerViewer::afterRealizeHook();
812 SoCamera *cam = getCamera();
814 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
816 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
819 ((SoOrthographicCamera *) cam)->height.getValue();
823 ((SoOrthographicCamera *) cam)->height.getValue();
826 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
828 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
834 fileIn.open(fileName.c_str());
835 if (!fileIn.fail()) {
837 String dialogName = (
char *)
"Error Loading File";
838 std::string msg =
"Wrong or corrupted input file.";
842 fileOut.open(fileName.c_str(), std::ios::in);
843 fileOut.seekp(0, std::ios::end);
844 constructListsDialog(getParentWidget(),
this, NULL);
846 if (viewPtList.size()) {
850 XtSetSensitive(nextViewPtButton, True);
851 XtSetSensitive(prevViewPtButton, True);
858 fileOut.open(fileName.c_str());
859 constructListsDialog(getParentWidget(),
this, NULL);
864 SoSeparator *root = (SoSeparator *) (getSceneManager()->getSceneGraph());
866 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::afterRealizeHook",
"Root is null.");
868 root->addChild(myCam);
871 sceneChangeSensor =
new SoNodeSensor;
872 sceneChangeSensor->setFunction(sceneChangeCB);
873 sceneChangeSensor->attach(root);
874 sceneChangeSensor->setData(
this);
880 SoEventCallback *moCB =
new SoEventCallback;
881 moCB->addEventCallback(
882 SoLocation2Event::getClassTypeId(),
883 mouseoverCB, static_cast<void *>(
this));
884 root->addChild(moCB);
888 SoEventCallback *pickCB =
new SoEventCallback;
889 pickCB->addEventCallback(
890 SoMouseButtonEvent::getClassTypeId(),
891 pickingCB, static_cast<void *>(
this));
892 root->addChild(pickCB);
901 SoCamera *cam = getCamera();
907 SbVec3f camPosNew = prevPt - (
camDir*distance);
908 cam->position = camPosNew;
910 cam->focalDistance = (prevPt - camPosNew).length();
914 if (animateSensorRotation->isScheduled()) {
915 animateSensorRotation->unschedule();
918 animateSensorRotation->setBaseTime(SbTime::getTimeOfDay());
919 animateSensorRotation->setInterval(SbTime(0.02));
920 animateSensorRotation->schedule();
929 SoCamera *cam = getCamera();
934 if(refParticleTrajectory.size() == 0) {
939 distance = (cam->position.getValue() - center).length();
941 cam->position.setValue(center + offsetFromCenter*distance);
942 cam->focalDistance = (cam->position.getValue() - center).length();
943 cam->pointAt(center, upVector);
949 if (refParticleIdx >= (
int) refParticleTrajectory.size() - 1) {
950 prevPt = refParticleTrajectory[refParticleIdx - step];
951 dist = (prevPt - cam->position.getValue()).length();
956 if (refParticleIdx < 0) {
957 prevPt = refParticleTrajectory[refParticleIdx + step];
958 dist = (prevPt - cam->position.getValue()).length();
959 refParticleIdx = refParticleTrajectory.size() - 2;
963 p1 = refParticleTrajectory[refParticleIdx];
964 p2 = refParticleTrajectory[refParticleIdx + step];
967 particleDir = p2 - p1;
968 particleDir.normalize();
970 if(prevParticleDir == SbVec3f(0,0,0)){
981 SbRotation rot(SbVec3f(0,0,1), particleDir);
986 else if(particleDir != prevParticleDir) {
989 SbRotation rot(prevParticleDir, particleDir);
995 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
997 distance = (prevPt - cam->position.getValue()).length();
1002 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
1004 distance = (prevPt - cam->position.getValue()).length();
1011 prevPt.getValue(x,y,z);
1014 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1015 camPosNew = p2 - (
camDir*distance);
1017 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
1018 camPosNew = p2 - (
camDir);
1021 cam->position = camPosNew;
1028 camPosNew.getValue(x,y,z);
1030 prevParticleDir = particleDir;
1038 void G4OpenInventorXtExaminerViewer::pickingCB(
void *aThis,
1039 SoEventCallback *eventCB)
1041 SoHandleEventAction* action = eventCB->getAction();
1042 const SoPickedPoint *
pp = action->getPickedPoint();
1047 SoPath* path = pp->getPath();
1048 SoNode* node = ((SoFullPath*)path)->getTail();
1050 if(node->getTypeId() == SoLineSet::getClassTypeId()){
1057 This->setComponentCursor(SoXtCursor(SoXtCursor::DEFAULT));
1060 SoLineSet * trajectory = (SoLineSet *)node;
1066 SoSeparator * grpNode =
1067 (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1072 int nodeIndex = grpNode->findChild(trajectory);
1075 SoCoordinate3 * coords = 0;
1079 for(
int i = 0; i < 100; ++i) {
1082 tmpNode = grpNode->getChild(nodeIndex);
1083 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()){
1085 coords = (SoCoordinate3 *)tmpNode;
1091 String dialogName = (
char *)
"No coordinates";
1092 std::string msg =
"Could not find the coordinates node"
1093 " for the picked trajectory."
1094 " Reference trajectory not set";
1100 if ((This->lshiftdown) || (This->rshiftdown))
1101 This->setReferencePath(trajectory, coords,
true);
1103 This->setReferencePath(trajectory, coords,
false);
1111 if(attHolder && attHolder->
GetAttDefs().size()) {
1113 std::string strTrajPoint =
"G4TrajectoryPoint:";
1114 std::ostringstream oss;
1115 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1120 if(oss.str().find(strTrajPoint) != std::string::npos) {
1135 G4String cls((
char*)node->getTypeId().getName().getString());
1136 G4cout <<
"SoNode : " << node
1137 <<
" SoType : " << cls
1138 <<
" name : " << name
1155 if(attHolder && attHolder->
GetAttDefs().size()) {
1156 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1162 G4String cls((
char*)node->getTypeId().getName().getString());
1163 G4cout <<
"SoNode : " << node
1164 <<
" SoType : " << cls
1165 <<
" name : " << name
1171 eventCB->setHandled();
1176 void G4OpenInventorXtExaminerViewer::mouseoverCB(
void *aThis, SoEventCallback *eventCB)
1178 SoHandleEventAction* action = eventCB->getAction();
1179 const SoPickedPoint* pp = action->getPickedPoint();
1187 const SbViewportRegion & viewportRegion = action->getViewportRegion();
1189 std::string sLogName;
1191 std::stringstream ssZPos;
1192 std::stringstream ssSolids;
1193 std::stringstream ssMaterials;
1194 SoPath * path = pp->getPath();
1195 SoNode* node = ((SoFullPath*)path)->getTail();
1197 if(node->getTypeId() == Geant4_SoPolyhedron::getClassTypeId()) {
1199 sLogName =
"Logical Volume: ";
1202 SoGetBoundingBoxAction bAction(viewportRegion);
1203 bAction.apply((SoFullPath*)path);
1204 SbBox3f bBox = bAction.getBoundingBox();
1205 SbVec3f center = bBox.getCenter();
1206 center.getValue(x,y,z);
1207 ssZPos <<
"Pos: " << x <<
" " << y <<
" " << z;
1210 if(attHolder && attHolder->
GetAttDefs().size()) {
1212 std::vector<const std::map<G4String,G4AttDef>*> vecDefs =
1214 std::vector<const std::vector<G4AttValue>*> vecVals =
1216 for (
size_t i = 0; i < vecDefs.size(); ++i) {
1217 const std::vector<G4AttValue> * vals = vecVals[i];
1219 std::vector<G4AttValue>::const_iterator iValue;
1221 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1222 const G4String& valueName = iValue->GetName();
1225 if(valueName ==
"Solid") {
1226 if(ssSolids.str() ==
"")
1227 ssSolids <<
"Solid Name: " << value;
1229 ssSolids <<
", " <<
value;
1232 if(valueName ==
"Material") {
1233 if(ssMaterials.str() ==
"")
1234 ssMaterials <<
"Material Name: " << value;
1236 ssMaterials <<
", " <<
value;
1243 else if(node->getTypeId() == SoLineSet::getClassTypeId()) {
1246 if(attHolder && attHolder->
GetAttDefs().size()) {
1247 std::string strTrajPoint =
"G4TrajectoryPoint:";
1248 std::ostringstream oss;
1250 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1253 const std::vector<G4AttValue>* vals = attHolder->
GetAttValues()[i];
1254 std::vector<G4AttValue>::const_iterator iValue;
1255 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1256 const G4String& valueName = iValue->GetName();
1257 const G4String& value = iValue->GetValue();
1261 if (valueName ==
"PN") t1 =
value;
1262 if (valueName ==
"Ch") {
1263 if (atof(value.c_str()) > 0)
1269 if (valueName ==
"PDG") {
1273 This->mouseOverTextLogName->string.setValue(t1);
1277 if (valueName ==
"EventID") t2 =
"Evt " +
value;
1278 if (valueName ==
"ID") t2 +=
" Trk " +
value;
1279 if (valueName ==
"PID") {
1280 t2 +=
" Prt " +
value;
1281 This->mouseOverTextSolid->string.setValue(t2);
1284 if (valueName ==
"IKE") t3 =
"KE " +
value;
1285 if (valueName ==
"IMom") {
1287 unsigned ipos = value.rfind(
" ");
1290 t3 +=
" P (" + value1 +
")";
1292 if (valueName ==
"IMag") {
1293 t3 +=
" " + value +
"/c";
1295 This->mouseOverTextMaterial->string.setValue(t3);
1298 if (valueName ==
"NTP") {
1299 std::ostringstream t4oss;
1300 t4oss <<
"TrjPts " <<
value;
1301 t4oss <<
" Pos " << pp->getPoint()[0] <<
" " << pp->getPoint()[1] <<
1302 " " << pp->getPoint()[2];
1303 This->mouseOverTextZPos->string.setValue(SbString(t4oss.str().c_str()));
1324 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
1325 This->scheduleRedraw();
1326 eventCB->setHandled();
1330 bool redraw =
false;
1331 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) != sLogName) {
1332 This->mouseOverTextLogName->string.setValue(SbString(sLogName.c_str()));
1335 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) != ssSolids.str()) {
1336 This->mouseOverTextSolid->string.setValue(SbString(ssSolids.str().c_str()));
1339 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) != ssMaterials.str()){
1340 This->mouseOverTextMaterial->string.setValue(SbString(ssMaterials.str().c_str()));
1343 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) != ssZPos.str()) {
1344 This->mouseOverTextZPos->string.setValue(SbString(ssZPos.str().c_str()));
1349 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
1350 This->scheduleRedraw();
1353 eventCB->setHandled();
1356 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) !=
"") {
1357 This->mouseOverTextLogName->string.setValue(SbString(
""));
1358 This->scheduleRedraw();
1360 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) !=
"") {
1361 This->mouseOverTextSolid->string.setValue(SbString(
""));
1362 This->scheduleRedraw();
1364 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) !=
"") {
1365 This->mouseOverTextMaterial->string.setValue(SbString(
""));
1366 This->scheduleRedraw();
1368 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) !=
"") {
1369 This->mouseOverTextZPos->string.setValue(SbString(
""));
1370 This->scheduleRedraw();
1377 SoCamera *cam = getCamera();
1378 const SoType type(ev->getTypeId());
1380 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
1381 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
1383 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1384 || currentState == PAUSED_ANIMATION) {
1385 switch (me->getButton()) {
1386 case SoMouseButtonEvent::BUTTON4:
1387 if (me->getState() == SoButtonEvent::DOWN) {
1388 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1390 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1391 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1394 }
else if (cam->isOfType(
1395 SoOrthographicCamera::getClassTypeId())) {
1397 ((SoOrthographicCamera *) cam)->height.getValue();
1398 ((SoOrthographicCamera *) cam)->height = height + 5;
1403 case SoMouseButtonEvent::BUTTON5:
1404 if (me->getState() == SoButtonEvent::DOWN) {
1405 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1407 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1409 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1412 }
else if (cam->isOfType(
1413 SoOrthographicCamera::getClassTypeId())) {
1415 ((SoOrthographicCamera *) cam)->height.getValue();
1417 ((SoOrthographicCamera *) cam)->height = height - 5;
1426 if (currentState == GENERAL) {
1431 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
1432 SoKeyboardEvent * ke = (SoKeyboardEvent *) ev;
1434 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
1435 switch (ke->getKey()) {
1436 case SoKeyboardEvent::LEFT_SHIFT:
1437 this->lshiftdown =
true;
1439 case SoKeyboardEvent::RIGHT_SHIFT:
1440 this->rshiftdown =
true;
1442 case SoKeyboardEvent::LEFT_CONTROL:
1443 this->lctrldown =
true;
1445 case SoKeyboardEvent::RIGHT_CONTROL:
1446 this->rctrldown =
true;
1448 case SoKeyboardEvent::SPACE:
1449 if (currentState == ANIMATION
1450 || currentState == REVERSED_ANIMATION) {
1451 beforePausing = currentState;
1452 currentState = PAUSED_ANIMATION;
1453 if (animateSensor->isScheduled())
1454 animateSensor->unschedule();
1456 }
else if (currentState == PAUSED_ANIMATION) {
1458 if ((beforePausing == ANIMATION
1460 < (
int) refParticleTrajectory.size() - 1)
1461 || (beforePausing == REVERSED_ANIMATION
1462 && refParticleIdx > 0)) {
1463 currentState = beforePausing;
1464 animateRefParticle();
1470 case SoKeyboardEvent::ESCAPE:
1471 if (currentState == ANIMATION
1472 || currentState == REVERSED_ANIMATION
1473 || currentState == PAUSED_ANIMATION) {
1475 if (animateSensor->isScheduled())
1476 animateSensor->unschedule();
1477 currentState = prevState;
1478 refParticleIdx = prevRefIdx;
1479 setSuperimpositionEnabled(superimposition,
FALSE);
1484 if (currentState == VIEWPOINT) {
1485 setSuperimpositionEnabled(superimposition,
TRUE);
1486 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
1487 animSpeedOutlineSwitch->whichChild.setValue(
1489 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1497 case SoKeyboardEvent::DELETE:
1498 if (viewPtList.size()
1499 && (currentState != ANIMATION
1500 || currentState != REVERSED_ANIMATION
1501 || currentState != PAUSED_ANIMATION)) {
1502 String dialogName = (
char *)
"Delete Viewpoint";
1503 std::string msg =
"Are you sure you want to delete current viewpoint?";
1508 case SoKeyboardEvent::LEFT_ARROW:
1509 switch (currentState) {
1511 if ((this->lshiftdown) || (this->rshiftdown)){
1512 refParticleIdx -= step;
1515 else if ((this->lctrldown) || (this->rctrldown)){
1516 if (SoXtExaminerViewer::isAnimating())
1518 prevState = currentState;
1519 currentState = ROTATING;
1520 animateBtwPtsPeriod = 0.08f;
1532 if (SoXtExaminerViewer::isAnimating())
1534 prevState = currentState;
1535 currentState = ROTATING;
1536 animateBtwPtsPeriod = 0.08f;
1551 case REVERSED_ANIMATION:
1554 case PAUSED_ANIMATION:
1556 setStartingPtForAnimation();
1557 cam->position = myCam->position;
1561 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1564 this->bottomWheelMotion(
1565 this->getBottomWheelValue() + 0.1f);
1575 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1576 "Unhandled viewer state");
1581 case SoKeyboardEvent::RIGHT_ARROW:
1582 switch(currentState){
1584 if ((this->lshiftdown) || (this->rshiftdown)){
1585 refParticleIdx += step;
1588 else if ((this->lctrldown) || (this->rctrldown)){
1589 if (SoXtExaminerViewer::isAnimating())
1591 prevState = currentState;
1592 currentState = ROTATING;
1593 animateBtwPtsPeriod = 0.08f;
1603 if (SoXtExaminerViewer::isAnimating())
1605 prevState = currentState;
1606 currentState = ROTATING;
1607 animateBtwPtsPeriod = 0.08f;
1619 case REVERSED_ANIMATION:
1622 case PAUSED_ANIMATION:
1624 setStartingPtForAnimation();
1625 cam->position = myCam->position;
1629 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1632 this->bottomWheelMotion(
1633 this->getBottomWheelValue() - 0.1f);
1642 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1643 "Unhandled viewer state");
1648 case SoKeyboardEvent::DOWN_ARROW:
1649 switch(currentState){
1652 if ((this->lshiftdown) || (this->rshiftdown)){
1653 refParticleIdx -= step;
1657 if (SoXtExaminerViewer::isAnimating())
1659 prevState = currentState;
1660 currentState = ROTATING;
1661 animateBtwPtsPeriod = 0.08f;
1674 case REVERSED_ANIMATION:
1677 case PAUSED_ANIMATION:
1679 setStartingPtForAnimation();
1680 cam->position = myCam->position;
1686 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1687 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
1696 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1697 "Unhandled viewer state");
1702 case SoKeyboardEvent::UP_ARROW:
1703 switch(currentState){
1705 if ((this->lshiftdown) || (this->rshiftdown)){
1706 refParticleIdx -= step;
1710 if (SoXtExaminerViewer::isAnimating())
1712 prevState = currentState;
1713 currentState = ROTATING;
1714 animateBtwPtsPeriod = 0.08f;
1727 case REVERSED_ANIMATION:
1730 case PAUSED_ANIMATION:
1732 setStartingPtForAnimation();
1733 cam->position = myCam->position;
1739 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1740 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
1749 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1750 "Unhandled viewer state");
1755 case SoKeyboardEvent::PAGE_UP:
1756 switch(currentState){
1758 if (step < (
int) refParticleTrajectory.size() / 5)
1769 case REVERSED_ANIMATION:
1770 if(!animateSensor->isScheduled()){
1771 currentState = ANIMATION;
1773 < (
int) refParticleTrajectory.size() - 1) {
1777 animateRefParticle();
1786 case PAUSED_ANIMATION:
1791 if (beforePausing == ANIMATION) {
1796 beforePausing = ANIMATION;
1806 case SoKeyboardEvent::PAGE_DOWN:
1807 switch(currentState){
1813 if(!animateSensor->isScheduled()){
1814 currentState = REVERSED_ANIMATION;
1815 if (refParticleIdx > 1) {
1819 animateRefParticle();
1828 case REVERSED_ANIMATION:
1831 if (maxSpeed < -0.8)
1835 case PAUSED_ANIMATION:
1837 if (maxSpeed < -0.8)
1839 if (beforePausing == REVERSED_ANIMATION) {
1844 beforePausing = REVERSED_ANIMATION;
1854 case SoKeyboardEvent::E:
1855 this->escapeCallback(this->examinerObject);
1862 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
1863 switch (ke->getKey()) {
1864 case SoKeyboardEvent::LEFT_SHIFT:
1865 this->lshiftdown =
false;
1867 case SoKeyboardEvent::RIGHT_SHIFT:
1868 this->rshiftdown =
false;
1870 case SoKeyboardEvent::LEFT_CONTROL:
1871 this->lctrldown =
false;
1873 case SoKeyboardEvent::RIGHT_CONTROL:
1874 this->rctrldown =
false;
1882 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1883 || currentState == ROTATING)
1886 return SoXtExaminerViewer::processSoEvent(ev);
1890 void G4OpenInventorXtExaminerViewer::incSpeed() {
1891 if (std::ceil(animateBtwPtsPeriod * 100) >= 4) {
1892 if (speedStep > 0.08)
1896 animateBtwPtsPeriod -= speedStep;
1898 animateBtwPtsPeriod = 0.0;
1900 if (currentState != PAUSED_ANIMATION) {
1901 int lastIdx = refParticleTrajectory.size() - 1;
1902 if (refParticleIdx < lastIdx && !animateSensor->isScheduled())
1903 animateRefParticle();
1908 void G4OpenInventorXtExaminerViewer::decSpeed() {
1909 animateBtwPtsPeriod += speedStep;
1911 if (std::floor(animateBtwPtsPeriod * 100) == 12) {
1913 }
else if (animateBtwPtsPeriod > 0.12)
1919 if (animateSensor->isScheduled())
1920 animateSensor->unschedule();
1925 void G4OpenInventorXtExaminerViewer::updateSpeedIndicator(
void) {
1926 assert(this->sgeometry != NULL);
1928 SbVec3f * points = this->sgeometry->point.startEditing();
1930 if (points[10][0] == 0.0f)
1931 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
1932 if (points[14][0] == 0.0f)
1933 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
1934 points[10][0] = this->maxSpeed;
1935 points[11][0] = this->maxSpeed;
1936 points[14][0] = this->maxSpeed;
1937 points[15][0] = this->maxSpeed;
1938 this->sgeometry->point.finishEditing();
1940 if (this->maxSpeed == 0.0f) {
1941 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
1942 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1946 void G4OpenInventorXtExaminerViewer::actualRedraw(
void) {
1947 switch (currentState) {
1949 case REVERSED_ANIMATION:
1950 case PAUSED_ANIMATION:
1951 updateSpeedIndicator();
1952 SoXtExaminerViewer::actualRedraw();
1955 SoXtExaminerViewer::actualRedraw();
1960 void G4OpenInventorXtExaminerViewer::setReferencePath(SoLineSet *lineset, SoCoordinate3 *coords,
bool append)
2001 SbVec3f refParticlePt;
2004 this->refParticleTrajectory.clear();
2006 for(
int i = 0; i < lineset->numVertices.getNum(); ++i){
2007 for(
int j = 0; j < lineset->numVertices[i]; ++j){
2008 refParticlePt = coords->point[j];
2009 this->refParticleTrajectory.push_back(refParticlePt);
2013 this->evenOutRefParticlePts();
2014 this->setReferencePathZPos();
2015 this->sortElements();
2019 void G4OpenInventorXtExaminerViewer::setReferencePathZPos()
2021 refZPositions.clear();
2022 refZPositions.push_back(0);
2024 for(
unsigned int i=0; i < this->refParticleTrajectory.size() - 1; ++i){
2025 dist = (refParticleTrajectory[i] -
2026 refParticleTrajectory[i + 1]).length();
2027 refZPositions.push_back(refZPositions[i] + dist);
2032 void G4OpenInventorXtExaminerViewer::findAndSetRefPath()
2034 SoSearchAction action;
2035 action.setType(SoLineSet::getClassTypeId(),
false);
2037 action.apply(this->getSceneGraph());
2039 SoPathList &pathList = action.getPaths();
2041 if(pathList.getLength() != 0){
2043 SoCoordinate3 * coords = NULL;
2044 std::vector<SoCoordinate3 *> coordvec;
2045 std::vector<SoLineSet *> linevec;
2047 bool refPathFound =
false;
2048 for(
int i = 0; i < pathList.getLength(); ++i) {
2049 SoFullPath *path = (SoFullPath *)pathList[i];
2052 for (
size_t j = 0; j < attHolder->
GetAttDefs().size(); ++j) {
2053 std::ostringstream oss;
2056 std::string findStr =
"Type of trajectory (Type): ";
2057 std::string compareValue =
"REFERENCE";
2058 size_t idx = oss.str().find(findStr);
2060 if(idx != std::string::npos) {
2061 if(oss.str().substr(idx + findStr.size(), compareValue.size()) == compareValue) {
2062 coords = this->getCoordsNode(path);
2064 refPathFound =
true;
2065 coordvec.push_back(coords);
2066 linevec.push_back((SoLineSet *)path->getTail());
2072 findStr =
"Track ID (ID): ";
2073 idx = oss.str().find(findStr);
2074 if(idx != std::string::npos) {
2076 std::string tmpstr = oss.str().substr(idx + findStr.size(),1);
2077 std::istringstream
buffer(tmpstr);
2085 char nextChar = oss.str().at(idx+findStr.size()+1);
2088 if(std::isdigit(nextChar))
2092 coords = this->getCoordsNode(path);
2094 coordvec.push_back(coords);
2095 linevec.push_back((SoLineSet *)path->getTail());
2111 if(coordvec.empty())
2116 this->setReferencePath(linevec.back(), coordvec.back());
2122 float longestLength = 0.0;
2124 for(
unsigned int i=0;i < linevec.size(); ++i){
2127 std::vector<SbVec3f> trajectory;
2129 for(
int j=0; j < linevec[i]->numVertices.getNum(); ++j){
2131 for(
int k=0; k < linevec[i]->numVertices[j]; ++k){
2132 trajectory.push_back(coordvec[i]->point[k]);
2137 float tmpLength=0.0;
2138 for(
unsigned int j=0; j < trajectory.size() - 1; ++j){
2139 tmpLength += (trajectory[j] - trajectory[j + 1]).length();
2142 if(tmpLength > longestLength){
2144 longestLength = tmpLength;
2149 this->setReferencePath(linevec[longestIdx], coordvec[longestIdx]);
2154 SoCoordinate3 * G4OpenInventorXtExaminerViewer::getCoordsNode(SoFullPath *path)
2156 SoLineSet *trajectory = (SoLineSet *)path->getTail();
2157 SoSeparator * grpNode = (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
2158 int nodeIndex = grpNode->findChild(trajectory);
2163 for(
int i = 0; i < 100; ++i){
2166 tmpNode = grpNode->getChild(nodeIndex);
2167 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()){
2169 return (SoCoordinate3 *)tmpNode;
2178 void G4OpenInventorXtExaminerViewer::getSceneElements()
2180 std::string field, eltName;
2182 std::map<std::string, int> duplicates;
2183 std::map<std::string, int> sceneElts;
2184 SoSearchAction search;
2186 SoGroup *root = (SoGroup *)getSceneManager()->getSceneGraph();
2188 SoBaseKit::setSearchingChildren(
TRUE);
2191 search.setSearchingAll(
TRUE);
2193 search.setType(Geant4_SoPolyhedron::getClassTypeId(), 0);
2196 SoPathList &pl = search.getPaths();
2200 for(
int i = 0; i < pl.getLength(); i++) {
2201 SoFullPath *path = (SoFullPath *)pl[i];
2203 eltName = node->getName();
2204 if(duplicates.count(eltName))
2205 duplicates[eltName]++;
2207 duplicates[eltName] = 1;
2210 for(
int i = 0; i < pl.getLength(); i++) {
2212 std::stringstream ssCount;
2213 SoFullPath *path = (SoFullPath *)pl[i];
2215 eltName = node->getName();
2217 if(duplicates[eltName] == 1)
2220 if(sceneElts.count(eltName))
2221 sceneElts[eltName]++;
2223 sceneElts[eltName] = 1;
2225 ssCount << sceneElts[eltName];
2229 field += ssCount.str();
2231 SoGetBoundingBoxAction bAction(getViewportRegion());
2232 bAction.apply(path);
2233 SbBox3f bBox = bAction.getBoundingBox();
2235 SbVec3f centr = bBox.getCenter();
2236 centr.getValue(x,y,z);
2239 sceneElement el = { field, path, centr, 0.0 };
2240 this->sceneElements.push_back(el);
2245 float G4OpenInventorXtExaminerViewer::sqrlen(
const SbVec3f &a)
2249 return x*x + y*y + z*z;
2253 void G4OpenInventorXtExaminerViewer::distanceToTrajectory(
const SbVec3f &q,
2255 SbVec3f &closestPoint,
2290 const size_t count = this->refParticleTrajectory.size();
2293 SbVec3f b = this->refParticleTrajectory[0];
2294 SbVec3f dbq = b - q;
2295 float sqrDist = sqrlen(dbq);
2298 for (
size_t i = 1; i < count; ++i) {
2299 const SbVec3f a = b;
2300 const SbVec3f daq = dbq;
2301 b = this->refParticleTrajectory[i];
2303 const SbVec3f dab = a - b;
2305 float dab_x, dab_y, dab_z;
2306 dab.getValue(dab_x,dab_y,dab_z);
2307 float daq_x, daq_y, daq_z;
2308 daq.getValue(daq_x, daq_y, daq_z);
2309 float dbq_x, dbq_y, dbq_z;
2310 dbq.getValue(dbq_x, dbq_y, dbq_z);
2312 const float inv_sqrlen = 1./sqrlen(dab);
2313 const float t = (dab_x*daq_x + dab_y*daq_y + dab_z*daq_z)*inv_sqrlen;
2324 current_dist = daq_x*daq_x + daq_y*daq_y + daq_z*daq_z
2325 - t*(daq_x*dab_x + daq_y*dab_y + daq_z*dab_z)
2326 + t*t*(dab_x*dab_x + dab_y*dab_y + dab_z*dab_z);
2331 current_dist = sqrlen(dbq);
2334 if (current_dist < sqrDist){
2335 sqrDist = current_dist;
2336 closestPoint = a + t*(b-a);
2341 dist = std::sqrt(sqrDist);
2345 void G4OpenInventorXtExaminerViewer::sortElements()
2347 if(this->refParticleTrajectory.empty())
2350 float * trajLength =
new float[this->refParticleTrajectory.size()];
2351 typedef std::map<elementForSorting, sceneElement> sortedMap;
2357 std::vector<SbVec3f>::iterator itRef = this->refParticleTrajectory.begin();
2360 trajLength[trajIndex] = 0.0;
2363 for(; itRef != this->refParticleTrajectory.end(); ++itRef, ++trajIndex){
2364 trajLength[trajIndex] = trajLength[trajIndex-1] + (*itRef - prevPoint).length();
2372 SoGetBoundingBoxAction bAction(this->getViewportRegion());
2373 SbVec3f elementCoord;
2374 std::vector<sceneElement>::iterator itEl;
2376 elementForSorting el;
2377 for(itEl = this->sceneElements.begin(), elementIndex = 0;
2378 itEl != this->sceneElements.end(); ++itEl, ++elementIndex){
2379 bAction.apply(itEl->path);
2382 elementCoord = itEl->center;
2391 distanceToTrajectory(elementCoord, el.smallestDistance, el.closestPoint, index);
2392 itEl->closestPointZCoord = el.closestPointZCoord = trajLength[index];
2393 el.distanceToBeamlineStart = (itEl->center - this->refParticleTrajectory[0]).length();
2400 sorted.insert(std::make_pair(el,*itEl));
2404 this->sceneElements.clear();
2406 sortedMap::iterator itSorted = sorted.begin();
2407 for(; itSorted != sorted.end(); itSorted++)
2408 this->sceneElements.push_back(itSorted->second);
2410 this->zcoordSetFlag =
true;
2413 Widget formTop = XtNameToWidget(this->listsDialog,
"FormTop");
2414 Widget formTopRight = XtNameToWidget(formTop,
"FormTopRight");
2416 this->createElementsList(formTopRight);
2418 delete[] trajLength;
2422 void G4OpenInventorXtExaminerViewer::createElementsList(Widget formTopRight)
2424 if(this->myElementList != NULL)
2425 XtUnmanageChild(this->myElementList);
2427 int size = this->sceneElements.size();
2428 XmString *elements = (XmString *) XtMalloc(size *
sizeof(XmString));
2430 std::vector<sceneElement>::const_iterator it;
2432 std::stringstream ss;
2433 for(it=this->sceneElements.begin(); it!=this->sceneElements.end(); ++it) {
2436 ss <<
" [" << it->closestPointZCoord <<
"]";
2437 elements[count] = XmStringCreateLocalized((
char *)ss.str().c_str());
2448 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2450 labelRight = XmCreateLabelGadget(formTopRight, (
char*)
"Element [S mm]",
2452 XtManageChild(labelRight);
2456 XtSetArg(args[n], XmNvisibleItemCount, 7); n++;
2457 XtSetArg(args[n], XmNitemCount, size); n++;
2458 XtSetArg(args[n], XmNitems, elements); n++;
2459 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2460 XtSetArg(args[n], XmNtopWidget, labelRight); n++;
2461 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2462 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2464 XtSetArg(args[n], XmNwidth, 240); n++;
2468 this->myElementList = XmCreateScrolledList(formTopRight, (
char *)
"ListRight", args, n);
2470 XtAddCallback(this->myElementList, XmNbrowseSelectionCallback,
2471 (XtCallbackProc) lookAtSceneElementCB,
this);
2473 XtManageChild(this->myElementList);
2475 if (elements != NULL) {
2476 for (
int i = 0; i < size; i++)
2477 XmStringFree(elements[i]);
2478 XtFree((
char *) elements);
2486 void G4OpenInventorXtExaminerViewer::constructListsDialog(Widget w,
2487 XtPointer client_data,
2492 if (This->listsDialog) {
2496 if (This->currentState == ANIMATION || This->currentState == PAUSED_ANIMATION) {
2497 if (This->animateSensor->isScheduled())
2498 This->animateSensor->unschedule();
2499 This->refParticleIdx = This->prevRefIdx;
2500 This->restoreCamera();
2501 This->currentState = This->prevState;
2505 This->refParticleIdx = 0;
2506 if (This->refParticleTrajectory.size()){
2507 This->prevPt = This->refParticleTrajectory[0];
2510 This->getSceneElements();
2514 Atom WM_DELETE_WINDOW;
2526 std::string dialogNameStr = This->fileName.substr(This->fileName.rfind(
'/') + 1);
2527 const int nDialog = dialogNameStr.size() + 1;
2528 char *dialogName =
new char[nDialog];
2529 strncpy(dialogName, dialogNameStr.c_str(), nDialog);
2532 XtSetArg(args[n], XmNx, 610); n++;
2533 This->myShellDialog = XmCreateDialogShell(topShell, dialogName, args, n);
2535 delete[] dialogName;
2536 WM_DELETE_WINDOW = XInternAtom(XtDisplay(w),
"WM_DELETE_WINDOW", False);
2537 XmAddWMProtocolCallback(This->myShellDialog, WM_DELETE_WINDOW,
2538 (XtCallbackProc)closeListsDialogCB, This);
2542 XtSetArg(args[n], XmNsashWidth, 1); n++;
2543 XtSetArg(args[n], XmNsashHeight, 1); n++;
2544 XtSetArg(args[n], XmNseparatorOn, False); n++;
2546 This->listsDialog = XmCreatePanedWindow(This->myShellDialog, (
char *)
"MainPane",
2554 Widget formTop = XmCreateForm(This->listsDialog, (
char *)
"FormTop", args, n);
2557 XtSetArg(args[n], XmNmarginWidth, 8); n++;
2558 XtSetArg(args[n], XmNmarginHeight, 8); n++;
2559 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2560 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2561 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2562 Widget formTopRight = XmCreateForm(formTop, (
char *)
"FormTopRight", args,
2566 XtSetArg(args[n], XmNmarginWidth, 8); n++;
2567 XtSetArg(args[n], XmNmarginHeight, 8); n++;
2568 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2569 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2570 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
2571 XtSetArg(args[n], XmNrightWidget, formTopRight); n++;
2572 XtSetArg(args[n], XmNrightOffset, 10); n++;
2573 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2574 Widget formTopLeft = XmCreateForm(formTop, (
char *)
"FormTopLeft", args, n);
2578 This->createElementsList(formTopRight);
2579 XtManageChild(formTopRight);
2585 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2586 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2587 Widget labelLeft = XmCreateLabelGadget(formTopLeft, (
char *)
"ViewPoints",
2589 XtManageChild(labelLeft);
2593 XtSetArg(args[n], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE); n++;
2594 XtSetArg(args[n], XmNvisibleItemCount, 7); n++;
2596 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2597 XtSetArg(args[n], XmNtopWidget, labelLeft); n++;
2598 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
2599 XtSetArg(args[n], XmNrightWidget, This->myElementList); n++;
2600 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2601 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2603 XtSetArg(args[n], XmNwidth, 160); n++;
2606 This->myViewPtList = XmCreateScrolledList(formTopLeft, (
char *)
"ListLeft",
2608 if (This->viewPtList.size())
2609 This->addViewPoints();
2610 XtAddCallback(This->myViewPtList, XmNbrowseSelectionCallback,
2611 (XtCallbackProc) loadBookmarkCB, This);
2614 XtManageChild(This->myViewPtList);
2616 XtManageChild(formTopLeft);
2618 XtManageChild(formTop);
2622 XtSetArg(args[n], XmNmarginWidth, 6); n++;
2625 Widget formMiddle = XmCreateForm(This->listsDialog, (
char *)
"MiddleForm", args, n);
2629 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2630 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2631 XtSetArg(args[n], XmNtopWidget, This->myViewPtList); n++;
2632 Widget label = XmCreateLabelGadget(formMiddle, (
char *)
"Selection", args,
2634 XtManageChild(label);
2638 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2639 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2640 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2641 XtSetArg(args[n], XmNtopWidget, label); n++;
2642 XtSetArg(args[n], XmNtopOffset, 3); n++;
2643 XtSetArg(args[n], XmNmaxLength, This->MAX_VP_NAME); n++;
2644 This->viewPtSelection = XmCreateText(formMiddle, (
char *)
"Txt", args, n);
2645 XtManageChild(This->viewPtSelection);
2647 Dimension h1, h2, h;
2648 XtVaGetValues(label, XmNheight, &h1, NULL);
2649 XtVaGetValues(This->viewPtSelection, XmNheight, &h2, NULL);
2651 h = (Dimension) (1.1 * (h1 + h2));
2653 XtVaSetValues(formMiddle, XmNpaneMaximum, h, XmNpaneMinimum, h, NULL);
2654 XtManageChild(formMiddle);
2659 XtSetArg(args[n], XmNfractionBase, 4); n++;
2660 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2661 XtSetArg(args[n], XmNtopWidget, This->viewPtSelection); n++;
2664 Widget formAction = XmCreateForm(This->listsDialog, (
char *)
"ActionForm", args, n);
2667 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2668 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2669 XtSetArg(args[n], XmNtopOffset, 3); n++;
2670 XtSetArg(args[n], XmNbottomOffset, 5); n++;
2671 Widget separator = XmCreateSeparatorGadget(formAction, (
char *)
"Sep", args, n);
2673 XtManageChild(separator);
2675 Widget button = XmCreatePushButton(formAction, (
char *)
"Delete", NULL, 0);
2676 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2677 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2678 XmATTACH_POSITION, XmNleftPosition, 0, XmNrightAttachment,
2679 XmATTACH_POSITION, XmNrightPosition, 1,
2680 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2683 XtAddCallback(button, XmNactivateCallback,
2684 (XtCallbackProc) deleteBookmarkCB, This);
2685 XtManageChild(button);
2687 button = XmCreatePushButton(formAction, (
char *)
"Rename", NULL, 0);
2688 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2689 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2690 XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment,
2691 XmATTACH_POSITION, XmNrightPosition, 2,
2692 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2695 XtAddCallback(button, XmNactivateCallback,
2696 (XtCallbackProc) renameBookmarkCB, This);
2697 XtManageChild(button);
2699 button = XmCreatePushButton(formAction, (
char *)
"Sort", NULL, 0);
2700 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2701 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2702 XmATTACH_POSITION, XmNleftPosition, 2, XmNrightAttachment,
2703 XmATTACH_POSITION, XmNrightPosition, 3,
2704 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2707 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc) sortBookmarksCB, This);
2708 XtManageChild(button);
2710 button = XmCreatePushButton(formAction, (
char *)
"Close", NULL, 0);
2711 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2712 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2713 XmATTACH_POSITION, XmNleftPosition, 3, XmNrightAttachment,
2714 XmATTACH_POSITION, XmNrightPosition, 4,
2715 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2718 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc) closeListsDialogCB, This);
2719 XtManageChild(button);
2721 XtManageChild(formAction);
2722 XtVaGetValues(button, XmNheight, &h1, NULL);
2723 XtVaSetValues(formAction, XmNpaneMaximum, h1, XmNpaneMinimum, h1, NULL);
2725 XtManageChild(This->listsDialog);
2733 void G4OpenInventorXtExaminerViewer::lookAtSceneElementCB(Widget,
2734 XtPointer client_data,
2735 XtPointer call_data)
2738 std::string elementField;
2740 SoCamera * cam = This->getCamera();
2742 if (This->SoXtExaminerViewer::isAnimating())
2743 This->stopAnimating();
2745 XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
2747 value = (
char *) XmStringUnparse(cbs->item, XmFONTLIST_DEFAULT_TAG,
2748 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
2749 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
2750 || This->currentState == PAUSED_ANIMATION ) {
2751 if (This->animateSensor->isScheduled())
2752 This->animateSensor->unschedule();
2753 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
2754 This->maxSpeed = 0.0f;
2755 This->scheduleRedraw();
2756 This->restoreCamera();
2757 This->currentState = This->prevState;
2758 }
else if (This->currentState == VIEWPOINT)
2759 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
2761 elementField =
value;
2763 int idx = elementField.find_last_of(
"[");
2765 idx = elementField.size();
2771 SoSearchAction search;
2772 SoNode *root = This->getSceneManager()->getSceneGraph();
2773 int counter, idxUnderscore = elementField.find_last_of(
"_");
2775 This->
parseString<
int>(counter, elementField.substr(idxUnderscore + 1, idx),
error);
2777 SoBaseKit::setSearchingChildren(
TRUE);
2779 search.setSearchingAll(
TRUE);
2782 This->
curEltName = elementField.substr(0, idx);
2786 path = (SoFullPath *)search.getPath();
2789 This->
curEltName = elementField.substr(0, idxUnderscore);
2794 SoPathList &pl = search.getPaths();
2795 path = (SoFullPath *)pl[counter - 1];
2800 if ((idx > 0) && (path)) {
2802 if(!This->refParticleTrajectory.empty()){
2804 SoGetBoundingBoxAction bAction(This->getViewportRegion());
2805 bAction.apply(path);
2806 SbBox3f bBox = bAction.getBoundingBox();
2807 SbVec3f elementCoord = bBox.getCenter();
2809 This->refParticleIdx = 0;
2812 float absLengthNow, absLengthMin;
2813 int maxIdx = This->refParticleTrajectory.size() - 2;
2817 p = This->refParticleTrajectory[This->refParticleIdx];
2818 absLengthMin = (p - elementCoord).length();
2819 This->refParticleIdx++;
2822 while (This->refParticleIdx < maxIdx) {
2823 p = This->refParticleTrajectory[This->refParticleIdx];
2824 absLengthNow = (p - elementCoord).length();
2826 if (absLengthNow < absLengthMin) {
2827 absLengthMin = absLengthNow;
2828 targetIdx = This->refParticleIdx;
2830 This->refParticleIdx++;
2833 if (This->currentState != BEAMLINE) {
2835 This->currentState = BEAMLINE;
2836 This->prevParticleDir = SbVec3f(0,0,0);
2838 p1 = This->prevPt = This->refParticleTrajectory[0];
2839 pN = This->refParticleTrajectory[This->refParticleTrajectory.size() - 1];
2840 This->distance = (pN - p1).length() / 10;
2843 if (cam->isOfType(SoOrthographicCamera::getClassTypeId()))
2844 ((SoOrthographicCamera *) cam)->height.setValue(This->defaultHeight);
2846 else if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2847 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2848 This->defaultHeightAngle);
2850 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2851 This->distance = (This->prevPt - cam->position.getValue()).length();
2853 This->refParticleIdx = targetIdx;
2856 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
2857 This->axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2858 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2859 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2860 This->scheduleRedraw();
2868 This->offsetFromCenter.setValue(0, 0, 1);
2869 This->distance = 50;
2870 This->upVector.setValue(0, 1, 0);
2873 cam->viewAll(path, This->getViewportRegion());
2877 XmTextSetString(This->viewPtSelection, NULL);
2883 void G4OpenInventorXtExaminerViewer::closeListsDialogCB(Widget,
2884 XtPointer client_data,
2889 This->sceneElements.clear();
2890 This->refParticleTrajectory.clear();
2892 This->currentState = GENERAL;
2893 XtDestroyWidget(This->myShellDialog);
2894 This->listsDialog = NULL;
2898 void G4OpenInventorXtExaminerViewer::prevViewPtCB(Widget, XtPointer client_data,
2902 if (This->viewPtIdx == 0)
2903 This->viewPtIdx = This->viewPtList.size() - 1;
2907 This->writeViewPtIdx();
2912 void G4OpenInventorXtExaminerViewer::nextViewPtCB(Widget, XtPointer client_data,
2916 if (This->viewPtIdx >= (
int) This->viewPtList.size() - 1)
2917 This->viewPtIdx = 0;
2921 This->writeViewPtIdx();
2928 void G4OpenInventorXtExaminerViewer::writeViewPtIdx()
2931 std::stringstream out;
2934 fileOut.seekp(0, std::ios::beg);
2936 while ((
int) idxStr.length() < MAX_VP_IDX) {
2940 fileOut << idxStr <<
"\n";
2942 fileOut.seekp(0, std::ios::end);
2948 void G4OpenInventorXtExaminerViewer::setViewPt()
2950 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
2951 || currentState == ROTATING) {
2953 if (animateSensor->isScheduled())
2954 animateSensor->unschedule();
2955 setSuperimpositionEnabled(superimposition,
FALSE);
2960 SoCamera * camera = getCamera();
2961 if (camera == NULL) {
2962 String dialogName = (
char *)
"Missing Camera Node";
2963 std::string msg =
"Camera is null. Unable to set the viewpoint.";
2968 if (!viewPtList.size()) {
2969 String dialogName = (
char *)
"Missing Viewpoints";
2970 std::string msg =
"There are no viewpoints to load.";
2975 if (SoXtExaminerViewer::isAnimating())
2978 if (currentState != VIEWPOINT) {
2979 currentState = VIEWPOINT;
2981 setSuperimpositionEnabled(superimposition,
TRUE);
2982 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2983 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2984 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2990 curViewPtName = viewPtList[viewPtIdx].viewPtName;
2991 camera->viewportMapping = viewPtList[viewPtIdx].viewportMapping;
2992 camera->position = viewPtList[viewPtIdx].position;
2993 camera->orientation = viewPtList[viewPtIdx].orientation;
2994 camera->aspectRatio = viewPtList[viewPtIdx].aspectRatio;
2995 camera->nearDistance = viewPtList[viewPtIdx].nearDistance;
2996 camera->farDistance = viewPtList[viewPtIdx].farDistance;
2997 camera->focalDistance = viewPtList[viewPtIdx].focalDistance;
3000 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3001 if (viewPtList[viewPtIdx].camType == ORTHOGRAPHIC) {
3003 camera = getCamera();
3004 ((SoOrthographicCamera *) camera)->height.setValue(
3005 viewPtList[viewPtIdx].height);
3007 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3008 viewPtList[viewPtIdx].height);
3009 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3010 if (viewPtList[viewPtIdx].camType == PERSPECTIVE) {
3012 camera = getCamera();
3013 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3014 viewPtList[viewPtIdx].height);
3016 ((SoOrthographicCamera *) camera)->height.setValue(
3017 viewPtList[viewPtIdx].height);
3019 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::setViewPt",
3020 "Only Perspective and Orthographic cameras are supported.");
3029 void G4OpenInventorXtExaminerViewer::saveViewPtCB(Widget w,
3030 XtPointer client_data,
3035 if (This->fileName.empty()) {
3036 newViewPtFileCB(w, This, NULL);
3037 This->returnToSaveVP =
true;
3043 Widget nameViewPtDialog;
3044 Widget parent = This->getParentWidget();
3045 XmString label = XmStringCreateLocalized((
char *)
"Name the viewpoint:");
3047 XtSetArg(args[n], XmNselectionLabelString, label); n++;
3049 XtSetArg(args[n], XmNautoUnmanage, False); n++;
3051 XtSetArg(args[n], XmNtitle,
"Save Bookmark"); n++;
3052 nameViewPtDialog = XmCreatePromptDialog(parent, String(
"Save Bookmark"),
3055 XmStringFree(label);
3056 XtAddCallback(nameViewPtDialog, XmNokCallback, getViewPtNameCB, This);
3057 XtAddCallback(nameViewPtDialog, XmNcancelCallback,
3058 (XtCallbackProc) XtDestroyWidget, NULL);
3060 Widget text = XtNameToWidget(nameViewPtDialog,
"Text");
3061 XtVaSetValues(text, XmNmaxLength, This->MAX_VP_NAME, NULL);
3062 std::string autoName =
"";
3064 autoName = This->viewPtAutoName();
3067 XmTextSetString(text, (
char *) autoName.c_str());
3068 XmTextSetInsertionPosition(text, autoName.length());
3070 XtUnmanageChild(XtNameToWidget(nameViewPtDialog,
"Help"));
3071 XtManageChild(nameViewPtDialog);
3075 std::string G4OpenInventorXtExaminerViewer::viewPtAutoName()
3078 std::stringstream sstream;
3079 std::vector<int> existingViewPts;
3083 for (
unsigned int i = 0; i < this->viewPtList.size(); ++i) {
3084 viewPt = this->viewPtList[i].viewPtName;
3085 if (viewPt.find(
"viewpoint_") != std::string::npos) {
3086 tmp = atoi(viewPt.substr(10).c_str());
3089 if (!viewPt.compare(
"viewpoint_0"))
3090 existingViewPts.push_back(0);
3092 existingViewPts.push_back(tmp);
3100 if (existingViewPts.size() > 0) {
3103 if (std::find(existingViewPts.begin(), existingViewPts.end(), vpNum)
3104 == existingViewPts.end()) {
3105 sstream <<
"viewpoint_" << vpNum;
3106 return sstream.str();
3111 return "viewpoint_0";
3117 void G4OpenInventorXtExaminerViewer::abbrOutputCB(Widget,
3118 XtPointer client_data,
3128 void G4OpenInventorXtExaminerViewer::pickRefPathCB(Widget,
3129 XtPointer client_data,
3136 if(This->isViewing())
3137 This->setViewing(
false);
3138 This->setComponentCursor(SoXtCursor(SoXtCursor::CROSSHAIR));
3143 void G4OpenInventorXtExaminerViewer::switchWireFrameCB(Widget w,
3144 XtPointer client_data,
3150 if (XmToggleButtonGetState(w)) {
3151 This->setDrawStyle(SoXtViewer::STILL, SoXtViewer::VIEW_LINE);
3152 This->setDrawStyle(SoXtViewer::INTERACTIVE, SoXtViewer::VIEW_LINE);
3154 This->setDrawStyle(SoXtViewer::STILL, SoXtViewer::VIEW_AS_IS);
3155 This->setDrawStyle(SoXtViewer::INTERACTIVE,
3156 SoXtViewer::VIEW_SAME_AS_STILL);
3163 void G4OpenInventorXtExaminerViewer::getViewPtNameCB(Widget w,
3164 XtPointer client_data,
3165 XtPointer call_data)
3168 std::string strName;
3170 XmSelectionBoxCallbackStruct *cbs =
3171 (XmSelectionBoxCallbackStruct *) call_data;
3172 XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &name);
3185 int beg = strName.find_first_not_of(
' ');
3186 int end = strName.find_last_not_of(
' ');
3187 strName = strName.substr(beg, end - beg + 1);
3189 bool nameExists =
false;
3190 int size = This->viewPtList.size();
3191 for (
int i = 0; i < size; i++) {
3192 if (!strcmp(This->viewPtList[i].viewPtName, strName.c_str())) {
3199 const int nVPName = This->MAX_VP_NAME + 1;
3200 name =
new char[nVPName];
3201 strncpy(name, strName.c_str(), nVPName);
3202 if (This->viewPtIdx == -1)
3203 This->viewPtIdx = 0;
3204 This->saveViewPt(name);
3205 if (This->listsDialog) {
3206 XmListAddItemUnselected(This->myViewPtList, cbs->value, 0);
3211 String dialogName = (
char *)
"Existing Viewpoint";
3212 std::string msg =
"The viewpoint already exists.";
3221 void G4OpenInventorXtExaminerViewer::saveViewPt(
char *name)
3225 float x, y, z,
angle;
3226 SoCamera * camera = getCamera();
3228 if (viewPtList.size() == 0) {
3230 XtSetSensitive(nextViewPtButton, True);
3231 XtSetSensitive(prevViewPtButton, True);
3234 tmp.viewPtName =
name;
3235 tmp.viewportMapping = camera->viewportMapping.getValue();
3236 tmp.position = camera->position.getValue();
3237 tmp.orientation = camera->orientation.getValue();
3238 tmp.aspectRatio = camera->aspectRatio.getValue();
3239 tmp.nearDistance = camera->nearDistance.getValue();
3240 tmp.farDistance = camera->farDistance.getValue();
3241 tmp.focalDistance = camera->focalDistance.getValue();
3244 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3245 tmp.height = ((SoPerspectiveCamera *) camera)->heightAngle.getValue();
3246 tmp.camType = PERSPECTIVE;
3247 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3248 tmp.height = ((SoOrthographicCamera *) camera)->height.getValue();
3249 tmp.camType = ORTHOGRAPHIC;
3251 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::saveViewPtCB",
3252 "Only Perspective and Orthographic cameras are supported.");
3256 viewPtList.push_back(tmp);
3259 std::string vpName =
name;
3261 while ((
int) vpName.size() <= MAX_VP_NAME)
3264 fileOut << vpName << std::endl;
3265 tmp.position.getValue(x, y, z);
3266 fileOut << x <<
" " << y <<
" " << z << std::endl;
3269 tmp.orientation.getValue(axis, angle);
3270 axis.getValue(x, y, z);
3271 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3273 fileOut << tmp.camType <<
" " << tmp.height << std::endl;
3274 fileOut << tmp.focalDistance <<
" ";
3275 fileOut << tmp.nearDistance <<
" ";
3276 fileOut << tmp.farDistance << std::endl;
3277 fileOut << tmp.viewportMapping <<
" ";
3278 fileOut << tmp.aspectRatio <<
"\n" << std::endl;
3284 void G4OpenInventorXtExaminerViewer::deleteViewPtCB(Widget,
3285 XtPointer client_data,
3290 This->deleteViewPt();
3297 void G4OpenInventorXtExaminerViewer::deleteViewPt(
char *vpName)
3301 fileIn.open(fileName.c_str());
3302 std::ofstream out(
"temporaryFile.txt");
3305 vpName = viewPtList[viewPtIdx].viewPtName;
3308 XmString vpNameStr = XmStringCreateLocalized(vpName);
3310 XmListDeleteItem(myViewPtList, vpNameStr);
3311 XmStringFree(vpNameStr);
3314 getline(fileIn, line);
3315 out << line <<
"\n";
3317 while (getline(fileIn, line)) {
3318 end = line.find_last_not_of(
' ');
3319 line = line.substr(0, end + 1);
3320 if (!strcmp(line.c_str(), vpName)) {
3321 while (line.size()) {
3322 getline(fileIn, line);
3325 while (getline(fileIn, line))
3326 out << line <<
"\n";
3328 while (line.size()) {
3329 out << line <<
"\n";
3330 getline(fileIn, line);
3337 int size = viewPtList.size();
3338 while (idx < size) {
3339 if (!strcmp(viewPtList[idx].viewPtName, vpName)) {
3340 viewPtList.erase(viewPtList.begin() + idx);
3352 int istat =
remove(fileName.c_str());
3354 char dialogName[] =
"Warning";
3358 istat = rename(
"temporaryFile.txt", fileName.c_str());
3360 char dialogName[] =
"Warning";
3364 fileOut.open(fileName.c_str(), std::ios::in);
3365 fileOut.seekp(0, std::ios::end);
3367 if (!viewPtList.size()) {
3368 curViewPtName = (
char *)
"";
3370 XtSetSensitive(nextViewPtButton, False);
3371 XtSetSensitive(prevViewPtButton, False);
3373 if (viewPtIdx >= (
int) viewPtList.size())
3383 void G4OpenInventorXtExaminerViewer::renameViewPt(
char *vpName)
3385 int idx = 0, end,
pos;
3386 int size = viewPtList.size();
3387 std::string line, newName;
3388 fileIn.open(fileName.c_str());
3391 while ((
int) newName.size() < MAX_VP_NAME)
3394 getline(fileIn, line);
3395 pos = fileIn.tellg();
3396 while (getline(fileIn, line)) {
3397 end = line.find_last_not_of(
' ');
3398 line = line.substr(0, end + 1);
3399 if (!strcmp(line.c_str(), curViewPtName)) {
3402 fileOut.seekp(0, std::ios::end);
3406 getline(fileIn, line);
3407 pos = fileIn.tellg();
3413 while (idx < size) {
3414 if (!strcmp(viewPtList[idx].viewPtName, curViewPtName)) {
3415 strcpy(viewPtList[idx].viewPtName, vpName);
3425 void G4OpenInventorXtExaminerViewer::sortViewPts(std::vector<std::string> sortedViewPts)
3428 float x, y, z,
angle;
3429 int sortIdx = 0, unsortIdx = 0;
3431 if (fileOut.is_open())
3434 fileOut.open(fileName.c_str());
3438 int size = sortedViewPts.size();
3439 while (sortIdx < size) {
3440 while (strcmp(sortedViewPts[sortIdx].c_str(),
3441 viewPtList[unsortIdx].viewPtName))
3444 std::string vpName = viewPtList[unsortIdx].viewPtName;
3446 while ((
int) vpName.size() < MAX_VP_NAME)
3448 fileOut << vpName << std::endl;
3449 viewPtList[unsortIdx].position.getValue(x, y, z);
3450 fileOut << x <<
" " << y <<
" " << z << std::endl;
3453 viewPtList[unsortIdx].orientation.getValue(axis, angle);
3454 axis.getValue(x, y, z);
3455 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3457 fileOut << viewPtList[unsortIdx].camType <<
" "
3458 << viewPtList[unsortIdx].height << std::endl;
3459 fileOut << viewPtList[unsortIdx].focalDistance <<
" ";
3461 fileOut << viewPtList[unsortIdx].nearDistance <<
" ";
3463 fileOut << viewPtList[unsortIdx].farDistance << std::endl;
3465 fileOut << viewPtList[unsortIdx].viewportMapping <<
" ";
3466 fileOut << viewPtList[unsortIdx].aspectRatio <<
"\n" << std::endl;
3484 float x, y, z,
angle;
3488 parseString<int>(viewPtIdx, token,
error);
3489 getline(fileIn, token);
3491 while (getline(fileIn, token)) {
3493 int end = token.find_last_not_of(
' ');
3494 token = token.substr(0, end + 1);
3496 char *vpName =
new char[token.size() + 1];
3497 strcpy(vpName, token.c_str());
3498 tmp.viewPtName = vpName;
3501 parseString<float>(x, token,
error);
3503 parseString<float>(y, token,
error);
3505 parseString<float>(z, token,
error);
3507 tmp.position = axis.setValue(x, y, z);
3509 parseString<float>(x, token,
error);
3511 parseString<float>(y, token,
error);
3513 parseString<float>(z, token,
error);
3517 orient.setValue(axis.setValue(x, y, z),
angle);
3518 tmp.orientation = orient.getValue();
3521 parseString<int>(camType, token,
error);
3523 tmp.camType = (CameraType) camType;
3525 parseString<float>(tmp.height, token,
error);
3527 parseString<float>(tmp.focalDistance, token,
error);
3529 parseString<float>(tmp.nearDistance, token,
error);
3531 parseString<float>(tmp.farDistance, token,
error);
3533 parseString<int>(tmp.viewportMapping, token,
error);
3535 parseString<float>(tmp.aspectRatio, token,
error);
3537 getline(fileIn, token);
3538 getline(fileIn, token);
3545 viewPtList.push_back(tmp);
3558 std::istringstream str(s);
3559 if ((str >> t).fail())
3566 void G4OpenInventorXtExaminerViewer::popUpFileSelDialog(Widget &dialog,
3567 std::string dialogName,
3568 std::string buttonLabel,
3569 XtCallbackProc cbOK)
3573 Widget parent, scrollWidget;
3574 parent = SoXt::getShellWidget(getParentWidget());
3576 if (dialog == NULL) {
3579 XmString str = XmStringCreateLocalized((
char *) buttonLabel.c_str());
3582 XtSetArg(args[n], XmNokLabelString, str); n++;
3583 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
3585 dialog = XmCreateFileSelectionDialog(parent,
3586 (
char *) dialogName.c_str(), args,
n);
3588 XtAddCallback(dialog, XmNokCallback, cbOK,
this);
3589 XtAddCallback(dialog, XmNcancelCallback, cancelFileSelDialogCB,
this);
3592 scrollWidget = XmFileSelectionBoxGetChild(dialog, XmDIALOG_DIR_LIST);
3595 scrollWidget = XmFileSelectionBoxGetChild(dialog, XmDIALOG_LIST);
3599 XtUnmanageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
3602 XtManageChild(dialog);
3608 void G4OpenInventorXtExaminerViewer::cancelFileSelDialogCB(Widget w,
3618 void G4OpenInventorXtExaminerViewer::openViewPtFileCB(Widget,
3619 XtPointer client_data,
3624 This->popUpFileSelDialog(This->openFileDialog,
"Open File",
"Load",
3625 viewPtFileSelectedCB);
3629 void G4OpenInventorXtExaminerViewer::viewPtFileSelectedCB(Widget w,
3630 XtPointer client_data,
3631 XtPointer call_data)
3635 XmFileSelectionBoxCallbackStruct *cbs =
3636 (XmFileSelectionBoxCallbackStruct *) call_data;
3640 if (!(file = (
char *) XmStringUnparse(cbs->value,
3641 XmFONTLIST_DEFAULT_TAG, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0,
3643 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::fileSelectedCB",
3644 "Internal error during file opening");
3648 This->fileIn.open(file);
3649 if (!This->fileIn.fail()) {
3651 This->cleanUpAfterPrevFile();
3653 String dialogName = (
char *)
"Error Loading File";
3654 std::string msg =
"Wrong or corrupted input file.";
3657 This->fileName = file;
3658 This->fileOut.open(This->fileName.c_str(), std::ios::in);
3659 This->fileOut.seekp(0, std::ios::end);
3661 if (!This->listsDialog)
3662 constructListsDialog(w, This, NULL);
3664 This->addViewPoints();
3666 std::string newDialogName = This->fileName.substr(
3667 This->fileName.rfind(
'/') + 1);
3668 XtVaSetValues(This->myShellDialog, XmNtitle,
3669 (
char *) newDialogName.c_str(), NULL);
3671 if (This->viewPtList.size()) {
3673 XmTextSetString(This->viewPtSelection, NULL);
3674 XtSetSensitive(This->nextViewPtButton, True);
3675 XtSetSensitive(This->prevViewPtButton, True);
3677 XtSetSensitive(This->nextViewPtButton, False);
3678 XtSetSensitive(This->prevViewPtButton, False);
3684 This->fileIn.close();
3686 String dialogName = (
char *)
"Nonexistent File";
3687 std::string msg =
"Unable to open file.";
3692 This->fileIn.clear();
3699 void G4OpenInventorXtExaminerViewer::addViewPoints()
3701 int size = viewPtList.size();
3707 viewPts = (XmString *) XtMalloc(size *
sizeof(XmString));
3708 for (
int i = 0; i < size; i++)
3709 viewPts[i] = XmStringCreateLocalized(viewPtList[i].viewPtName);
3711 XmListAddItemsUnselected(myViewPtList, viewPts, size, 1);
3713 if (viewPts != NULL) {
3714 for (
int i = 0; i < size; i++)
3715 XmStringFree(viewPts[i]);
3716 XtFree((
char *) viewPts);
3724 void G4OpenInventorXtExaminerViewer::cleanUpAfterPrevFile()
3728 setSuperimpositionEnabled(superimposition,
FALSE);
3730 currentState = GENERAL;
3731 if (fileOut.is_open())
3734 XmListDeleteAllItems(myViewPtList);
3746 XmString warningMsg;
3748 warningMsg = XmStringCreateLocalized((
char *)msg.c_str());
3751 XtSetArg(args[n], XmNmessageString, warningMsg); n++;
3752 Widget warningDialog = XmCreateWarningDialog(getParentWidget(), dialogName, args, n);
3754 XtAddCallback(warningDialog, XmNokCallback, cb,
this);
3756 XmStringFree(warningMsg);
3758 XtVaSetValues (warningDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
3759 XtUnmanageChild(XtNameToWidget(warningDialog,
"Help"));
3760 XtUnmanageChild(XtNameToWidget(warningDialog,
"Cancel"));
3762 XtManageChild(warningDialog);
3766 void G4OpenInventorXtExaminerViewer::newViewPtFileCB(Widget,
3767 XtPointer client_data,
3772 This->popUpFileSelDialog(This->newFileDialog,
"New File",
"Save",
3777 void G4OpenInventorXtExaminerViewer::createNewVPFileCB(Widget w,
3778 XtPointer client_data,
3779 XtPointer call_data)
3784 XmFileSelectionBoxCallbackStruct *cbs =
3785 (XmFileSelectionBoxCallbackStruct *) call_data;
3789 if (!(file = (
char *) XmStringUnparse(cbs->value,
3790 XmFONTLIST_DEFAULT_TAG, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0,
3792 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::createNewVPFileCB",
3793 "Internal error during file opening");
3797 This->fileName = file;
3798 fName = This->fileName.substr(This->fileName.rfind(
'/') + 1);
3799 This->fileIn.open(file);
3800 if (This->fileIn.fail()) {
3801 This->cleanUpAfterPrevFile();
3802 This->fileOut.open(file);
3803 XtSetSensitive(This->nextViewPtButton, False);
3804 XtSetSensitive(This->prevViewPtButton, False);
3805 if (This->listsDialog)
3806 closeListsDialogCB(w, This, NULL);
3807 constructListsDialog(w, This, NULL);
3809 if (This->returnToSaveVP) {
3810 This->returnToSaveVP =
false;
3811 saveViewPtCB(NULL, This, NULL);
3814 String dialogName = (
char *)
"Existing File";
3815 std::string msg =
"'" + fName +
"' already exists. Do you want to overwrite it?";
3817 This->fileIn.close();
3819 This->fileIn.clear();
3825 void G4OpenInventorXtExaminerViewer::overwriteFileCB(Widget,
3826 XtPointer client_data,
3830 This->cleanUpAfterPrevFile();
3831 XtSetSensitive(This->nextViewPtButton, False);
3832 XtSetSensitive(This->prevViewPtButton, False);
3834 XtUnmanageChild(This->newFileDialog);
3836 This->fileOut.open(This->fileName.c_str());
3838 if (This->returnToSaveVP) {
3839 This->returnToSaveVP =
false;
3840 saveViewPtCB(NULL, This, NULL);
3845 void G4OpenInventorXtExaminerViewer::loadRefCoordsDialogCB(Widget,
3846 XtPointer client_data,
3851 This->popUpFileSelDialog(This->loadRefCoordsDialog,
"Load Ref Coords",
3852 "Load", loadRefCoordsCB);
3856 void G4OpenInventorXtExaminerViewer::loadRefCoordsCB(Widget w,
3857 XtPointer client_data,
3858 XtPointer call_data)
3862 XmFileSelectionBoxCallbackStruct *cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
3867 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3868 XmCHARSET_TEXT, XmCHARSET_TEXT,
3869 NULL, 0, XmOUTPUT_ALL);
3871 std::ifstream ifs(file);
3873 This->refParticleTrajectory.clear();
3875 while(ifs >> x >> y >> z){
3876 This->refParticleTrajectory.push_back(SbVec3f(x,y,z));
3882 String dialogName = (
char *)
"Problem reading file";
3883 std::string msg =
"Problem reading file";
3894 void G4OpenInventorXtExaminerViewer::saveRefCoordsDialogCB(Widget,
3895 XtPointer client_data,
3900 if (!This->refParticleTrajectory.size()) {
3901 String dialogName = (
char *)
"No Reference Trajectory";
3902 std::string msg =
"You need to start a run or load a reference trajectory from a file";
3909 Widget parent, scrollWidget;
3910 parent = SoXt::getShellWidget(This->getParentWidget());
3912 if (This->saveRefCoordsDialog == NULL) {
3915 XmString str = XmStringCreateLocalized((
char *)
"Save");
3918 XtSetArg(args[n], XmNokLabelString, str); n++;
3919 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
3921 This->saveRefCoordsDialog = XmCreateFileSelectionDialog(parent,(
char *)
"Save Ref Coords", args, n);
3923 XtAddCallback(This->saveRefCoordsDialog, XmNokCallback, saveRefCoordsCB, This);
3924 XtAddCallback(This->saveRefCoordsDialog, XmNcancelCallback, cancelFileSelDialogCB, This);
3927 scrollWidget = XmFileSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_DIR_LIST);
3930 scrollWidget = XmFileSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_LIST);
3934 XtUnmanageChild(XmSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_HELP_BUTTON));
3940 XtManageChild(This->saveRefCoordsDialog);
3945 void G4OpenInventorXtExaminerViewer::saveRefCoordsCB(Widget w,
3946 XtPointer client_data,
3947 XtPointer call_data)
3951 XmFileSelectionBoxCallbackStruct *cbs =
3952 (XmFileSelectionBoxCallbackStruct *) call_data;
3957 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3958 XmCHARSET_TEXT, XmCHARSET_TEXT,
3959 NULL, 0, XmOUTPUT_ALL);
3961 std::ifstream ifile(file);
3966 Widget parent = This->getParentWidget();
3967 Widget confirmOverwriteDialog;
3970 confirmOverwriteDialog = XmCreateQuestionDialog (parent, (
char *)
"Confirm overwrite", args, 0);
3971 msg = XmStringCreateLocalized ((
char *)
"File exists. Overwrite?");
3972 XtVaSetValues (confirmOverwriteDialog, XmNmessageString, msg, NULL);
3977 XtVaSetValues (confirmOverwriteDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
3978 XtAddCallback (confirmOverwriteDialog, XmNokCallback, saveRefCoordsOverWriteCB, client_data);
3979 XtAddCallback (confirmOverwriteDialog, XmNcancelCallback, saveRefCoordsOverWriteCB, client_data);
3987 XtUnmanageChild(XtNameToWidget(confirmOverwriteDialog,
"Help"));
3988 XtManageChild(confirmOverwriteDialog);
3994 std::ofstream ofs(file);
3997 for(
unsigned int i=0; i < This->refParticleTrajectory.size(); ++i){
3998 This->refParticleTrajectory[i].getValue(x,y,z);
3999 ofs << x <<
" " << y <<
" " << z <<
"\n";
4005 String dialogName = (
char *)
"Error opening file";
4006 std::string msg =
"There was a problem trying to open the file '";
4019 void G4OpenInventorXtExaminerViewer::saveRefCoordsOverWriteCB(Widget w,
4020 XtPointer client_data,
4021 XtPointer call_data)
4023 XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
4026 switch (cbs->reason) {
4034 for(
unsigned int i=0; i < This->refParticleTrajectory.size(); ++i){
4035 This->refParticleTrajectory[i].getValue(x,y,z);
4036 ofs << x <<
" " << y <<
" " << z <<
"\n";
4043 String dialogName = (
char *)
"Error opening file";
4044 std::string msg =
"There was a problem trying to open the file '";
4058 XmProcessTraversal(XtNameToWidget(This->
saveRefCoordsWidget,
"Text"), XmTRAVERSE_CURRENT);
4071 void G4OpenInventorXtExaminerViewer::loadSceneGraphDialogCB(Widget,
4072 XtPointer client_data,
4077 This->popUpFileSelDialog(This->loadSceneGraphDialog,
"Load Scene Graph",
4078 "Load", loadSceneGraphCB);
4083 void G4OpenInventorXtExaminerViewer::loadSceneGraphCB(Widget w,
4084 XtPointer client_data,
4085 XtPointer call_data)
4089 XmFileSelectionBoxCallbackStruct *cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
4093 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
4094 XmCHARSET_TEXT, XmCHARSET_TEXT,
4095 NULL, 0, XmOUTPUT_ALL);
4098 if (!sceneInput.openFile(file)) {
4099 String dialogName = (
char *)
"Problem opening file";
4100 std::string msg =
"Cannot open file ";
4104 sceneInput.closeFile();
4108 This->newSceneGraph = SoDB::readAll(&sceneInput);
4109 if (This->newSceneGraph == NULL) {
4110 String dialogName = (
char *)
"Problem reading file";
4111 std::string msg =
"Problem reading file";
4117 This->setSceneGraph(This->newSceneGraph);
4124 void G4OpenInventorXtExaminerViewer::saveSceneGraphDialogCB(Widget,
4125 XtPointer client_data,
4132 Widget parent, scrollWidget;
4133 parent = SoXt::getShellWidget(This->getParentWidget());
4135 if (This->saveSceneGraphDialog == NULL) {
4138 XmString str = XmStringCreateLocalized((
char *)
"Save");
4141 XtSetArg(args[n], XmNokLabelString, str); n++;
4142 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
4144 This->saveSceneGraphDialog = XmCreateFileSelectionDialog(parent,(
char *)
"Save Scene Graph", args, n);
4146 XtAddCallback(This->saveSceneGraphDialog, XmNokCallback, saveSceneGraphCB, This);
4147 XtAddCallback(This->saveSceneGraphDialog, XmNcancelCallback, cancelFileSelDialogCB, This);
4150 scrollWidget = XmFileSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_DIR_LIST);
4153 scrollWidget = XmFileSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_LIST);
4157 XtUnmanageChild(XmSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_HELP_BUTTON));
4163 XtManageChild(This->saveSceneGraphDialog);
4169 void G4OpenInventorXtExaminerViewer::saveSceneGraphCB(Widget w,
4170 XtPointer client_data,
4171 XtPointer call_data)
4175 XmFileSelectionBoxCallbackStruct *cbs =
4176 (XmFileSelectionBoxCallbackStruct *) call_data;
4180 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
4181 XmCHARSET_TEXT, XmCHARSET_TEXT,
4182 NULL, 0, XmOUTPUT_ALL);
4184 std::ifstream ifile(file);
4189 Widget parent = This->getParentWidget();
4190 Widget confirmOverwriteDialog;
4193 confirmOverwriteDialog = XmCreateQuestionDialog (parent, (
char *)
"Confirm overwrite", args, 0);
4194 msg = XmStringCreateLocalized ((
char *)
"File exists. Overwrite?");
4195 XtVaSetValues (confirmOverwriteDialog, XmNmessageString, msg, NULL);
4200 XtVaSetValues (confirmOverwriteDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
4201 XtAddCallback (confirmOverwriteDialog, XmNokCallback, saveSceneGraphOverWriteCB, client_data);
4202 XtAddCallback (confirmOverwriteDialog, XmNcancelCallback, saveSceneGraphOverWriteCB, client_data);
4210 XtUnmanageChild(XtNameToWidget(confirmOverwriteDialog,
"Help"));
4211 XtManageChild(confirmOverwriteDialog);
4217 SoWriteAction writeAction;
4218 SoSeparator *root = (SoSeparator *) (This->getSceneGraph());
4220 SoOutput * out = writeAction.getOutput();
4222 if(out->openFile(file)){
4223 out->setBinary(
FALSE);
4224 writeAction.apply(root);
4230 String dialogName = (
char *)
"Error opening file";
4231 std::string msg =
"There was a problem trying to open the file '";
4246 void G4OpenInventorXtExaminerViewer::saveSceneGraphOverWriteCB(Widget w,
4247 XtPointer client_data,
4248 XtPointer call_data)
4250 XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
4253 switch (cbs->reason) {
4258 SoWriteAction writeAction;
4259 SoSeparator *root = (SoSeparator *) (This->getSceneGraph());
4261 SoOutput * out = writeAction.getOutput();
4263 out->setBinary(
FALSE);
4264 writeAction.apply(root);
4273 String dialogName = (
char *)
"Error opening file";
4274 std::string msg =
"There was a problem trying to open the file '";
4305 void G4OpenInventorXtExaminerViewer::loadBookmarkCB(Widget,
4306 XtPointer client_data,
4307 XtPointer call_data)
4311 XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
4313 vpName = (
char *) XmStringUnparse(cbs->item, XmFONTLIST_DEFAULT_TAG,
4314 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
4316 for (
int i = 0; i < (
int) This->viewPtList.size(); i++) {
4317 if (!strcmp(This->viewPtList[i].viewPtName, vpName)) {
4318 This->viewPtIdx = i;
4322 XmTextSetString(This->viewPtSelection, vpName);
4324 This->writeViewPtIdx();
4331 void G4OpenInventorXtExaminerViewer::deleteBookmarkCB(Widget,
4332 XtPointer client_data,
4338 vpName = XmTextGetString(This->viewPtSelection);
4340 XmString vpNameStr = XmStringCreateLocalized(vpName);
4342 if (XmListItemExists(This->myViewPtList, vpNameStr)) {
4343 XmListDeleteItem(This->myViewPtList, vpNameStr);
4344 This->deleteViewPt(vpName);
4347 XmStringFree(vpNameStr);
4348 XmTextSetString(This->viewPtSelection, NULL);
4353 void G4OpenInventorXtExaminerViewer::renameBookmarkCB(Widget,
4354 XtPointer client_data,
4357 std::string vpNameStr;
4359 int *pos_list, pos_cnt;
4362 vpName = XmTextGetString(This->viewPtSelection);
4364 if (!strlen(vpName) || !strcmp(This->curViewPtName, vpName)) {
4371 int beg = vpNameStr.find_first_not_of(
' ');
4372 int end = vpNameStr.find_last_not_of(
' ');
4373 vpNameStr = vpNameStr.substr(beg, end - beg + 1);
4374 const int nVPName = vpNameStr.size() + 1;
4375 char* vpName1 =
new char[nVPName];
4376 strncpy(vpName1, vpNameStr.c_str(), nVPName);
4378 int size = This->viewPtList.size();
4379 for (
int i = 0; i < size; i++) {
4380 if (!strcmp(vpName1, This->viewPtList[i].viewPtName)) {
4382 String dialogName = (
char *)
"Existing Viewpoint";
4383 std::string msg =
"'";
4385 msg +=
"' already exists. Choose a different name";
4393 XmString vpNameXmStr = XmStringCreateLocalized(vpName1);
4395 if (XmListGetSelectedPos(This->myViewPtList, &pos_list, &pos_cnt)) {
4396 XmListReplaceItemsPos(This->myViewPtList, &vpNameXmStr, 1, pos_list[0]);
4397 This->renameViewPt(vpName1);
4398 XtFree((
char *) pos_list);
4401 if (This->currentState == VIEWPOINT)
4402 This->scheduleRedraw();
4404 XmStringFree(vpNameXmStr);
4409 void G4OpenInventorXtExaminerViewer::sortBookmarksCB(Widget,
4410 XtPointer client_data,
4415 XmString *strList, *newStrList;
4416 std::vector<std::string> charList;
4419 if (This->viewPtList.size() < 2)
4423 XtVaGetValues(This->myViewPtList, XmNitemCount, &size, XmNitems, &strList,
4426 for (
int i = 0; i < size; i++) {
4427 vpName = (
char *) XmStringUnparse(strList[i], XmFONTLIST_DEFAULT_TAG,
4428 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
4429 charList.push_back(vpName);
4433 std::sort(charList.begin(), charList.end());
4435 newStrList = (XmString *) XtMalloc(size *
sizeof(XmString));
4436 for (
int i = 0; i < size; i++) {
4438 if (!strcmp(charList[i].c_str(), This->curViewPtName))
4439 This->viewPtIdx = i;
4440 const int nVPName = charList[i].size() + 1;
4441 char *vpName2 =
new char[nVPName];
4442 strncpy(vpName2, charList[i].c_str(), nVPName);
4443 newStrList[i] = XmStringCreateLocalized(vpName2);
4447 XmListDeleteAllItems(This->myViewPtList);
4448 XmListAddItemsUnselected(This->myViewPtList, newStrList, size, 1);
4450 This->sortViewPts(charList);
4452 if (newStrList != NULL) {
4453 for (
int i = 0; i < size; i++)
4454 XmStringFree(newStrList[i]);
4455 XtFree((
char *) newStrList);
4460 void G4OpenInventorXtExaminerViewer::evenOutRefParticlePts()
4462 if(this->refParticleTrajectory.empty())
4465 SbVec3f p1, p2, p3, dirNow, dirNxt, dir, p2_tmp, p_start, p_corner, p_nxt;
4466 float avgDistBtwPts = 0;
4467 float totalDistBtwPts = 0;
4468 std::vector<SbVec3f> newRefParticleTrajectory;
4470 int size = refParticleTrajectory.size() - 1;
4472 for (
int i = 0; i < size; i++) {
4473 p1 = refParticleTrajectory[i];
4474 p2 = refParticleTrajectory[i + 1];
4478 totalDistBtwPts += (p2 - p1).length();
4481 avgDistBtwPts = totalDistBtwPts / numOfPts;
4482 float minDistAllowed = 0.75 * avgDistBtwPts;
4488 p1 = refParticleTrajectory[i];
4489 p2 = refParticleTrajectory[i + 1];
4492 p1.getValue(x, y, z);
4494 newRefParticleTrajectory.push_back(refPoint);
4497 while ((p2 - p1).length() < minDistAllowed && j < (size - 1)) {
4500 p1 = refParticleTrajectory[j];
4501 p2 = refParticleTrajectory[j + 1];
4509 refParticleTrajectory.clear();
4510 refParticleTrajectory = newRefParticleTrajectory;
4516 void G4OpenInventorXtExaminerViewer::closeMainWindowCB(Widget,
4517 XtPointer client_data,
4523 if (This->openFileDialog)
4524 XtUnmanageChild(This->openFileDialog);
4526 if (This->newFileDialog)
4527 XtUnmanageChild(This->newFileDialog);
4529 if (This->listsDialog)
4530 closeListsDialogCB(NULL, This, NULL);
4534 void G4OpenInventorXtExaminerViewer::saveCurCamera()
4536 SoCamera *cam = getCamera();
4537 camB4Animation.viewportMapping = cam->viewportMapping.getValue();
4538 camB4Animation.position = cam->position.getValue();
4539 camB4Animation.orientation = cam->orientation.getValue();
4540 camB4Animation.aspectRatio = cam->aspectRatio.getValue();
4541 camB4Animation.nearDistance = cam->nearDistance.getValue();
4542 camB4Animation.farDistance = cam->farDistance.getValue();
4543 camB4Animation.focalDistance = cam->focalDistance.getValue();
4545 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
4546 camB4Animation.height =
4547 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
4548 camB4Animation.camType = PERSPECTIVE;
4549 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4550 camB4Animation.height =
4551 ((SoOrthographicCamera *) cam)->height.getValue();
4552 camB4Animation.camType = ORTHOGRAPHIC;
4557 void G4OpenInventorXtExaminerViewer::restoreCamera()
4559 SoCamera *cam = getCamera();
4561 cam->viewportMapping = camB4Animation.viewportMapping;
4562 cam->position = camB4Animation.position;
4563 cam->orientation = camB4Animation.orientation;
4564 cam->aspectRatio = camB4Animation.aspectRatio;
4565 cam->nearDistance = camB4Animation.nearDistance;
4566 cam->farDistance = camB4Animation.farDistance;
4567 cam->focalDistance = camB4Animation.focalDistance;
4569 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
4570 if (camB4Animation.camType == ORTHOGRAPHIC) {
4573 ((SoOrthographicCamera *) cam)->height.setValue(
4574 camB4Animation.height);
4576 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
4577 camB4Animation.height);
4578 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4579 if (camB4Animation.camType == PERSPECTIVE) {
4582 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
4583 camB4Animation.height);
4585 ((SoOrthographicCamera *) cam)->height.setValue(
4586 camB4Animation.height);
4591 void G4OpenInventorXtExaminerViewer::animateSensorRotationCB(
void *
data,
4594 SbTime curTime = SbTime::getTimeOfDay();
4596 SoTimerSensor *
s = (SoTimerSensor *) sensor;
4598 float t = float((curTime - s->getBaseTime()).getValue())
4599 / This->animateBtwPtsPeriod;
4601 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
4603 SbBool end = (t == 1.0f);
4606 This->animateSensorRotation->unschedule();
4613 This->currentState = This->prevState;
4623 void G4OpenInventorXtExaminerViewer::animateSensorCB(
void *data,
4626 SbTime curTime = SbTime::getTimeOfDay();
4628 SoCamera *cam = This->getCamera();
4629 SoTimerSensor *s = (SoTimerSensor *) sensor;
4631 float t = float((curTime - s->getBaseTime()).getValue())
4632 / This->animateBtwPtsPeriod;
4634 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
4636 SbBool end = (t == 1.0f);
4638 cam->orientation = SbRotation::slerp(This->camStartOrient, This->camEndOrient, t);
4639 cam->position = This->camStartPos + (This->camEndPos - This->camStartPos) * t;
4642 This->animateSensor->unschedule();
4644 if (This->currentState == ANIMATION) {
4645 if (This->refParticleIdx < (
int) (This->refParticleTrajectory.size() - 1))
4646 This->animateRefParticle();
4652 if (This->currentState == REVERSED_ANIMATION) {
4653 if (This->refParticleIdx >= 1)
4654 This->animateRefParticle();
4664 void G4OpenInventorXtExaminerViewer::setStartingPtForAnimation()
4666 if (SoXtExaminerViewer::isAnimating())
4670 SbVec3f p1, p2, p2_tmp, camUpV, camD, camD_tmp, leftRightAxis;
4671 float x1, y1, z1, x2, y2, z2;
4673 if (currentState == ANIMATION) {
4674 p1 = refParticleTrajectory[refParticleIdx];
4675 p2 = refParticleTrajectory[++(refParticleIdx)];
4676 }
else if (currentState == REVERSED_ANIMATION) {
4677 p2 = refParticleTrajectory[refParticleIdx];
4678 p1 = refParticleTrajectory[--(refParticleIdx)];
4679 }
else if (currentState == PAUSED_ANIMATION) {
4680 if (refParticleIdx < (
int) refParticleTrajectory.size()) {
4681 p1 = refParticleTrajectory[refParticleIdx];
4682 p2 = refParticleTrajectory[refParticleIdx + 1];
4684 p1 = refParticleTrajectory[refParticleIdx - 1];
4685 p2 = refParticleTrajectory[refParticleIdx];
4688 p1.getValue(x1, y1, z1);
4689 p2.getValue(x2, y2, z2);
4694 p2_tmp.setValue(x2, y1, z2);
4695 camD_tmp = p2_tmp - p1;
4696 camD_tmp.normalize();
4698 camUpV.setValue(0, 1, 0);
4699 rot.setValue(camD_tmp, camD);
4700 rot.multVec(camUpV, camUpV);
4702 leftRightAxis = camD.cross(camUpV);
4704 myCam->position = p1;
4705 myCam->pointAt(p2, camUpV);
4708 p1 = p1 + (up_down * camUpV) + (left_right * leftRightAxis);
4709 myCam->position = p1;
4711 int idx = refParticleIdx + pathLookahead;
4712 idx =
std::min(idx, (
int)refParticleTrajectory.size() - 1);
4713 myCam->pointAt(refParticleTrajectory[idx], camUpV);
4715 myCam->focalDistance = 0.1f;
4719 void G4OpenInventorXtExaminerViewer::gotoRefPathStart()
4721 G4OpenInventorXtExaminerViewer::gotoRefPathStartCB(NULL, (
void *)
this,
4726 void G4OpenInventorXtExaminerViewer::gotoRefPathStartCB(Widget,
4727 XtPointer client_data,
4732 if (!This->refParticleTrajectory.size()) {
4733 String dialogName = (
char *)
"No Reference Trajectory";
4734 std::string msg =
"You need to start a run or load a reference trajectory from a file";
4739 if (This->currentState == ROTATING)
4741 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
4742 || This->currentState == PAUSED_ANIMATION) {
4743 if (This->animateSensor->isScheduled())
4744 This->animateSensor->unschedule();
4745 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
4746 This->maxSpeed = 0.0f;
4747 This->scheduleRedraw();
4749 This->saveCurCamera();
4750 This->prevState = This->currentState;
4751 This->prevRefIdx = This->refParticleIdx;
4754 if (This->SoXtExaminerViewer::isAnimating())
4755 This->stopAnimating();
4758 This->left_right = 0;
4761 This->refParticleIdx = 0;
4762 This->currentState = BEAMLINE;
4763 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
4764 This->axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
4765 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
4766 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
4767 This->scheduleRedraw();
4774 This->prevParticleDir = SbVec3f(0,0,0);
4777 SbVec3f p1 = This->refParticleTrajectory[0];
4778 SbVec3f pN = This->refParticleTrajectory[This->refParticleTrajectory.size() - 1];
4779 This->distance = (pN - p1).length() / 10;
4785 void G4OpenInventorXtExaminerViewer::invertRefPathCB(Widget,
4786 XtPointer client_data,
4791 This->invertRefPath();
4795 void G4OpenInventorXtExaminerViewer::invertRefPath()
4797 std::reverse(this->refParticleTrajectory.begin(),
4798 this->refParticleTrajectory.end());
4799 this->setReferencePathZPos();
4800 this->sortElements();
4804 void G4OpenInventorXtExaminerViewer::animateRefParticleCB(Widget,
4805 XtPointer client_data,
4810 if (!This->refParticleTrajectory.size()) {
4811 This->returnToAnim =
true;
4812 String dialogName = (
char *)
"No Reference Trajectory";
4813 std::string msg =
"You need to start a run or load a reference trajectory from a file";
4818 if (!This->refParticleTrajectory.size())
4822 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
4824 This->axisSwitch->whichChild.setValue(SO_SWITCH_ALL);
4825 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
4826 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
4827 This->scheduleRedraw();
4830 SoCamera *cam = This->getCamera();
4833 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
4834 || This->currentState == ROTATING)
4837 if (This->currentState != PAUSED_ANIMATION) {
4839 This->saveCurCamera();
4840 This->prevState = This->currentState;
4841 This->prevRefIdx = This->refParticleIdx;
4843 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4844 This->toggleCameraType();
4845 cam = This->getCamera();
4848 This->refParticleIdx = 0;
4851 This->left_right = This->up_down = 0;
4853 cam->focalDistance = 0.1f;
4854 ((SoPerspectiveCamera *) cam)->heightAngle = 0.50f;
4857 This->currentState = ANIMATION;
4858 This->setStartingPtForAnimation();
4860 cam->position = (This->myCam)->
position.getValue();
4861 cam->orientation = (This->myCam)->orientation.getValue();
4862 This->animateRefParticle();
4866 void G4OpenInventorXtExaminerViewer::animateRefParticle()
4868 SoCamera *cam = getCamera();
4870 camStartPos = cam->position.getValue();
4871 camStartOrient = cam->orientation.getValue();
4873 if (currentState != BEAMLINE)
4874 setStartingPtForAnimation();
4876 camEndPos = myCam->position.getValue();
4877 camEndOrient = myCam->orientation.getValue();
4879 if (animateSensor->isScheduled())
4880 animateSensor->unschedule();
4882 animateSensor->setBaseTime(SbTime::getTimeOfDay());
4883 animateSensor->setInterval(SbTime(0.02));
4885 animateSensor->schedule();
4890 void (*callback)(
void *),
void *
object)
4892 this->escapeCallback = callback;
4893 this->examinerObject = object;
4897 void G4OpenInventorXtExaminerViewer::sceneChangeCB(
void *
userData, SoSensor *)
4901 if(This->newEvents){
4902 This->findAndSetRefPath();
4903 This->newEvents =
false;
4921 this->viewer->newEvents =
true;
#define SPEED_INDICATOR_STEP
static const char * pickext_xpm[]
void xmAddMouseEventHandler(Widget w)
static const char * wireframe_xpm[]
~G4OpenInventorXtExaminerViewer()
friend class HookEventProcState
const std::vector< const std::vector< G4AttValue > * > & GetAttValues() const
static G4double angle[DIM]
bool viewingBeforePickRef
std::string saveScenegraphFileName
Widget addMenu(std::string name)
static const char * pickref_xpm[]
void parseString(T &t, const std::string &s, bool &error)
void moveCamera(float dist=0, bool lookdown=false)
const XML_Char const XML_Char * data
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
const XML_Char int const XML_Char * value
void warningMsgDialog(std::string, String, XtCallbackProc)
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
HookEventProcState(G4OpenInventorXtExaminerViewer *)
void addButton(Widget menu, std::string name, XtCallbackProc)
static Pixmap createPixmapFromXpm(Widget button, const char **xpm, SbBool ghost=FALSE)
static const char * thisClassName
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
Widget buildWidget(Widget parent)
static PROLOG_HANDLER error
virtual SbBool processSoEvent(const SoEvent *const event)
static const char * saveViewPt_xpm[]
virtual void afterRealizeHook()
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
#define MAX_SPEED_INDICATOR
void addEscapeCallback(void(*cb)(void *), void *)
Widget saveRefCoordsWidget
static const G4double pos
const std::vector< const std::map< G4String, G4AttDef > * > & GetAttDefs() const
std::string saveRefCoordsFileName
Widget saveScenegraphWidget
virtual void createViewerButtons(Widget parent, SbPList *buttonlist)