30#ifdef G4VIS_BUILD_OIX_DRIVER
41#include <X11/keysym.h>
46#include <Xm/MessageB.h>
48#include <Xm/ToggleB.h>
49#include <Xm/CascadeB.h>
50#include <Xm/ArrowBG.h>
52#include <Xm/RowColumn.h>
54#include <Xm/SelectioB.h>
55#include <Xm/Protocols.h>
56#include <Xm/SeparatoG.h>
57#include <Xm/DialogS.h>
61#include <Xm/DrawingA.h>
63#include <Inventor/Xt/SoXt.h>
65#include <Inventor/Xt/SoXtCursor.h>
66#include <Inventor/events/SoKeyboardEvent.h>
67#include <Inventor/events/SoMouseButtonEvent.h>
68#include <Inventor/events/SoLocation2Event.h>
69#include <Inventor/nodes/SoSeparator.h>
70#include <Inventor/nodes/SoOrthographicCamera.h>
71#include <Inventor/nodes/SoPerspectiveCamera.h>
74#include <Inventor/nodes/SoLineSet.h>
75#include <Inventor/nodes/SoMaterial.h>
76#include <Inventor/errors/SoDebugError.h>
77#include <Inventor/SoPickedPoint.h>
78#include <Inventor/actions/SoWriteAction.h>
83#include <Inventor/sensors/SoTimerSensor.h>
84#include <Inventor/sensors/SoNodeSensor.h>
99#include <Inventor/nodes/SoCallback.h>
100#include <Inventor/nodes/SoSwitch.h>
101#include <Inventor/nodes/SoScale.h>
102#include <Inventor/nodes/SoTranslation.h>
103#include <Inventor/actions/SoSearchAction.h>
104#include <Inventor/actions/SoGetBoundingBoxAction.h>
106#include <Inventor/nodes/SoCoordinate3.h>
108#include <Inventor/nodes/SoText2.h>
109#include <Inventor/nodes/SoFont.h>
110#include <Inventor/nodes/SoPointSet.h>
111#include <Inventor/nodes/SoDrawStyle.h>
112#include <Inventor/nodes/SoBaseColor.h>
115#include <Inventor/nodekits/SoBaseKit.h>
118#include <Inventor/SbVec3f.h>
122static const char* thisClassName =
"G4OpenInventorXtExaminerViewer";
125#define START_STEP 0.3
126#define SPEED_INDICATOR_STEP 0.045
127#define MAX_SPEED_INDICATOR 0.81
133 const char *name, SbBool embed,
134 SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type) :
135 SoXtExaminerViewer(parent,
name, embed, flag, type,
FALSE)
138 this->constructor(
TRUE);
143 const char *name, SbBool embed,
144 SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type,
146 SoXtExaminerViewer(parent,
name, embed, flag, type,
FALSE)
148 this->constructor(build);
152void G4OpenInventorXtExaminerViewer::constructor(
const SbBool build)
154 setClassName(thisClassName);
157 this->newEvents =
false;
159 fileName =
".bookmarkFile";
161 animateSensor =
new SoTimerSensor(
162 G4OpenInventorXtExaminerViewer::animateSensorCB,
this);
163 animateSensorRotation =
new SoTimerSensor(
164 G4OpenInventorXtExaminerViewer::animateSensorRotationCB,
this);
165 animateBtwPtsPeriod = MIN_SPEED;
166 currentState = GENERAL;
167 myCam =
new SoPerspectiveCamera;
171 curViewPtName =
new char[MAX_VP_NAME + 1];
172 left_right = up_down = 0;
173 speedStep = START_STEP;
178 lshiftdown = rshiftdown =
false;
181 lctrldown = rctrldown =
false;
185 prevColorField = NULL;
188 openFileDialog = newFileDialog = listsDialog = (Widget) NULL;
189 loadRefCoordsDialog = saveRefCoordsDialog = NULL;
190 loadSceneGraphDialog = saveSceneGraphDialog = NULL;
191 myElementList = NULL;
195 newSceneGraph = NULL;
196 zcoordSetFlag =
false;
203 static const char * superimposed[] = {
204 "#Inventor V2.1 ascii",
"",
211 " OrthographicCamera ",
217 " DEF soxt->callback Callback { }",
220 " DEF soxt->translation Translation ",
222 " translation 0 0 0",
224 " DEF soxt->scale Scale ",
226 " scaleFactor 1 1 1",
228 " DEF soxt->geometry Coordinate3 ",
232 " -0.81 -0.04 0, -0.81 0 0,",
233 " -0.81 0.04 0, 0 -0.04 0,",
235 " 0.81 -0.04 0, 0.81 0 0,",
238 " 0.81 0.02 0, 0.81 -0.02 0,",
241 " 0.4 0.01 0, 0.4 -0.01 0,",
246 " DEF soxt->animSpeedOutlineSwitch Switch ",
251 " emissiveColor 0 0 0",
257 " 12, 11, 10, 9, -1",
262 " DEF soxt->axisSwitch Switch ",
281 " DEF soxt->animSpeedSwitch Switch ",
286 " emissiveColor 0 1 0",
292 " 16, 15, 14, 13, -1",
298 " DEF soxt->curInfoSwitch Switch ",
301 " DEF soxt->curInfoTrans Translation ",
303 " translation 10 20 30 ",
305 " DEF soxt->curInfoFont Font ",
307 " name defaultFont:Bold",
310 " DEF soxt->curInfoText Text2 ",
319 " DEF soxt->mouseOverTransLogName Translation ",
321 " translation 0 0 0 ",
323 " DEF soxt->mouseOverFontLogName Font ",
325 " name defaultFont:Bold",
328 " DEF soxt->mouseOverTextLogName Text2 { } ",
332 " DEF soxt->mouseOverTransSolid Translation ",
334 " translation 0 0 0 ",
336 " DEF soxt->mouseOverFontSolid Font ",
338 " name defaultFont:Bold",
341 " DEF soxt->mouseOverTextSolid Text2 { } ",
345 " DEF soxt->mouseOverTransMaterial Translation ",
347 " translation 0 0 0 ",
349 " DEF soxt->mouseOverFontMaterial Font ",
351 " name defaultFont:Bold",
354 " DEF soxt->mouseOverTextMaterial Text2 { } ",
358 " DEF soxt->mouseOverTransZPos Translation ",
360 " translation 0 0 0 ",
362 " DEF soxt->mouseOverFontZPos Font ",
364 " name defaultFont:Bold",
367 " DEF soxt->mouseOverTextZPos Text2 { } ",
373 for (i = bufsize = 0; superimposed[i]; i++)
374 bufsize += strlen(superimposed[i]) + 1;
375 char * buf =
new char[bufsize + 1];
376 for (i = bufsize = 0; superimposed[i]; i++) {
377 strcpy(buf + bufsize, superimposed[i]);
378 bufsize += strlen(superimposed[i]);
382 SoInput * input =
new SoInput;
383 input->setBuffer(buf, bufsize);
384 SbBool ok = SoDB::read(input, this->superimposition);
389 this->superimposition->ref();
391 this->sscale = (SoScale *) this->getSuperimpositionNode(
392 this->superimposition,
"soxt->scale");
393 this->stranslation = (SoTranslation *) this->getSuperimpositionNode(
394 this->superimposition,
"soxt->translation");
395 this->sgeometry = (SoCoordinate3 *) this->getSuperimpositionNode(
396 this->superimposition,
"soxt->geometry");
397 this->axisSwitch = (SoSwitch *) this->getSuperimpositionNode(
398 this->superimposition,
"soxt->axisSwitch");
399 this->animSpeedOutlineSwitch = (SoSwitch *) this->getSuperimpositionNode(
400 this->superimposition,
"soxt->animSpeedOutlineSwitch");
401 this->animSpeedSwitch = (SoSwitch *) this->getSuperimpositionNode(
402 this->superimposition,
"soxt->animSpeedSwitch");
403 this->curInfoSwitch = (SoSwitch *) this->getSuperimpositionNode(
404 this->superimposition,
"soxt->curInfoSwitch");
405 this->curInfoTrans = (SoTranslation *) this->getSuperimpositionNode(
406 this->superimposition,
"soxt->curInfoTrans");
407 this->curInfoFont = (SoFont *) this->getSuperimpositionNode(
408 this->superimposition,
"soxt->curInfoFont");
409 this->curInfoText = (SoText2 *) this->getSuperimpositionNode(
410 this->superimposition,
"soxt->curInfoText");
411 this->mouseOverTransLogName = (SoTranslation*)this->getSuperimpositionNode(
412 this->superimposition,
"soxt->mouseOverTransLogName");
413 this->mouseOverFontLogName = (SoFont *) this->getSuperimpositionNode(
414 this->superimposition,
"soxt->mouseOverFontLogName");
415 this->mouseOverTextLogName = (SoText2 *) this->getSuperimpositionNode(
416 this->superimposition,
"soxt->mouseOverTextLogName");
417 this->mouseOverTransSolid = (SoTranslation *) this->getSuperimpositionNode(
418 this->superimposition,
"soxt->mouseOverTransSolid");
419 this->mouseOverFontSolid = (SoFont *) this->getSuperimpositionNode(
420 this->superimposition,
"soxt->mouseOverFontSolid");
421 this->mouseOverTextSolid = (SoText2 *) this->getSuperimpositionNode(
422 this->superimposition,
"soxt->mouseOverTextSolid");
423 this->mouseOverTransMaterial = (SoTranslation*)this->getSuperimpositionNode(
424 this->superimposition,
"soxt->mouseOverTransMaterial");
425 this->mouseOverFontMaterial = (SoFont *) this->getSuperimpositionNode(
426 this->superimposition,
"soxt->mouseOverFontMaterial");
427 this->mouseOverTextMaterial = (SoText2 *) this->getSuperimpositionNode(
428 this->superimposition,
"soxt->mouseOverTextMaterial");
429 this->mouseOverTransZPos = (SoTranslation *) this->getSuperimpositionNode(
430 this->superimposition,
"soxt->mouseOverTransZPos");
431 this->mouseOverFontZPos = (SoFont *) this->getSuperimpositionNode(
432 this->superimposition,
"soxt->mouseOverFontZPos");
433 this->mouseOverTextZPos = (SoText2 *) this->getSuperimpositionNode(
434 this->superimposition,
"soxt->mouseOverTextZPos");
436 SoCallback * cb = (SoCallback *) this->getSuperimpositionNode(
437 this->superimposition,
"soxt->callback");
438 cb->setCallback(superimpositionCB,
this);
440 this->addSuperimposition(this->superimposition);
441 this->setSuperimpositionEnabled(this->superimposition,
FALSE);
442 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
443 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
444 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
473G4OpenInventorXtExaminerViewer::getSuperimpositionNode(SoNode *root,
477 this->searcher =
new SoSearchAction;
479 searcher->setName(SbName(name));
480 searcher->setInterest(SoSearchAction::FIRST);
481 searcher->setSearchingAll(
TRUE);
482 searcher->apply(root);
483 assert(searcher->getPath());
484 return searcher->getPath()->getTail();
488void G4OpenInventorXtExaminerViewer::superimpositionCB(
void * closure,
498void G4OpenInventorXtExaminerViewer::superimpositionEvent(SoAction * action)
501 if (!action->isOfType(SoGLRenderAction::getClassTypeId()))
503 SbViewportRegion vpRegion =
504 ((SoGLRenderAction *) action)->getViewportRegion();
505 SbVec2s viewportSize = vpRegion.getViewportSizePixels();
507 float aspect = float(viewportSize[0]) / float(viewportSize[1]);
508 float factorx = 1.0f / float(viewportSize[1]) * 220.0f;
509 float factory = factorx;
512 this->stranslation->translation.setValue(SbVec3f(0.0f, -0.4f, 0.0f));
514 this->stranslation->translation.setValue(
515 SbVec3f(0.0f, -0.4f / aspect, 0.0f));
519 if (viewportSize[0] > 500)
520 factorx *= 500.0f / 400.0f;
522 factorx *= float(viewportSize[0]) / 400.0f;
523 this->sscale->scaleFactor.setValue(SbVec3f(factorx, factory, 1.0f));
525 float xInfo, yInfo, xMouseLogName, yMouseLogName, xMouseSolid, yMouseSolid,
526 xMouseMaterial, yMouseMaterial, xMouseZPos, yMouseZPos;
530 yMouseLogName = -.75;
533 xMouseMaterial = 0.0;
534 yMouseMaterial = -.81;
540 xMouseSolid *= aspect;
541 xMouseMaterial *= aspect;
542 this->curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
543 this->mouseOverTransLogName->translation.setValue(
544 SbVec3f(xMouseLogName, yMouseLogName, 0.0));
545 this->mouseOverTransSolid->translation.setValue(
546 SbVec3f(xMouseSolid, yMouseSolid, 0.0));
547 this->mouseOverTransMaterial->translation.setValue(
548 SbVec3f(xMouseMaterial, yMouseMaterial, 0.0));
549 this->mouseOverTransZPos->translation.setValue(
550 SbVec3f(xMouseZPos, yMouseZPos, 0.0));
553 yMouseSolid /= aspect;
554 yMouseMaterial /= aspect;
555 this->curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
556 this->mouseOverTransLogName->translation.setValue(
557 SbVec3f(xMouseLogName, yMouseLogName, 0.0));
558 this->mouseOverTransSolid->translation.setValue(
559 SbVec3f(xMouseSolid, yMouseSolid, 0.0));
560 this->mouseOverTransMaterial->translation.setValue(
561 SbVec3f(xMouseMaterial, yMouseMaterial, 0.0));
562 this->mouseOverTransZPos->translation.setValue(
563 SbVec3f(xMouseZPos, yMouseZPos, 0.0));
566 if (currentState == VIEWPOINT) {
567 this->curInfoFont->size.setValue(15);
568 this->curInfoFont->name.setValue(
"defaultFont:Italic");
569 this->curInfoText->string.setValue(SbString(curViewPtName));
571 else if(currentState == GENERAL) {
572 this->curInfoFont->size.setValue(16);
573 this->curInfoFont->name.setValue(
"defaultFont:Bold");
574 this->curInfoText->string.setValue(SbString(
""));
577 if (refParticleIdx < (
int) refParticleTrajectory.size() - 1) {
578 this->curInfoFont->size.setValue(16);
579 this->curInfoFont->name.setValue(
"defaultFont:Bold");
581 sprintf(zPos,
"%7.2f [m]", refZPositions[refParticleIdx] / 1000);
582 this->curInfoText->string.setValue(SbString(zPos));
590 if (superimposition != NULL) {
591 removeSuperimposition(superimposition);
592 superimposition->unref();
593 superimposition = NULL;
595 if (animateSensor->isScheduled())
596 animateSensor->unschedule();
597 delete animateSensor;
598 delete sceneChangeSensor;
600 delete[] curViewPtName;
611 Atom WM_DELETE_WINDOW;
614 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::buildWidget",
"Error: Parent is null.");
617 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
618 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
619 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
620 XtSetArg(args[3], XmNbottomAttachment, XmATTACH_FORM);
621 Widget form = XmCreateForm(parent, (
char *)
"Form", args, 4);
624 shell = XtParent(form);
625 WM_DELETE_WINDOW = XInternAtom(XtDisplay(parent),
"WM_DELETE_WINDOW",
627 XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW,
628 (XtCallbackProc)closeMainWindowCB,
this);
630 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
631 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
632 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
633 menuBar = XmCreateMenuBar(form, (
char *)
"MenuBar", args, 3);
634 XtManageChild(menuBar);
637 this->
addButton(fileMenu,
"Open Viewpoint File...", openViewPtFileCB);
638 addButton(fileMenu,
"New Viewpoint File", newViewPtFileCB);
639 addButton(fileMenu,
"Load Ref. Coords", loadRefCoordsDialogCB);
640 addButton(fileMenu,
"Save Ref. Coords", saveRefCoordsDialogCB);
641 addButton(fileMenu,
"Load Scene Graph", loadSceneGraphDialogCB);
642 addButton(fileMenu,
"Save Scene Graph", saveSceneGraphDialogCB);
644 XmCreateSeparatorGadget(fileMenu, (
char *)
"Separator", NULL, 0));
646 Widget menu =
addMenu(
"Tools");
647 addButton(menu,
"Animate Ref. Particle", animateRefParticleCB);
648 addButton(menu,
"Go to start of Ref path", gotoRefPathStartCB);
649 addButton(menu,
"Invert Ref path", invertRefPathCB);
651 Widget viewerBase = SoXtFullViewer::buildWidget(form);
653 XtSetArg(args[0], XmNtopAttachment, XmATTACH_WIDGET);
654 XtSetArg(args[1], XmNtopWidget, menuBar);
655 XtSetArg(args[2], XmNleftAttachment, XmATTACH_FORM);
656 XtSetArg(args[3], XmNrightAttachment, XmATTACH_FORM);
657 XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM);
658 XtSetValues(viewerBase, args, 5);
668 Widget menu = XmCreatePulldownMenu(menuBar, (
char *)
name.c_str(), NULL, 0);
670 XtSetArg(args[0], XmNsubMenuId, menu);
671 Widget w = XmCreateCascadeButton(menuBar, (
char *)
name.c_str(), args, 1);
682 Widget button = XmCreatePushButton(menu, (
char *)
name.c_str(), NULL, 0);
683 XtManageChild(button);
684 XtAddCallback(button, XmNactivateCallback, cb,
this);
690 SbPList * buttonlist)
694 Widget saveViewPtButton, abbrOutputButton, pickRefPathButton;
695 Widget switchWireFrameButton;
698 SoXtExaminerViewer::createViewerButtons(parent, buttonlist);
701 Widget emptyButton = XtVaCreateManagedWidget(
"", xmPushButtonWidgetClass,
703 buttonlist->append(emptyButton);
707 XtSetArg(args[n], XmNtopPosition, 1);
n++;
708 XtSetArg(args[n], XmNbottomPosition, 2);
n++;
709 XtSetArg(args[n], XmNleftPosition, 0);
n++;
710 XtSetArg(args[n], XmNrightPosition, 1);
n++;
711 XtSetArg(args[n], XmNarrowDirection, XmARROW_LEFT);
n++;
712 XtSetArg(args[n], XmNsensitive, False);
n++;
713 prevViewPtButton = XmCreateArrowButtonGadget(parent, (
char *)
"ArrowL",
715 XtManageChild(prevViewPtButton);
716 XtAddCallback(prevViewPtButton, XmNactivateCallback,
717 G4OpenInventorXtExaminerViewer::prevViewPtCB,
this);
718 buttonlist->append(prevViewPtButton);
722 XtSetArg(args[n], XmNtopPosition, 1);
n++;
723 XtSetArg(args[n], XmNbottomPosition, 2);
n++;
724 XtSetArg(args[n], XmNleftPosition, 0);
n++;
725 XtSetArg(args[n], XmNrightPosition, 1);
n++;
726 XtSetArg(args[n], XmNarrowDirection, XmARROW_RIGHT);
n++;
727 XtSetArg(args[n], XmNsensitive, False);
n++;
728 nextViewPtButton = XmCreateArrowButtonGadget(parent, (
char *)
"ArrowR",
730 XtManageChild(nextViewPtButton);
731 XtAddCallback(nextViewPtButton, XmNactivateCallback,
732 G4OpenInventorXtExaminerViewer::nextViewPtCB,
this);
733 buttonlist->append(nextViewPtButton);
736 saveViewPtButton = XtVaCreateManagedWidget(
"Save", xmPushButtonWidgetClass,
738 XtAddCallback(saveViewPtButton, XmNactivateCallback,
739 G4OpenInventorXtExaminerViewer::saveViewPtCB,
this);
740 Pixmap saveVP, saveVP_ins;
744 saveViewPt_xpm,
TRUE);
745 XtVaSetValues(saveViewPtButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
746 saveVP, XmNselectPixmap, saveVP, XmNlabelInsensitivePixmap,
747 saveVP_ins, XmNselectInsensitivePixmap, saveVP_ins, NULL);
748 buttonlist->append(saveViewPtButton);
751 abbrOutputButton = XtVaCreateManagedWidget(
"Abbr",
752 xmToggleButtonWidgetClass, parent, XmNindicatorOn, False, NULL);
753 XtAddCallback(abbrOutputButton, XmNdisarmCallback, G4OpenInventorXtExaminerViewer::abbrOutputCB,
755 Pixmap pickextxpm, pickextxpm_ins;
760 XtVaSetValues(abbrOutputButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
761 pickextxpm, XmNselectPixmap, pickextxpm, XmNlabelInsensitivePixmap,
762 pickextxpm_ins, XmNselectInsensitivePixmap, pickextxpm_ins, NULL);
771 buttonlist->append(abbrOutputButton);
774 pickRefPathButton = XtVaCreateManagedWidget(
"Refpath", xmPushButtonWidgetClass,
776 XtAddCallback(pickRefPathButton, XmNactivateCallback,
777 G4OpenInventorXtExaminerViewer::pickRefPathCB,
this);
778 Pixmap pickrefxpm, pickrefxpm_ins;
783 XtVaSetValues(pickRefPathButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
784 pickrefxpm, XmNselectPixmap, pickrefxpm, XmNlabelInsensitivePixmap,
785 pickrefxpm_ins, XmNselectInsensitivePixmap, pickrefxpm_ins, NULL);
787 buttonlist->append(pickRefPathButton);
790 switchWireFrameButton = XtVaCreateManagedWidget(
"Wireframe",
791 xmToggleButtonWidgetClass, parent, XmNindicatorOn, False, NULL);
792 XtAddCallback(switchWireFrameButton, XmNvalueChangedCallback,
793 G4OpenInventorXtExaminerViewer::switchWireFrameCB,
this);
794 Pixmap wireframe, wireframe_ins;
798 wireframe_xpm,
TRUE);
799 XtVaSetValues(switchWireFrameButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
800 wireframe, XmNselectPixmap, wireframe, XmNlabelInsensitivePixmap,
801 wireframe_ins, XmNselectInsensitivePixmap, wireframe_ins, NULL);
802 buttonlist->append(switchWireFrameButton);
810 SoXtExaminerViewer::afterRealizeHook();
814 SoCamera *cam = getCamera();
816 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
818 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
821 ((SoOrthographicCamera *) cam)->height.getValue();
825 ((SoOrthographicCamera *) cam)->height.getValue();
828 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
830 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
836 fileIn.open(fileName.c_str());
837 if (!fileIn.fail()) {
839 String dialogName = (
char *)
"Error Loading File";
840 std::string msg =
"Wrong or corrupted input file.";
844 fileOut.open(fileName.c_str(), std::ios::in);
845 fileOut.seekp(0, std::ios::end);
846 constructListsDialog(getParentWidget(),
this, NULL);
847 if (viewPtList.size()) {
851 XtSetSensitive(nextViewPtButton, True);
852 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();
903 SbRotation rot(rotAxis,
M_PI / (2 * ROT_CNT));
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();
1012 prevPt.getValue(x,y,z);
1015 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1016 camPosNew = p2 - (
camDir*distance);
1018 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
1020 camPosNew = p2 - (
camDir*cam->focalDistance.getValue());
1024 cam->position = camPosNew;
1026 cam->focalDistance = (p2 - camPosNew).length();
1029 camPosNew.getValue(x,y,z);
1031 prevParticleDir = particleDir;
1039void G4OpenInventorXtExaminerViewer::pickingCB(
void *aThis,
1040 SoEventCallback *eventCB)
1042 SoHandleEventAction* action = eventCB->getAction();
1043 const SoPickedPoint *
pp = action->getPickedPoint();
1048 SoPath* path =
pp->getPath();
1049 SoNode* node = ((SoFullPath*)path)->getTail();
1051 if(node->getTypeId() == SoLineSet::getClassTypeId()){
1058 This->setComponentCursor(SoXtCursor(SoXtCursor::DEFAULT));
1061 SoLineSet * trajectory = (SoLineSet *)node;
1067 SoSeparator * grpNode =
1068 (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1073 int nodeIndex = grpNode->findChild(trajectory);
1076 SoCoordinate3 * coords = 0;
1080 for(
int i = 0; i < 100; ++i) {
1083 tmpNode = grpNode->getChild(nodeIndex);
1084 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()){
1086 coords = (SoCoordinate3 *)tmpNode;
1092 String dialogName = (
char *)
"No coordinates";
1093 std::string msg =
"Could not find the coordinates node"
1094 " for the picked trajectory."
1095 " Reference trajectory not set";
1101 if ((This->lshiftdown) || (This->rshiftdown))
1102 This->setReferencePath(trajectory, coords,
true);
1104 This->setReferencePath(trajectory, coords,
false);
1112 if(attHolder && attHolder->
GetAttDefs().size()) {
1114 std::string strTrajPoint =
"G4TrajectoryPoint:";
1115 std::ostringstream oss;
1116 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1121 if(oss.str().find(strTrajPoint) != std::string::npos) {
1136 G4String cls((
char*)node->getTypeId().getName().getString());
1137 G4cout <<
"SoNode : " << node
1138 <<
" SoType : " << cls
1139 <<
" name : " <<
name
1156 if(attHolder && attHolder->
GetAttDefs().size()) {
1157 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1163 G4String cls((
char*)node->getTypeId().getName().getString());
1164 G4cout <<
"SoNode : " << node
1165 <<
" SoType : " << cls
1166 <<
" name : " <<
name
1172 eventCB->setHandled();
1177void G4OpenInventorXtExaminerViewer::mouseoverCB(
void *aThis, SoEventCallback *eventCB)
1179 SoHandleEventAction* action = eventCB->getAction();
1180 const SoPickedPoint*
pp = action->getPickedPoint();
1188 const SbViewportRegion & viewportRegion = action->getViewportRegion();
1190 std::string sLogName;
1192 std::stringstream ssZPos;
1193 std::stringstream ssSolids;
1194 std::stringstream ssMaterials;
1195 SoPath * path =
pp->getPath();
1196 SoNode* node = ((SoFullPath*)path)->getTail();
1198 if(node->getTypeId() == Geant4_SoPolyhedron::getClassTypeId()) {
1200 sLogName =
"Logical Volume: ";
1203 SoGetBoundingBoxAction bAction(viewportRegion);
1204 bAction.apply((SoFullPath*)path);
1205 SbBox3f bBox = bAction.getBoundingBox();
1206 SbVec3f center = bBox.getCenter();
1207 center.getValue(x,y,z);
1208 ssZPos <<
"Pos: " << x <<
" " << y <<
" " << z;
1211 if(attHolder && attHolder->
GetAttDefs().size()) {
1213 std::vector<const std::map<G4String,G4AttDef>*> vecDefs =
1215 std::vector<const std::vector<G4AttValue>*> vecVals =
1217 for (
size_t i = 0; i < vecDefs.size(); ++i) {
1218 const std::vector<G4AttValue> * vals = vecVals[i];
1220 std::vector<G4AttValue>::const_iterator iValue;
1222 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1223 const G4String& valueName = iValue->GetName();
1224 const G4String& value = iValue->GetValue();
1226 if(valueName ==
"Solid") {
1227 if(ssSolids.str() ==
"")
1228 ssSolids <<
"Solid Name: " << value;
1230 ssSolids <<
", " << value;
1233 if(valueName ==
"Material") {
1234 if(ssMaterials.str() ==
"")
1235 ssMaterials <<
"Material Name: " << value;
1237 ssMaterials <<
", " << value;
1244 else if(node->getTypeId() == SoLineSet::getClassTypeId()) {
1247 if(attHolder && attHolder->
GetAttDefs().size()) {
1248 std::string strTrajPoint =
"G4TrajectoryPoint:";
1249 std::ostringstream oss;
1251 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1254 const std::vector<G4AttValue>* vals = attHolder->
GetAttValues()[i];
1255 std::vector<G4AttValue>::const_iterator iValue;
1256 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1257 const G4String& valueName = iValue->GetName();
1258 const G4String& value = iValue->GetValue();
1262 if (valueName ==
"PN") t1 = value;
1263 if (valueName ==
"Ch") {
1264 if (atof(value.c_str()) > 0)
1270 if (valueName ==
"PDG") {
1274 This->mouseOverTextLogName->string.setValue(t1);
1278 if (valueName ==
"EventID") t2 =
"Evt " + value;
1279 if (valueName ==
"ID") t2 +=
" Trk " + value;
1280 if (valueName ==
"PID") {
1281 t2 +=
" Prt " + value;
1282 This->mouseOverTextSolid->string.setValue(t2);
1285 if (valueName ==
"IKE") t3 =
"KE " + value;
1286 if (valueName ==
"IMom") {
1288 unsigned ipos = value.rfind(
" ");
1291 t3 +=
" P (" + value1 +
")";
1293 if (valueName ==
"IMag") {
1294 t3 +=
" " + value +
"/c";
1296 This->mouseOverTextMaterial->string.setValue(t3);
1299 if (valueName ==
"NTP") {
1300 std::ostringstream t4oss;
1301 t4oss <<
"TrjPts " << value;
1302 t4oss <<
" Pos " <<
pp->getPoint()[0] <<
" " <<
pp->getPoint()[1] <<
1303 " " <<
pp->getPoint()[2];
1304 This->mouseOverTextZPos->string.setValue(SbString(t4oss.str().c_str()));
1325 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
1326 This->scheduleRedraw();
1327 eventCB->setHandled();
1331 bool redraw =
false;
1332 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) != sLogName) {
1333 This->mouseOverTextLogName->string.setValue(SbString(sLogName.c_str()));
1336 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) != ssSolids.str()) {
1337 This->mouseOverTextSolid->string.setValue(SbString(ssSolids.str().c_str()));
1340 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) != ssMaterials.str()){
1341 This->mouseOverTextMaterial->string.setValue(SbString(ssMaterials.str().c_str()));
1344 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) != ssZPos.str()) {
1345 This->mouseOverTextZPos->string.setValue(SbString(ssZPos.str().c_str()));
1350 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
1351 This->scheduleRedraw();
1354 eventCB->setHandled();
1357 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) !=
"") {
1358 This->mouseOverTextLogName->string.setValue(SbString(
""));
1359 This->scheduleRedraw();
1361 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) !=
"") {
1362 This->mouseOverTextSolid->string.setValue(SbString(
""));
1363 This->scheduleRedraw();
1365 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) !=
"") {
1366 This->mouseOverTextMaterial->string.setValue(SbString(
""));
1367 This->scheduleRedraw();
1369 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) !=
"") {
1370 This->mouseOverTextZPos->string.setValue(SbString(
""));
1371 This->scheduleRedraw();
1378 SoCamera *cam = getCamera();
1379 const SoType type(ev->getTypeId());
1381 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
1382 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
1384 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1385 || currentState == PAUSED_ANIMATION) {
1386 switch (me->getButton()) {
1387 case SoMouseButtonEvent::BUTTON4:
1388 if (me->getState() == SoButtonEvent::DOWN) {
1389 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1391 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1392 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1395 }
else if (cam->isOfType(
1396 SoOrthographicCamera::getClassTypeId())) {
1398 ((SoOrthographicCamera *) cam)->height.getValue();
1399 ((SoOrthographicCamera *) cam)->height = height + 5;
1404 case SoMouseButtonEvent::BUTTON5:
1405 if (me->getState() == SoButtonEvent::DOWN) {
1406 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1408 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1410 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1413 }
else if (cam->isOfType(
1414 SoOrthographicCamera::getClassTypeId())) {
1416 ((SoOrthographicCamera *) cam)->height.getValue();
1418 ((SoOrthographicCamera *) cam)->height = height - 5;
1427 if (currentState == GENERAL) {
1432 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
1433 SoKeyboardEvent * ke = (SoKeyboardEvent *) ev;
1435 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
1436 switch (ke->getKey()) {
1437 case SoKeyboardEvent::LEFT_SHIFT:
1438 this->lshiftdown =
true;
1440 case SoKeyboardEvent::RIGHT_SHIFT:
1441 this->rshiftdown =
true;
1443 case SoKeyboardEvent::LEFT_CONTROL:
1444 this->lctrldown =
true;
1446 case SoKeyboardEvent::RIGHT_CONTROL:
1447 this->rctrldown =
true;
1449 case SoKeyboardEvent::SPACE:
1450 if (currentState == ANIMATION
1451 || currentState == REVERSED_ANIMATION) {
1452 beforePausing = currentState;
1453 currentState = PAUSED_ANIMATION;
1454 if (animateSensor->isScheduled())
1455 animateSensor->unschedule();
1457 }
else if (currentState == PAUSED_ANIMATION) {
1459 if ((beforePausing == ANIMATION
1461 < (
int) refParticleTrajectory.size() - 1)
1462 || (beforePausing == REVERSED_ANIMATION
1463 && refParticleIdx > 0)) {
1464 currentState = beforePausing;
1465 animateRefParticle();
1471 case SoKeyboardEvent::ESCAPE:
1472 if (currentState == ANIMATION
1473 || currentState == REVERSED_ANIMATION
1474 || currentState == PAUSED_ANIMATION) {
1476 if (animateSensor->isScheduled())
1477 animateSensor->unschedule();
1478 currentState = prevState;
1479 refParticleIdx = prevRefIdx;
1480 setSuperimpositionEnabled(superimposition,
FALSE);
1485 if (currentState == VIEWPOINT) {
1486 setSuperimpositionEnabled(superimposition,
TRUE);
1487 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
1488 animSpeedOutlineSwitch->whichChild.setValue(
1490 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1498 case SoKeyboardEvent::DELETE:
1499 if (viewPtList.size()
1500 && (currentState != ANIMATION
1501 && currentState != REVERSED_ANIMATION
1502 && currentState != PAUSED_ANIMATION)) {
1503 String dialogName = (
char *)
"Delete Viewpoint";
1504 std::string msg =
"Are you sure you want to delete current viewpoint?";
1509 case SoKeyboardEvent::LEFT_ARROW:
1510 switch (currentState) {
1512 if ((this->lshiftdown) || (this->rshiftdown)){
1513 refParticleIdx -= step;
1516 else if ((this->lctrldown) || (this->rctrldown)){
1517 if (SoXtExaminerViewer::isAnimating())
1519 prevState = currentState;
1520 currentState = ROTATING;
1521 animateBtwPtsPeriod = 0.08f;
1533 if (SoXtExaminerViewer::isAnimating())
1535 prevState = currentState;
1536 currentState = ROTATING;
1537 animateBtwPtsPeriod = 0.08f;
1552 case REVERSED_ANIMATION:
1555 case PAUSED_ANIMATION:
1557 setStartingPtForAnimation();
1558 cam->position = myCam->position;
1562 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1565 this->bottomWheelMotion(
1566 this->getBottomWheelValue() + 0.1f);
1576 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1577 "Unhandled viewer state");
1582 case SoKeyboardEvent::RIGHT_ARROW:
1583 switch(currentState){
1585 if ((this->lshiftdown) || (this->rshiftdown)){
1586 refParticleIdx += step;
1589 else if ((this->lctrldown) || (this->rctrldown)){
1590 if (SoXtExaminerViewer::isAnimating())
1592 prevState = currentState;
1593 currentState = ROTATING;
1594 animateBtwPtsPeriod = 0.08f;
1604 if (SoXtExaminerViewer::isAnimating())
1606 prevState = currentState;
1607 currentState = ROTATING;
1608 animateBtwPtsPeriod = 0.08f;
1620 case REVERSED_ANIMATION:
1623 case PAUSED_ANIMATION:
1625 setStartingPtForAnimation();
1626 cam->position = myCam->position;
1630 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1633 this->bottomWheelMotion(
1634 this->getBottomWheelValue() - 0.1f);
1643 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1644 "Unhandled viewer state");
1649 case SoKeyboardEvent::DOWN_ARROW:
1650 switch(currentState){
1653 if ((this->lshiftdown) || (this->rshiftdown)){
1654 refParticleIdx -= step;
1658 if (SoXtExaminerViewer::isAnimating())
1660 prevState = currentState;
1661 currentState = ROTATING;
1662 animateBtwPtsPeriod = 0.08f;
1675 case REVERSED_ANIMATION:
1678 case PAUSED_ANIMATION:
1680 setStartingPtForAnimation();
1681 cam->position = myCam->position;
1687 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1688 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
1697 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1698 "Unhandled viewer state");
1703 case SoKeyboardEvent::UP_ARROW:
1704 switch(currentState){
1706 if ((this->lshiftdown) || (this->rshiftdown)){
1707 refParticleIdx -= step;
1711 if (SoXtExaminerViewer::isAnimating())
1713 prevState = currentState;
1714 currentState = ROTATING;
1715 animateBtwPtsPeriod = 0.08f;
1728 case REVERSED_ANIMATION:
1731 case PAUSED_ANIMATION:
1733 setStartingPtForAnimation();
1734 cam->position = myCam->position;
1740 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1741 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
1750 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1751 "Unhandled viewer state");
1756 case SoKeyboardEvent::PAGE_UP:
1757 switch(currentState){
1759 if (step < (
int) refParticleTrajectory.size() / 5)
1764 maxSpeed += SPEED_INDICATOR_STEP;
1766 maxSpeed = MAX_SPEED_INDICATOR;
1770 case REVERSED_ANIMATION:
1771 if(!animateSensor->isScheduled()){
1772 currentState = ANIMATION;
1774 < (
int) refParticleTrajectory.size() - 1) {
1776 maxSpeed = SPEED_INDICATOR_STEP;
1778 animateRefParticle();
1782 maxSpeed += SPEED_INDICATOR_STEP;
1787 case PAUSED_ANIMATION:
1788 maxSpeed += SPEED_INDICATOR_STEP;
1790 maxSpeed = MAX_SPEED_INDICATOR;
1792 if (beforePausing == ANIMATION) {
1796 if (animateBtwPtsPeriod >= MIN_SPEED)
1797 beforePausing = ANIMATION;
1807 case SoKeyboardEvent::PAGE_DOWN:
1808 switch(currentState){
1814 if(!animateSensor->isScheduled()){
1815 currentState = REVERSED_ANIMATION;
1816 if (refParticleIdx > 1) {
1818 maxSpeed = -SPEED_INDICATOR_STEP;
1820 animateRefParticle();
1824 maxSpeed -= SPEED_INDICATOR_STEP;
1829 case REVERSED_ANIMATION:
1831 maxSpeed -= SPEED_INDICATOR_STEP;
1832 if (maxSpeed < -0.8)
1833 maxSpeed = -MAX_SPEED_INDICATOR;
1836 case PAUSED_ANIMATION:
1837 maxSpeed -= SPEED_INDICATOR_STEP;
1838 if (maxSpeed < -0.8)
1839 maxSpeed = -MAX_SPEED_INDICATOR;
1840 if (beforePausing == REVERSED_ANIMATION) {
1844 if (animateBtwPtsPeriod >= MIN_SPEED)
1845 beforePausing = REVERSED_ANIMATION;
1855 case SoKeyboardEvent::E:
1856 this->escapeCallback(this->examinerObject);
1863 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
1864 switch (ke->getKey()) {
1865 case SoKeyboardEvent::LEFT_SHIFT:
1866 this->lshiftdown =
false;
1868 case SoKeyboardEvent::RIGHT_SHIFT:
1869 this->rshiftdown =
false;
1871 case SoKeyboardEvent::LEFT_CONTROL:
1872 this->lctrldown =
false;
1874 case SoKeyboardEvent::RIGHT_CONTROL:
1875 this->rctrldown =
false;
1883 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1884 || currentState == ROTATING)
1887 return SoXtExaminerViewer::processSoEvent(ev);
1891void G4OpenInventorXtExaminerViewer::incSpeed() {
1892 if (std::ceil(animateBtwPtsPeriod * 100) >= 4) {
1893 if (speedStep > 0.08)
1897 animateBtwPtsPeriod -= speedStep;
1899 animateBtwPtsPeriod = 0.0;
1901 if (currentState != PAUSED_ANIMATION) {
1902 int lastIdx = refParticleTrajectory.size() - 1;
1903 if (refParticleIdx < lastIdx && !animateSensor->isScheduled())
1904 animateRefParticle();
1909void G4OpenInventorXtExaminerViewer::decSpeed() {
1910 animateBtwPtsPeriod += speedStep;
1911 if (animateBtwPtsPeriod < MIN_SPEED) {
1912 if (std::floor(animateBtwPtsPeriod * 100) == 12) {
1914 }
else if (animateBtwPtsPeriod > 0.12)
1917 animateBtwPtsPeriod = MIN_SPEED;
1918 speedStep = START_STEP;
1920 if (animateSensor->isScheduled())
1921 animateSensor->unschedule();
1926void G4OpenInventorXtExaminerViewer::updateSpeedIndicator(
void) {
1927 assert(this->sgeometry != NULL);
1929 SbVec3f * points = this->sgeometry->point.startEditing();
1931 if (points[10][0] == 0.0f)
1932 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
1933 if (points[14][0] == 0.0f)
1934 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
1935 points[10][0] = this->maxSpeed;
1936 points[11][0] = this->maxSpeed;
1937 points[14][0] = this->maxSpeed;
1938 points[15][0] = this->maxSpeed;
1939 this->sgeometry->point.finishEditing();
1941 if (this->maxSpeed == 0.0f) {
1942 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
1943 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1947void G4OpenInventorXtExaminerViewer::actualRedraw(
void) {
1948 switch (currentState) {
1950 case REVERSED_ANIMATION:
1951 case PAUSED_ANIMATION:
1952 updateSpeedIndicator();
1953 SoXtExaminerViewer::actualRedraw();
1956 SoXtExaminerViewer::actualRedraw();
1961void G4OpenInventorXtExaminerViewer::setReferencePath(SoLineSet *lineset, SoCoordinate3 *coords,
bool append)
2002 SbVec3f refParticlePt;
2005 this->refParticleTrajectory.clear();
2007 for(
int i = 0; i < lineset->numVertices.getNum(); ++i){
2008 for(
int j = 0; j < lineset->numVertices[i]; ++j){
2009 refParticlePt = coords->point[j];
2010 this->refParticleTrajectory.push_back(refParticlePt);
2014 this->evenOutRefParticlePts();
2015 this->setReferencePathZPos();
2016 this->sortElements();
2020void G4OpenInventorXtExaminerViewer::setReferencePathZPos()
2022 refZPositions.clear();
2023 refZPositions.push_back(0);
2025 for(
unsigned int i=0; i < this->refParticleTrajectory.size() - 1; ++i){
2026 dist = (refParticleTrajectory[i] -
2027 refParticleTrajectory[i + 1]).length();
2028 refZPositions.push_back(refZPositions[i] + dist);
2033void G4OpenInventorXtExaminerViewer::findAndSetRefPath()
2035 SoSearchAction action;
2036 action.setType(SoLineSet::getClassTypeId(),
false);
2037 action.setInterest(SoSearchAction::ALL);
2038 action.apply(this->getSceneGraph());
2040 SoPathList &pathList = action.getPaths();
2042 if(pathList.getLength() != 0){
2044 SoCoordinate3 * coords = NULL;
2045 std::vector<SoCoordinate3 *> coordvec;
2046 std::vector<SoLineSet *> linevec;
2048 bool refPathFound =
false;
2049 for(
int i = 0; i < pathList.getLength(); ++i) {
2050 SoFullPath *path = (SoFullPath *)pathList[i];
2053 for (
size_t j = 0; j < attHolder->
GetAttDefs().size(); ++j) {
2054 std::ostringstream oss;
2057 std::string findStr =
"Type of trajectory (Type): ";
2058 std::string compareValue =
"REFERENCE";
2059 size_t idx = oss.str().find(findStr);
2061 if(idx != std::string::npos) {
2062 if(oss.str().substr(idx + findStr.size(), compareValue.size()) == compareValue) {
2063 coords = this->getCoordsNode(path);
2065 refPathFound =
true;
2066 coordvec.push_back(coords);
2067 linevec.push_back((SoLineSet *)path->getTail());
2073 findStr =
"Track ID (ID): ";
2074 idx = oss.str().find(findStr);
2075 if(idx != std::string::npos) {
2077 std::string tmpstr = oss.str().substr(idx + findStr.size(),1);
2078 std::istringstream
buffer(tmpstr);
2086 char nextChar = oss.str().at(idx+findStr.size()+1);
2089 if(std::isdigit(nextChar))
2093 coords = this->getCoordsNode(path);
2095 coordvec.push_back(coords);
2096 linevec.push_back((SoLineSet *)path->getTail());
2112 if(coordvec.empty())
2117 this->setReferencePath(linevec.back(), coordvec.back());
2123 float longestLength = 0.0;
2125 for(
unsigned int i=0;i < linevec.size(); ++i){
2128 std::vector<SbVec3f> trajectory;
2130 for(
int j=0; j < linevec[i]->numVertices.getNum(); ++j){
2132 for(
int k=0; k < linevec[i]->numVertices[j]; ++k){
2133 trajectory.push_back(coordvec[i]->point[k]);
2138 float tmpLength=0.0;
2139 for(
unsigned int j=0; j < trajectory.size() - 1; ++j){
2140 tmpLength += (trajectory[j] - trajectory[j + 1]).length();
2143 if(tmpLength > longestLength){
2145 longestLength = tmpLength;
2150 this->setReferencePath(linevec[longestIdx], coordvec[longestIdx]);
2155SoCoordinate3 * G4OpenInventorXtExaminerViewer::getCoordsNode(SoFullPath *path)
2157 SoLineSet *trajectory = (SoLineSet *)path->getTail();
2158 SoSeparator * grpNode = (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
2159 int nodeIndex = grpNode->findChild(trajectory);
2164 for(
int i = 0; i < 100; ++i){
2167 tmpNode = grpNode->getChild(nodeIndex);
2168 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()){
2170 return (SoCoordinate3 *)tmpNode;
2179void G4OpenInventorXtExaminerViewer::getSceneElements()
2181 std::string field, eltName;
2183 std::map<std::string, int> duplicates;
2184 std::map<std::string, int> sceneElts;
2185 SoSearchAction search;
2187 SoGroup *root = (SoGroup *)getSceneManager()->getSceneGraph();
2189 SoBaseKit::setSearchingChildren(
TRUE);
2192 search.setSearchingAll(
TRUE);
2193 search.setInterest(SoSearchAction::ALL);
2194 search.setType(Geant4_SoPolyhedron::getClassTypeId(), 0);
2197 SoPathList &pl = search.getPaths();
2201 for(
int i = 0; i < pl.getLength(); i++) {
2202 SoFullPath *path = (SoFullPath *)pl[i];
2204 eltName = node->getName();
2205 if(duplicates.count(eltName))
2206 duplicates[eltName]++;
2208 duplicates[eltName] = 1;
2211 for(
int i = 0; i < pl.getLength(); i++) {
2213 std::stringstream ssCount;
2214 SoFullPath *path = (SoFullPath *)pl[i];
2216 eltName = node->getName();
2218 if(duplicates[eltName] == 1)
2221 if(sceneElts.count(eltName))
2222 sceneElts[eltName]++;
2224 sceneElts[eltName] = 1;
2226 ssCount << sceneElts[eltName];
2230 field += ssCount.str();
2232 SoGetBoundingBoxAction bAction(getViewportRegion());
2233 bAction.apply(path);
2234 SbBox3f bBox = bAction.getBoundingBox();
2236 SbVec3f centr = bBox.getCenter();
2237 centr.getValue(x,y,z);
2240 sceneElement el = { field, path, centr, 0.0 };
2241 this->sceneElements.push_back(el);
2246float G4OpenInventorXtExaminerViewer::sqrlen(
const SbVec3f &a)
2250 return x*x + y*y + z*z;
2254void G4OpenInventorXtExaminerViewer::distanceToTrajectory(
const SbVec3f &q,
2256 SbVec3f &closestPoint,
2291 const size_t count = this->refParticleTrajectory.size();
2294 SbVec3f b = this->refParticleTrajectory[0];
2295 SbVec3f dbq = b - q;
2296 float sqrDist = sqrlen(dbq);
2299 for (
size_t i = 1; i < count; ++i) {
2300 const SbVec3f a = b;
2301 const SbVec3f daq = dbq;
2302 b = this->refParticleTrajectory[i];
2304 const SbVec3f dab = a - b;
2306 float dab_x, dab_y, dab_z;
2307 dab.getValue(dab_x,dab_y,dab_z);
2308 float daq_x, daq_y, daq_z;
2309 daq.getValue(daq_x, daq_y, daq_z);
2310 float dbq_x, dbq_y, dbq_z;
2311 dbq.getValue(dbq_x, dbq_y, dbq_z);
2313 const float inv_sqrlen = 1./sqrlen(dab);
2314 const float t = (dab_x*daq_x + dab_y*daq_y + dab_z*daq_z)*inv_sqrlen;
2325 current_dist = daq_x*daq_x + daq_y*daq_y + daq_z*daq_z
2326 - t*(daq_x*dab_x + daq_y*dab_y + daq_z*dab_z)
2327 + t*t*(dab_x*dab_x + dab_y*dab_y + dab_z*dab_z);
2332 current_dist = sqrlen(dbq);
2335 if (current_dist < sqrDist){
2336 sqrDist = current_dist;
2337 closestPoint = a + t*(b-a);
2342 dist = std::sqrt(sqrDist);
2346void G4OpenInventorXtExaminerViewer::sortElements()
2348 if(this->refParticleTrajectory.empty())
2351 float * trajLength =
new float[this->refParticleTrajectory.size()];
2352 typedef std::map<elementForSorting, sceneElement> sortedMap;
2358 std::vector<SbVec3f>::iterator itRef = this->refParticleTrajectory.begin();
2361 trajLength[trajIndex] = 0.0;
2364 for(; itRef != this->refParticleTrajectory.end(); ++itRef, ++trajIndex){
2365 trajLength[trajIndex] = trajLength[trajIndex-1] + (*itRef - prevPoint).length();
2373 SoGetBoundingBoxAction bAction(this->getViewportRegion());
2374 SbVec3f elementCoord;
2375 std::vector<sceneElement>::iterator itEl;
2377 elementForSorting el;
2378 for(itEl = this->sceneElements.begin(), elementIndex = 0;
2379 itEl != this->sceneElements.end(); ++itEl, ++elementIndex){
2380 bAction.apply(itEl->path);
2383 elementCoord = itEl->center;
2392 distanceToTrajectory(elementCoord, el.smallestDistance, el.closestPoint, index);
2393 itEl->closestPointZCoord = el.closestPointZCoord = trajLength[index];
2394 el.distanceToBeamlineStart = (itEl->center - this->refParticleTrajectory[0]).length();
2401 sorted.insert(std::make_pair(el,*itEl));
2405 this->sceneElements.clear();
2407 sortedMap::iterator itSorted = sorted.begin();
2408 for(; itSorted != sorted.end(); itSorted++)
2409 this->sceneElements.push_back(itSorted->second);
2411 this->zcoordSetFlag =
true;
2414 Widget formTop = XtNameToWidget(this->listsDialog,
"FormTop");
2415 Widget formTopRight = XtNameToWidget(formTop,
"FormTopRight");
2417 this->createElementsList(formTopRight);
2419 delete[] trajLength;
2423void G4OpenInventorXtExaminerViewer::createElementsList(Widget formTopRight)
2425 if(this->myElementList != NULL)
2426 XtUnmanageChild(this->myElementList);
2428 int size = this->sceneElements.size();
2429 XmString *elements = (XmString *) XtMalloc(size *
sizeof(XmString));
2431 std::vector<sceneElement>::const_iterator it;
2433 std::stringstream ss;
2434 for(it=this->sceneElements.begin(); it!=this->sceneElements.end(); ++it) {
2437 ss <<
" [" << it->closestPointZCoord <<
"]";
2438 elements[count] = XmStringCreateLocalized((
char *)ss.str().c_str());
2449 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2451 labelRight = XmCreateLabelGadget(formTopRight, (
char*)
"Element [S mm]",
2453 XtManageChild(labelRight);
2457 XtSetArg(args[n], XmNvisibleItemCount, 7);
n++;
2458 XtSetArg(args[n], XmNitemCount, size);
n++;
2459 XtSetArg(args[n], XmNitems, elements);
n++;
2460 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2461 XtSetArg(args[n], XmNtopWidget, labelRight);
n++;
2462 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2463 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2465 XtSetArg(args[n], XmNwidth, 240);
n++;
2469 this->myElementList = XmCreateScrolledList(formTopRight, (
char *)
"ListRight", args, n);
2471 XtAddCallback(this->myElementList, XmNbrowseSelectionCallback,
2472 (XtCallbackProc) lookAtSceneElementCB,
this);
2474 XtManageChild(this->myElementList);
2476 if (elements != NULL) {
2477 for (
int i = 0; i < size; i++)
2478 XmStringFree(elements[i]);
2479 XtFree((
char *) elements);
2487void G4OpenInventorXtExaminerViewer::constructListsDialog(Widget w,
2488 XtPointer client_data,
2493 if (This->listsDialog) {
2497 if (This->currentState == ANIMATION || This->currentState == PAUSED_ANIMATION) {
2498 if (This->animateSensor->isScheduled())
2499 This->animateSensor->unschedule();
2500 This->refParticleIdx = This->prevRefIdx;
2501 This->restoreCamera();
2502 This->currentState = This->prevState;
2506 This->refParticleIdx = 0;
2507 if (This->refParticleTrajectory.size()){
2508 This->prevPt = This->refParticleTrajectory[0];
2511 This->getSceneElements();
2515 Atom WM_DELETE_WINDOW;
2527 std::string dialogNameStr = This->fileName.substr(This->fileName.rfind(
'/') + 1);
2528 const int nDialog = dialogNameStr.size() + 1;
2529 char *dialogName =
new char[nDialog];
2530 strncpy(dialogName, dialogNameStr.c_str(), nDialog);
2533 XtSetArg(args[n], XmNx, 610);
n++;
2534 This->myShellDialog = XmCreateDialogShell(topShell, dialogName, args, n);
2536 delete[] dialogName;
2537 WM_DELETE_WINDOW = XInternAtom(XtDisplay(w),
"WM_DELETE_WINDOW", False);
2538 XmAddWMProtocolCallback(This->myShellDialog, WM_DELETE_WINDOW,
2539 (XtCallbackProc)closeListsDialogCB, This);
2543 XtSetArg(args[n], XmNsashWidth, 1);
n++;
2544 XtSetArg(args[n], XmNsashHeight, 1);
n++;
2545 XtSetArg(args[n], XmNseparatorOn, False);
n++;
2547 This->listsDialog = XmCreatePanedWindow(This->myShellDialog, (
char *)
"MainPane",
2555 Widget formTop = XmCreateForm(This->listsDialog, (
char *)
"FormTop", args, n);
2558 XtSetArg(args[n], XmNmarginWidth, 8);
n++;
2559 XtSetArg(args[n], XmNmarginHeight, 8);
n++;
2560 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2561 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2562 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2563 Widget formTopRight = XmCreateForm(formTop, (
char *)
"FormTopRight", args,
2567 XtSetArg(args[n], XmNmarginWidth, 8);
n++;
2568 XtSetArg(args[n], XmNmarginHeight, 8);
n++;
2569 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2570 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2571 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET);
n++;
2572 XtSetArg(args[n], XmNrightWidget, formTopRight);
n++;
2573 XtSetArg(args[n], XmNrightOffset, 10);
n++;
2574 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2575 Widget formTopLeft = XmCreateForm(formTop, (
char *)
"FormTopLeft", args, n);
2579 This->createElementsList(formTopRight);
2580 XtManageChild(formTopRight);
2586 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2587 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2588 Widget labelLeft = XmCreateLabelGadget(formTopLeft, (
char *)
"ViewPoints",
2590 XtManageChild(labelLeft);
2594 XtSetArg(args[n], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE);
n++;
2595 XtSetArg(args[n], XmNvisibleItemCount, 7);
n++;
2597 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2598 XtSetArg(args[n], XmNtopWidget, labelLeft);
n++;
2599 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET);
n++;
2600 XtSetArg(args[n], XmNrightWidget, This->myElementList);
n++;
2601 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2602 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2604 XtSetArg(args[n], XmNwidth, 160);
n++;
2607 This->myViewPtList = XmCreateScrolledList(formTopLeft, (
char *)
"ListLeft",
2609 if (This->viewPtList.size())
2610 This->addViewPoints();
2611 XtAddCallback(This->myViewPtList, XmNbrowseSelectionCallback,
2612 (XtCallbackProc) loadBookmarkCB, This);
2615 XtManageChild(This->myViewPtList);
2617 XtManageChild(formTopLeft);
2619 XtManageChild(formTop);
2623 XtSetArg(args[n], XmNmarginWidth, 6);
n++;
2626 Widget formMiddle = XmCreateForm(This->listsDialog, (
char *)
"MiddleForm", args, n);
2630 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2631 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2632 XtSetArg(args[n], XmNtopWidget, This->myViewPtList);
n++;
2633 Widget label = XmCreateLabelGadget(formMiddle, (
char *)
"Selection", args,
2635 XtManageChild(label);
2639 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2640 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2641 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2642 XtSetArg(args[n], XmNtopWidget, label);
n++;
2643 XtSetArg(args[n], XmNtopOffset, 3);
n++;
2644 XtSetArg(args[n], XmNmaxLength, This->MAX_VP_NAME);
n++;
2645 This->viewPtSelection = XmCreateText(formMiddle, (
char *)
"Txt", args, n);
2646 XtManageChild(This->viewPtSelection);
2648 Dimension h1, h2, h;
2649 XtVaGetValues(label, XmNheight, &h1, NULL);
2650 XtVaGetValues(This->viewPtSelection, XmNheight, &h2, NULL);
2652 h = (Dimension) (1.1 * (h1 + h2));
2654 XtVaSetValues(formMiddle, XmNpaneMaximum, h, XmNpaneMinimum, h, NULL);
2655 XtManageChild(formMiddle);
2660 XtSetArg(args[n], XmNfractionBase, 4);
n++;
2661 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2662 XtSetArg(args[n], XmNtopWidget, This->viewPtSelection);
n++;
2665 Widget formAction = XmCreateForm(This->listsDialog, (
char *)
"ActionForm", args, n);
2668 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2669 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2670 XtSetArg(args[n], XmNtopOffset, 3);
n++;
2671 XtSetArg(args[n], XmNbottomOffset, 5);
n++;
2672 Widget separator = XmCreateSeparatorGadget(formAction, (
char *)
"Sep", args, n);
2674 XtManageChild(separator);
2676 Widget button = XmCreatePushButton(formAction, (
char *)
"Delete", NULL, 0);
2677 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2678 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2679 XmATTACH_POSITION, XmNleftPosition, 0, XmNrightAttachment,
2680 XmATTACH_POSITION, XmNrightPosition, 1,
2681 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2684 XtAddCallback(button, XmNactivateCallback,
2685 (XtCallbackProc) deleteBookmarkCB, This);
2686 XtManageChild(button);
2688 button = XmCreatePushButton(formAction, (
char *)
"Rename", NULL, 0);
2689 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2690 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2691 XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment,
2692 XmATTACH_POSITION, XmNrightPosition, 2,
2693 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2696 XtAddCallback(button, XmNactivateCallback,
2697 (XtCallbackProc) renameBookmarkCB, This);
2698 XtManageChild(button);
2700 button = XmCreatePushButton(formAction, (
char *)
"Sort", NULL, 0);
2701 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2702 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2703 XmATTACH_POSITION, XmNleftPosition, 2, XmNrightAttachment,
2704 XmATTACH_POSITION, XmNrightPosition, 3,
2705 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2708 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc) sortBookmarksCB, This);
2709 XtManageChild(button);
2711 button = XmCreatePushButton(formAction, (
char *)
"Close", NULL, 0);
2712 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2713 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2714 XmATTACH_POSITION, XmNleftPosition, 3, XmNrightAttachment,
2715 XmATTACH_POSITION, XmNrightPosition, 4,
2716 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2719 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc) closeListsDialogCB, This);
2720 XtManageChild(button);
2722 XtManageChild(formAction);
2723 XtVaGetValues(button, XmNheight, &h1, NULL);
2724 XtVaSetValues(formAction, XmNpaneMaximum, h1, XmNpaneMinimum, h1, NULL);
2726 XtManageChild(This->listsDialog);
2734void G4OpenInventorXtExaminerViewer::lookAtSceneElementCB(Widget,
2735 XtPointer client_data,
2736 XtPointer call_data)
2739 std::string elementField;
2741 SoCamera * cam = This->getCamera();
2743 if (This->SoXtExaminerViewer::isAnimating())
2744 This->stopAnimating();
2746 XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
2748 value = (
char *) XmStringUnparse(cbs->item, XmFONTLIST_DEFAULT_TAG,
2749 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
2750 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
2751 || This->currentState == PAUSED_ANIMATION ) {
2752 if (This->animateSensor->isScheduled())
2753 This->animateSensor->unschedule();
2754 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
2755 This->maxSpeed = 0.0f;
2756 This->scheduleRedraw();
2757 This->restoreCamera();
2758 This->currentState = This->prevState;
2759 }
else if (This->currentState == VIEWPOINT)
2760 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
2762 elementField = value;
2764 int idx = elementField.find_last_of(
"[");
2766 idx = elementField.size();
2772 SoSearchAction search;
2773 SoNode *root = This->getSceneManager()->getSceneGraph();
2774 int counter, idxUnderscore = elementField.find_last_of(
"_");
2776 This->
parseString<
int>(counter, elementField.substr(idxUnderscore + 1, idx), error);
2778 SoBaseKit::setSearchingChildren(
TRUE);
2780 search.setSearchingAll(
TRUE);
2783 This->
curEltName = elementField.substr(0, idx);
2787 path = (SoFullPath *)search.getPath();
2790 This->
curEltName = elementField.substr(0, idxUnderscore);
2791 search.setInterest(SoSearchAction::ALL);
2795 SoPathList &pl = search.getPaths();
2796 path = (SoFullPath *)pl[counter - 1];
2801 if ((idx > 0) && (path)) {
2803 if(!This->refParticleTrajectory.empty()){
2805 SoGetBoundingBoxAction bAction(This->getViewportRegion());
2806 bAction.apply(path);
2807 SbBox3f bBox = bAction.getBoundingBox();
2808 SbVec3f elementCoord = bBox.getCenter();
2810 This->refParticleIdx = 0;
2813 float absLengthNow, absLengthMin;
2814 int maxIdx = This->refParticleTrajectory.size() - 2;
2818 p = This->refParticleTrajectory[This->refParticleIdx];
2819 absLengthMin = (p - elementCoord).length();
2820 This->refParticleIdx++;
2823 while (This->refParticleIdx < maxIdx) {
2824 p = This->refParticleTrajectory[This->refParticleIdx];
2825 absLengthNow = (p - elementCoord).length();
2827 if (absLengthNow < absLengthMin) {
2828 absLengthMin = absLengthNow;
2829 targetIdx = This->refParticleIdx;
2831 This->refParticleIdx++;
2834 if (This->currentState != BEAMLINE) {
2836 This->currentState = BEAMLINE;
2837 This->prevParticleDir = SbVec3f(0,0,0);
2839 p1 = This->prevPt = This->refParticleTrajectory[0];
2840 pN = This->refParticleTrajectory[This->refParticleTrajectory.size() - 1];
2841 This->distance = (pN - p1).length() / 10;
2853 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2854 ((SoPerspectiveCamera*)cam)->heightAngle.setValue(This->defaultHeightAngle);
2857 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2858 This->distance = (This->prevPt - cam->position.getValue()).length();
2860 This->refParticleIdx = targetIdx;
2863 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
2864 This->axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2865 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2866 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2867 This->scheduleRedraw();
2876 This->offsetFromCenter.setValue(0, 0, 1);
2877 This->distance = 50;
2878 This->upVector.setValue(0, 1, 0);
2880 cam->viewAll(path, This->getViewportRegion());
2884 XmTextSetString(This->viewPtSelection, NULL);
2890void G4OpenInventorXtExaminerViewer::closeListsDialogCB(Widget,
2891 XtPointer client_data,
2896 This->sceneElements.clear();
2897 This->refParticleTrajectory.clear();
2899 This->currentState = GENERAL;
2900 XtDestroyWidget(This->myShellDialog);
2901 This->listsDialog = NULL;
2905void G4OpenInventorXtExaminerViewer::prevViewPtCB(Widget, XtPointer client_data,
2909 if (This->viewPtIdx == 0)
2910 This->viewPtIdx = This->viewPtList.size() - 1;
2914 This->writeViewPtIdx();
2919void G4OpenInventorXtExaminerViewer::nextViewPtCB(Widget, XtPointer client_data,
2923 if (This->viewPtIdx >= (
int) This->viewPtList.size() - 1)
2924 This->viewPtIdx = 0;
2928 This->writeViewPtIdx();
2935void G4OpenInventorXtExaminerViewer::writeViewPtIdx()
2938 std::stringstream out;
2941 fileOut.seekp(0, std::ios::beg);
2943 while ((
int) idxStr.length() < MAX_VP_IDX) {
2947 fileOut << idxStr <<
"\n";
2949 fileOut.seekp(0, std::ios::end);
2955void G4OpenInventorXtExaminerViewer::setViewPt()
2957 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
2958 || currentState == ROTATING) {
2960 if (animateSensor->isScheduled())
2961 animateSensor->unschedule();
2962 setSuperimpositionEnabled(superimposition,
FALSE);
2967 SoCamera * camera = getCamera();
2968 if (camera == NULL) {
2969 String dialogName = (
char *)
"Missing Camera Node";
2970 std::string msg =
"Camera is null. Unable to set the viewpoint.";
2975 if (!viewPtList.size()) {
2976 String dialogName = (
char *)
"Missing Viewpoints";
2977 std::string msg =
"There are no viewpoints to load.";
2982 if (SoXtExaminerViewer::isAnimating())
2985 if (currentState != VIEWPOINT) {
2986 currentState = VIEWPOINT;
2988 setSuperimpositionEnabled(superimposition,
TRUE);
2989 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2990 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2991 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2997 curViewPtName = viewPtList[viewPtIdx].viewPtName;
2998 camera->viewportMapping = viewPtList[viewPtIdx].viewportMapping;
2999 camera->position = viewPtList[viewPtIdx].position;
3000 camera->orientation = viewPtList[viewPtIdx].orientation;
3001 camera->aspectRatio = viewPtList[viewPtIdx].aspectRatio;
3002 camera->nearDistance = viewPtList[viewPtIdx].nearDistance;
3003 camera->farDistance = viewPtList[viewPtIdx].farDistance;
3004 camera->focalDistance = viewPtList[viewPtIdx].focalDistance;
3007 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3008 if (viewPtList[viewPtIdx].camType == ORTHOGRAPHIC) {
3010 camera = getCamera();
3011 ((SoOrthographicCamera *) camera)->height.setValue(
3012 viewPtList[viewPtIdx].height);
3014 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3015 viewPtList[viewPtIdx].height);
3016 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3017 if (viewPtList[viewPtIdx].camType == PERSPECTIVE) {
3019 camera = getCamera();
3020 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3021 viewPtList[viewPtIdx].height);
3023 ((SoOrthographicCamera *) camera)->height.setValue(
3024 viewPtList[viewPtIdx].height);
3026 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::setViewPt",
3027 "Only Perspective and Orthographic cameras are supported.");
3036void G4OpenInventorXtExaminerViewer::saveViewPtCB(Widget w,
3037 XtPointer client_data,
3042 if (This->fileName.empty()) {
3043 newViewPtFileCB(w, This, NULL);
3044 This->returnToSaveVP =
true;
3050 Widget nameViewPtDialog;
3051 Widget parent = This->getParentWidget();
3052 XmString label = XmStringCreateLocalized((
char *)
"Name the viewpoint:");
3054 XtSetArg(args[n], XmNselectionLabelString, label);
n++;
3056 XtSetArg(args[n], XmNautoUnmanage, False);
n++;
3058 XtSetArg(args[n], XmNtitle,
"Save Bookmark");
n++;
3059 nameViewPtDialog = XmCreatePromptDialog(parent, String(
"Save Bookmark"),
3062 XmStringFree(label);
3063 XtAddCallback(nameViewPtDialog, XmNokCallback, getViewPtNameCB, This);
3064 XtAddCallback(nameViewPtDialog, XmNcancelCallback,
3065 getViewPtNameCancelCB, This);
3069 Widget text = XtNameToWidget(nameViewPtDialog,
"Text");
3070 XtVaSetValues(text, XmNmaxLength, This->MAX_VP_NAME, NULL);
3071 std::string autoName =
"";
3073 autoName = This->viewPtAutoName();
3076 XmTextSetString(text, (
char *) autoName.c_str());
3077 XmTextSetInsertionPosition(text, autoName.length());
3079 XtUnmanageChild(XtNameToWidget(nameViewPtDialog,
"Help"));
3080 XtManageChild(nameViewPtDialog);
3084std::string G4OpenInventorXtExaminerViewer::viewPtAutoName()
3087 std::stringstream sstream;
3088 std::vector<int> existingViewPts;
3092 for (
unsigned int i = 0; i < this->viewPtList.size(); ++i) {
3093 viewPt = this->viewPtList[i].viewPtName;
3094 if (viewPt.find(
"viewpoint_") != std::string::npos) {
3095 tmp = atoi(viewPt.substr(10).c_str());
3098 if (!viewPt.compare(
"viewpoint_0"))
3099 existingViewPts.push_back(0);
3101 existingViewPts.push_back(tmp);
3109 if (existingViewPts.size() > 0) {
3112 if (std::find(existingViewPts.begin(), existingViewPts.end(), vpNum)
3113 == existingViewPts.end()) {
3114 sstream <<
"viewpoint_" << vpNum;
3115 return sstream.str();
3120 return "viewpoint_0";
3126void G4OpenInventorXtExaminerViewer::abbrOutputCB(Widget,
3127 XtPointer client_data,
3137void G4OpenInventorXtExaminerViewer::pickRefPathCB(Widget,
3138 XtPointer client_data,
3145 if(This->isViewing())
3146 This->setViewing(
false);
3147 This->setComponentCursor(SoXtCursor(SoXtCursor::CROSSHAIR));
3152void G4OpenInventorXtExaminerViewer::switchWireFrameCB(Widget w,
3153 XtPointer client_data,
3159 if (XmToggleButtonGetState(w)) {
3160 This->setDrawStyle(SoXtViewer::STILL, SoXtViewer::VIEW_LINE);
3161 This->setDrawStyle(SoXtViewer::INTERACTIVE, SoXtViewer::VIEW_LINE);
3163 This->setDrawStyle(SoXtViewer::STILL, SoXtViewer::VIEW_AS_IS);
3164 This->setDrawStyle(SoXtViewer::INTERACTIVE,
3165 SoXtViewer::VIEW_SAME_AS_STILL);
3172void G4OpenInventorXtExaminerViewer::getViewPtNameCB(Widget w,
3173 XtPointer client_data,
3174 XtPointer call_data)
3177 std::string strName;
3179 XmSelectionBoxCallbackStruct *cbs =
3180 (XmSelectionBoxCallbackStruct *) call_data;
3181 XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &name);
3194 int beg = strName.find_first_not_of(
' ');
3195 int end = strName.find_last_not_of(
' ');
3196 strName = strName.substr(beg, end - beg + 1);
3198 bool nameExists =
false;
3199 int size = This->viewPtList.size();
3200 for (
int i = 0; i < size; i++) {
3201 if (!strcmp(This->viewPtList[i].viewPtName, strName.c_str())) {
3208 const int nVPName = This->MAX_VP_NAME + 1;
3209 name =
new char[nVPName];
3210 strncpy(name, strName.c_str(), nVPName);
3211 if (This->viewPtIdx == -1)
3212 This->viewPtIdx = 0;
3213 This->saveViewPt(name);
3214 if (This->listsDialog) {
3215 XmListAddItemUnselected(This->myViewPtList, cbs->value, 0);
3220 String dialogName = (
char *)
"Existing Viewpoint";
3221 std::string msg =
"The viewpoint already exists.";
3227void G4OpenInventorXtExaminerViewer::getViewPtNameCancelCB(Widget w,
3237void G4OpenInventorXtExaminerViewer::saveViewPt(
char *name)
3241 float x, y, z, angle;
3242 SoCamera * camera = getCamera();
3244 if (viewPtList.size() == 0) {
3246 XtSetSensitive(nextViewPtButton, True);
3247 XtSetSensitive(prevViewPtButton, True);
3250 tmp.viewPtName =
name;
3251 tmp.viewportMapping = camera->viewportMapping.getValue();
3252 tmp.position = camera->position.getValue();
3253 tmp.orientation = camera->orientation.getValue();
3254 tmp.aspectRatio = camera->aspectRatio.getValue();
3255 tmp.nearDistance = camera->nearDistance.getValue();
3256 tmp.farDistance = camera->farDistance.getValue();
3257 tmp.focalDistance = camera->focalDistance.getValue();
3260 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3261 tmp.height = ((SoPerspectiveCamera *) camera)->heightAngle.getValue();
3262 tmp.camType = PERSPECTIVE;
3263 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3264 tmp.height = ((SoOrthographicCamera *) camera)->height.getValue();
3265 tmp.camType = ORTHOGRAPHIC;
3267 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::saveViewPtCB",
3268 "Only Perspective and Orthographic cameras are supported.");
3272 viewPtList.push_back(tmp);
3275 std::string vpName =
name;
3277 while ((
int) vpName.size() <= MAX_VP_NAME)
3280 fileOut << vpName << std::endl;
3281 tmp.position.getValue(x, y, z);
3282 fileOut << x <<
" " << y <<
" " << z << std::endl;
3285 tmp.orientation.getValue(axis, angle);
3286 axis.getValue(x, y, z);
3287 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3289 fileOut << tmp.camType <<
" " << tmp.height << std::endl;
3290 fileOut << tmp.focalDistance <<
" ";
3291 fileOut << tmp.nearDistance <<
" ";
3292 fileOut << tmp.farDistance << std::endl;
3293 fileOut << tmp.viewportMapping <<
" ";
3294 fileOut << tmp.aspectRatio <<
"\n" << std::endl;
3300void G4OpenInventorXtExaminerViewer::deleteViewPtCB(Widget,
3301 XtPointer client_data,
3306 This->deleteViewPt();
3313void G4OpenInventorXtExaminerViewer::deleteViewPt(
char *vpName)
3317 fileIn.open(fileName.c_str());
3318 std::ofstream out(
"temporaryFile.txt");
3321 vpName = viewPtList[viewPtIdx].viewPtName;
3324 XmString vpNameStr = XmStringCreateLocalized(vpName);
3326 XmListDeleteItem(myViewPtList, vpNameStr);
3327 XmStringFree(vpNameStr);
3330 getline(fileIn, line);
3331 out << line <<
"\n";
3333 while (getline(fileIn, line)) {
3334 end = line.find_last_not_of(
' ');
3335 line = line.substr(0, end + 1);
3336 if (!strcmp(line.c_str(), vpName)) {
3337 while (line.size()) {
3338 getline(fileIn, line);
3341 while (getline(fileIn, line))
3342 out << line <<
"\n";
3344 while (line.size()) {
3345 out << line <<
"\n";
3346 getline(fileIn, line);
3353 int size = viewPtList.size();
3354 while (idx < size) {
3355 if (!strcmp(viewPtList[idx].viewPtName, vpName)) {
3356 viewPtList.erase(viewPtList.begin() + idx);
3368 int istat = remove(fileName.c_str());
3370 char dialogName[] =
"Warning";
3374 istat = rename(
"temporaryFile.txt", fileName.c_str());
3376 char dialogName[] =
"Warning";
3380 fileOut.open(fileName.c_str(), std::ios::in);
3381 fileOut.seekp(0, std::ios::end);
3383 if (!viewPtList.size()) {
3384 curViewPtName = (
char *)
"";
3386 XtSetSensitive(nextViewPtButton, False);
3387 XtSetSensitive(prevViewPtButton, False);
3389 if (viewPtIdx >= (
int) viewPtList.size())
3399void G4OpenInventorXtExaminerViewer::renameViewPt(
char *vpName)
3401 int idx = 0, end,
pos;
3402 int size = viewPtList.size();
3403 std::string line, newName;
3404 fileIn.open(fileName.c_str());
3407 while ((
int) newName.size() < MAX_VP_NAME)
3410 getline(fileIn, line);
3411 pos = fileIn.tellg();
3412 while (getline(fileIn, line)) {
3413 end = line.find_last_not_of(
' ');
3414 line = line.substr(0, end + 1);
3415 if (!strcmp(line.c_str(), curViewPtName)) {
3418 fileOut.seekp(0, std::ios::end);
3422 getline(fileIn, line);
3423 pos = fileIn.tellg();
3429 while (idx < size) {
3430 if (!strcmp(viewPtList[idx].viewPtName, curViewPtName)) {
3431 strcpy(viewPtList[idx].viewPtName, vpName);
3441void G4OpenInventorXtExaminerViewer::sortViewPts(std::vector<std::string> sortedViewPts)
3444 float x, y, z, angle;
3445 int sortIdx = 0, unsortIdx = 0;
3447 if (fileOut.is_open())
3450 fileOut.open(fileName.c_str());
3454 int size = sortedViewPts.size();
3455 while (sortIdx < size) {
3456 while (strcmp(sortedViewPts[sortIdx].c_str(),
3457 viewPtList[unsortIdx].viewPtName))
3460 std::string vpName = viewPtList[unsortIdx].viewPtName;
3462 while ((
int) vpName.size() < MAX_VP_NAME)
3464 fileOut << vpName << std::endl;
3465 viewPtList[unsortIdx].position.getValue(x, y, z);
3466 fileOut << x <<
" " << y <<
" " << z << std::endl;
3469 viewPtList[unsortIdx].orientation.getValue(axis, angle);
3470 axis.getValue(x, y, z);
3471 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3473 fileOut << viewPtList[unsortIdx].camType <<
" "
3474 << viewPtList[unsortIdx].height << std::endl;
3475 fileOut << viewPtList[unsortIdx].focalDistance <<
" ";
3477 fileOut << viewPtList[unsortIdx].nearDistance <<
" ";
3479 fileOut << viewPtList[unsortIdx].farDistance << std::endl;
3481 fileOut << viewPtList[unsortIdx].viewportMapping <<
" ";
3482 fileOut << viewPtList[unsortIdx].aspectRatio <<
"\n" << std::endl;
3500 float x, y, z, angle;
3504 parseString<int>(viewPtIdx, token, error);
3505 getline(fileIn, token);
3507 while (getline(fileIn, token)) {
3509 int end = token.find_last_not_of(
' ');
3510 token = token.substr(0, end + 1);
3512 char *vpName =
new char[token.size() + 1];
3513 strcpy(vpName, token.c_str());
3514 tmp.viewPtName = vpName;
3517 parseString<float>(x, token, error);
3519 parseString<float>(y, token, error);
3521 parseString<float>(z, token, error);
3523 tmp.position = axis.setValue(x, y, z);
3525 parseString<float>(x, token, error);
3527 parseString<float>(y, token, error);
3529 parseString<float>(z, token, error);
3531 parseString<float>(angle, token, error);
3533 orient.setValue(axis.setValue(x, y, z), angle);
3534 tmp.orientation = orient.getValue();
3537 parseString<int>(camType, token, error);
3539 tmp.camType = (CameraType) camType;
3541 parseString<float>(tmp.height, token, error);
3543 parseString<float>(tmp.focalDistance, token, error);
3545 parseString<float>(tmp.nearDistance, token, error);
3547 parseString<float>(tmp.farDistance, token, error);
3549 parseString<int>(tmp.viewportMapping, token, error);
3551 parseString<float>(tmp.aspectRatio, token, error);
3553 getline(fileIn, token);
3554 getline(fileIn, token);
3561 viewPtList.push_back(tmp);
3574 std::istringstream str(s);
3575 if ((str >> t).fail())
3582void G4OpenInventorXtExaminerViewer::popUpFileSelDialog(Widget &dialog,
3583 std::string dialogName,
3584 std::string buttonLabel,
3585 XtCallbackProc cbOK)
3589 Widget parent, scrollWidget;
3590 parent = SoXt::getShellWidget(getParentWidget());
3592 if (dialog == NULL) {
3595 XmString str = XmStringCreateLocalized((
char *) buttonLabel.c_str());
3598 XtSetArg(args[n], XmNokLabelString, str);
n++;
3599 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE);
n++;
3601 dialog = XmCreateFileSelectionDialog(parent,
3602 (
char *) dialogName.c_str(), args, n);
3604 XtAddCallback(dialog, XmNokCallback, cbOK,
this);
3605 XtAddCallback(dialog, XmNcancelCallback, cancelFileSelDialogCB,
this);
3608 scrollWidget = XmFileSelectionBoxGetChild(dialog, XmDIALOG_DIR_LIST);
3611 scrollWidget = XmFileSelectionBoxGetChild(dialog, XmDIALOG_LIST);
3615 XtUnmanageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
3618 XtManageChild(dialog);
3624void G4OpenInventorXtExaminerViewer::cancelFileSelDialogCB(Widget w,
3634void G4OpenInventorXtExaminerViewer::openViewPtFileCB(Widget,
3635 XtPointer client_data,
3640 This->popUpFileSelDialog(This->openFileDialog,
"Open File",
"Load",
3641 viewPtFileSelectedCB);
3645void G4OpenInventorXtExaminerViewer::viewPtFileSelectedCB(Widget w,
3646 XtPointer client_data,
3647 XtPointer call_data)
3651 XmFileSelectionBoxCallbackStruct *cbs =
3652 (XmFileSelectionBoxCallbackStruct *) call_data;
3656 if (!(file = (
char *) XmStringUnparse(cbs->value,
3657 XmFONTLIST_DEFAULT_TAG, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0,
3659 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::fileSelectedCB",
3660 "Internal error during file opening");
3664 This->fileIn.open(file);
3665 if (!This->fileIn.fail()) {
3667 This->cleanUpAfterPrevFile();
3669 String dialogName = (
char *)
"Error Loading File";
3670 std::string msg =
"Wrong or corrupted input file.";
3673 This->fileName = file;
3674 This->fileOut.open(This->fileName.c_str(), std::ios::in);
3675 This->fileOut.seekp(0, std::ios::end);
3677 if (!This->listsDialog)
3678 constructListsDialog(w, This, NULL);
3680 This->addViewPoints();
3682 std::string newDialogName = This->fileName.substr(
3683 This->fileName.rfind(
'/') + 1);
3684 XtVaSetValues(This->myShellDialog, XmNtitle,
3685 (
char *) newDialogName.c_str(), NULL);
3687 if (This->viewPtList.size()) {
3689 XmTextSetString(This->viewPtSelection, NULL);
3690 XtSetSensitive(This->nextViewPtButton, True);
3691 XtSetSensitive(This->prevViewPtButton, True);
3693 XtSetSensitive(This->nextViewPtButton, False);
3694 XtSetSensitive(This->prevViewPtButton, False);
3700 This->fileIn.close();
3702 String dialogName = (
char *)
"Nonexistent File";
3703 std::string msg =
"Unable to open file.";
3708 This->fileIn.clear();
3715void G4OpenInventorXtExaminerViewer::addViewPoints()
3717 int size = viewPtList.size();
3723 viewPts = (XmString *) XtMalloc(size *
sizeof(XmString));
3724 for (
int i = 0; i < size; i++)
3725 viewPts[i] = XmStringCreateLocalized(viewPtList[i].viewPtName);
3727 XmListAddItemsUnselected(myViewPtList, viewPts, size, 1);
3729 if (viewPts != NULL) {
3730 for (
int i = 0; i < size; i++)
3731 XmStringFree(viewPts[i]);
3732 XtFree((
char *) viewPts);
3740void G4OpenInventorXtExaminerViewer::cleanUpAfterPrevFile()
3744 setSuperimpositionEnabled(superimposition,
FALSE);
3746 currentState = GENERAL;
3747 if (fileOut.is_open())
3750 XmListDeleteAllItems(myViewPtList);
3762 XmString warningMsg;
3764 warningMsg = XmStringCreateLocalized((
char *)msg.c_str());
3767 XtSetArg(args[n], XmNmessageString, warningMsg);
n++;
3768 Widget warningDialog = XmCreateWarningDialog(getParentWidget(), dialogName, args, n);
3770 XtAddCallback(warningDialog, XmNokCallback, cb,
this);
3772 XmStringFree(warningMsg);
3774 XtVaSetValues (warningDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
3775 XtUnmanageChild(XtNameToWidget(warningDialog,
"Help"));
3776 XtUnmanageChild(XtNameToWidget(warningDialog,
"Cancel"));
3778 XtManageChild(warningDialog);
3782void G4OpenInventorXtExaminerViewer::newViewPtFileCB(Widget,
3783 XtPointer client_data,
3788 This->popUpFileSelDialog(This->newFileDialog,
"New File",
"Save",
3793void G4OpenInventorXtExaminerViewer::createNewVPFileCB(Widget w,
3794 XtPointer client_data,
3795 XtPointer call_data)
3800 XmFileSelectionBoxCallbackStruct *cbs =
3801 (XmFileSelectionBoxCallbackStruct *) call_data;
3805 if (!(file = (
char *) XmStringUnparse(cbs->value,
3806 XmFONTLIST_DEFAULT_TAG, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0,
3808 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::createNewVPFileCB",
3809 "Internal error during file opening");
3813 This->fileName = file;
3814 fName = This->fileName.substr(This->fileName.rfind(
'/') + 1);
3815 This->fileIn.open(file);
3816 if (This->fileIn.fail()) {
3817 This->cleanUpAfterPrevFile();
3818 This->fileOut.open(file);
3819 XtSetSensitive(This->nextViewPtButton, False);
3820 XtSetSensitive(This->prevViewPtButton, False);
3821 if (This->listsDialog)
3822 closeListsDialogCB(w, This, NULL);
3823 constructListsDialog(w, This, NULL);
3825 if (This->returnToSaveVP) {
3826 This->returnToSaveVP =
false;
3827 saveViewPtCB(NULL, This, NULL);
3830 String dialogName = (
char *)
"Existing File";
3831 std::string msg =
"'" + fName +
"' already exists. Do you want to overwrite it?";
3833 This->fileIn.close();
3835 This->fileIn.clear();
3841void G4OpenInventorXtExaminerViewer::overwriteFileCB(Widget,
3842 XtPointer client_data,
3846 This->cleanUpAfterPrevFile();
3847 XtSetSensitive(This->nextViewPtButton, False);
3848 XtSetSensitive(This->prevViewPtButton, False);
3850 XtUnmanageChild(This->newFileDialog);
3852 This->fileOut.open(This->fileName.c_str());
3854 if (This->returnToSaveVP) {
3855 This->returnToSaveVP =
false;
3856 saveViewPtCB(NULL, This, NULL);
3861void G4OpenInventorXtExaminerViewer::loadRefCoordsDialogCB(Widget,
3862 XtPointer client_data,
3867 This->popUpFileSelDialog(This->loadRefCoordsDialog,
"Load Ref Coords",
3868 "Load", loadRefCoordsCB);
3872void G4OpenInventorXtExaminerViewer::loadRefCoordsCB(Widget w,
3873 XtPointer client_data,
3874 XtPointer call_data)
3878 XmFileSelectionBoxCallbackStruct *cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
3883 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3884 XmCHARSET_TEXT, XmCHARSET_TEXT,
3885 NULL, 0, XmOUTPUT_ALL);
3887 std::ifstream ifs(file);
3889 This->refParticleTrajectory.clear();
3891 while(ifs >> x >> y >> z){
3892 This->refParticleTrajectory.push_back(SbVec3f(x,y,z));
3898 String dialogName = (
char *)
"Problem reading file";
3899 std::string msg =
"Problem reading file";
3910void G4OpenInventorXtExaminerViewer::saveRefCoordsDialogCB(Widget,
3911 XtPointer client_data,
3916 if (!This->refParticleTrajectory.size()) {
3917 String dialogName = (
char *)
"No Reference Trajectory";
3918 std::string msg =
"You need to start a run or load a reference trajectory from a file";
3925 Widget parent, scrollWidget;
3926 parent = SoXt::getShellWidget(This->getParentWidget());
3928 if (This->saveRefCoordsDialog == NULL) {
3931 XmString str = XmStringCreateLocalized((
char *)
"Save");
3934 XtSetArg(args[n], XmNokLabelString, str);
n++;
3935 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE);
n++;
3937 This->saveRefCoordsDialog = XmCreateFileSelectionDialog(parent,(
char *)
"Save Ref Coords", args, n);
3939 XtAddCallback(This->saveRefCoordsDialog, XmNokCallback, saveRefCoordsCB, This);
3940 XtAddCallback(This->saveRefCoordsDialog, XmNcancelCallback, cancelFileSelDialogCB, This);
3943 scrollWidget = XmFileSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_DIR_LIST);
3946 scrollWidget = XmFileSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_LIST);
3950 XtUnmanageChild(XmSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_HELP_BUTTON));
3956 XtManageChild(This->saveRefCoordsDialog);
3961void G4OpenInventorXtExaminerViewer::saveRefCoordsCB(Widget w,
3962 XtPointer client_data,
3963 XtPointer call_data)
3967 XmFileSelectionBoxCallbackStruct *cbs =
3968 (XmFileSelectionBoxCallbackStruct *) call_data;
3973 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3974 XmCHARSET_TEXT, XmCHARSET_TEXT,
3975 NULL, 0, XmOUTPUT_ALL);
3977 std::ifstream ifile(file);
3982 Widget parent = This->getParentWidget();
3983 Widget confirmOverwriteDialog;
3986 confirmOverwriteDialog = XmCreateQuestionDialog (parent, (
char *)
"Confirm overwrite", args, 0);
3987 msg = XmStringCreateLocalized ((
char *)
"File exists. Overwrite?");
3988 XtVaSetValues (confirmOverwriteDialog, XmNmessageString, msg, NULL);
3993 XtVaSetValues (confirmOverwriteDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
3994 XtAddCallback (confirmOverwriteDialog, XmNokCallback, saveRefCoordsOverWriteCB, client_data);
3995 XtAddCallback (confirmOverwriteDialog, XmNcancelCallback, saveRefCoordsOverWriteCB, client_data);
4003 XtUnmanageChild(XtNameToWidget(confirmOverwriteDialog,
"Help"));
4004 XtManageChild(confirmOverwriteDialog);
4010 std::ofstream ofs(file);
4013 for(
unsigned int i=0; i < This->refParticleTrajectory.size(); ++i){
4014 This->refParticleTrajectory[i].getValue(x,y,z);
4015 ofs << x <<
" " << y <<
" " << z <<
"\n";
4021 String dialogName = (
char *)
"Error opening file";
4022 std::string msg =
"There was a problem trying to open the file '";
4035void G4OpenInventorXtExaminerViewer::saveRefCoordsOverWriteCB(Widget w,
4036 XtPointer client_data,
4037 XtPointer call_data)
4039 XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
4042 switch (cbs->reason) {
4050 for(
unsigned int i=0; i < This->refParticleTrajectory.size(); ++i){
4051 This->refParticleTrajectory[i].getValue(x,y,z);
4052 ofs << x <<
" " << y <<
" " << z <<
"\n";
4059 String dialogName = (
char *)
"Error opening file";
4060 std::string msg =
"There was a problem trying to open the file '";
4074 XmProcessTraversal(XtNameToWidget(This->
saveRefCoordsWidget,
"Text"), XmTRAVERSE_CURRENT);
4087void G4OpenInventorXtExaminerViewer::loadSceneGraphDialogCB(Widget,
4088 XtPointer client_data,
4093 This->popUpFileSelDialog(This->loadSceneGraphDialog,
"Load Scene Graph",
4094 "Load", loadSceneGraphCB);
4099void G4OpenInventorXtExaminerViewer::loadSceneGraphCB(Widget w,
4100 XtPointer client_data,
4101 XtPointer call_data)
4105 XmFileSelectionBoxCallbackStruct *cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
4109 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
4110 XmCHARSET_TEXT, XmCHARSET_TEXT,
4111 NULL, 0, XmOUTPUT_ALL);
4114 if (!sceneInput.openFile(file)) {
4115 String dialogName = (
char *)
"Problem opening file";
4116 std::string msg =
"Cannot open file ";
4120 sceneInput.closeFile();
4124 This->newSceneGraph = SoDB::readAll(&sceneInput);
4125 if (This->newSceneGraph == NULL) {
4126 String dialogName = (
char *)
"Problem reading file";
4127 std::string msg =
"Problem reading file";
4133 This->setSceneGraph(This->newSceneGraph);
4140void G4OpenInventorXtExaminerViewer::saveSceneGraphDialogCB(Widget,
4141 XtPointer client_data,
4148 Widget parent, scrollWidget;
4149 parent = SoXt::getShellWidget(This->getParentWidget());
4151 if (This->saveSceneGraphDialog == NULL) {
4154 XmString str = XmStringCreateLocalized((
char *)
"Save");
4157 XtSetArg(args[n], XmNokLabelString, str);
n++;
4158 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE);
n++;
4160 This->saveSceneGraphDialog = XmCreateFileSelectionDialog(parent,(
char *)
"Save Scene Graph", args, n);
4162 XtAddCallback(This->saveSceneGraphDialog, XmNokCallback, saveSceneGraphCB, This);
4163 XtAddCallback(This->saveSceneGraphDialog, XmNcancelCallback, cancelFileSelDialogCB, This);
4166 scrollWidget = XmFileSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_DIR_LIST);
4169 scrollWidget = XmFileSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_LIST);
4173 XtUnmanageChild(XmSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_HELP_BUTTON));
4179 XtManageChild(This->saveSceneGraphDialog);
4185void G4OpenInventorXtExaminerViewer::saveSceneGraphCB(Widget w,
4186 XtPointer client_data,
4187 XtPointer call_data)
4191 XmFileSelectionBoxCallbackStruct *cbs =
4192 (XmFileSelectionBoxCallbackStruct *) call_data;
4196 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
4197 XmCHARSET_TEXT, XmCHARSET_TEXT,
4198 NULL, 0, XmOUTPUT_ALL);
4200 std::ifstream ifile(file);
4205 Widget parent = This->getParentWidget();
4206 Widget confirmOverwriteDialog;
4209 confirmOverwriteDialog = XmCreateQuestionDialog (parent, (
char *)
"Confirm overwrite", args, 0);
4210 msg = XmStringCreateLocalized ((
char *)
"File exists. Overwrite?");
4211 XtVaSetValues (confirmOverwriteDialog, XmNmessageString, msg, NULL);
4216 XtVaSetValues (confirmOverwriteDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
4217 XtAddCallback (confirmOverwriteDialog, XmNokCallback, saveSceneGraphOverWriteCB, client_data);
4218 XtAddCallback (confirmOverwriteDialog, XmNcancelCallback, saveSceneGraphOverWriteCB, client_data);
4226 XtUnmanageChild(XtNameToWidget(confirmOverwriteDialog,
"Help"));
4227 XtManageChild(confirmOverwriteDialog);
4233 SoWriteAction writeAction;
4234 SoSeparator *root = (SoSeparator *) (This->getSceneGraph());
4236 SoOutput * out = writeAction.getOutput();
4238 if(out->openFile(file)){
4239 out->setBinary(
FALSE);
4240 writeAction.apply(root);
4246 String dialogName = (
char *)
"Error opening file";
4247 std::string msg =
"There was a problem trying to open the file '";
4262void G4OpenInventorXtExaminerViewer::saveSceneGraphOverWriteCB(Widget w,
4263 XtPointer client_data,
4264 XtPointer call_data)
4266 XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
4269 switch (cbs->reason) {
4274 SoWriteAction writeAction;
4275 SoSeparator *root = (SoSeparator *) (This->getSceneGraph());
4277 SoOutput * out = writeAction.getOutput();
4279 out->setBinary(
FALSE);
4280 writeAction.apply(root);
4289 String dialogName = (
char *)
"Error opening file";
4290 std::string msg =
"There was a problem trying to open the file '";
4321void G4OpenInventorXtExaminerViewer::loadBookmarkCB(Widget,
4322 XtPointer client_data,
4323 XtPointer call_data)
4327 XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
4329 vpName = (
char *) XmStringUnparse(cbs->item, XmFONTLIST_DEFAULT_TAG,
4330 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
4332 for (
int i = 0; i < (int) This->viewPtList.size(); i++) {
4333 if (!strcmp(This->viewPtList[i].viewPtName, vpName)) {
4334 This->viewPtIdx = i;
4338 XmTextSetString(This->viewPtSelection, vpName);
4340 This->writeViewPtIdx();
4347void G4OpenInventorXtExaminerViewer::deleteBookmarkCB(Widget,
4348 XtPointer client_data,
4354 vpName = XmTextGetString(This->viewPtSelection);
4356 XmString vpNameStr = XmStringCreateLocalized(vpName);
4358 if (XmListItemExists(This->myViewPtList, vpNameStr)) {
4359 XmListDeleteItem(This->myViewPtList, vpNameStr);
4360 This->deleteViewPt(vpName);
4363 XmStringFree(vpNameStr);
4364 XmTextSetString(This->viewPtSelection, NULL);
4369void G4OpenInventorXtExaminerViewer::renameBookmarkCB(Widget,
4370 XtPointer client_data,
4373 std::string vpNameStr;
4375 int *pos_list, pos_cnt;
4378 vpName = XmTextGetString(This->viewPtSelection);
4380 if (!strlen(vpName) || !strcmp(This->curViewPtName, vpName)) {
4387 int beg = vpNameStr.find_first_not_of(
' ');
4388 int end = vpNameStr.find_last_not_of(
' ');
4389 vpNameStr = vpNameStr.substr(beg, end - beg + 1);
4390 const int nVPName = vpNameStr.size() + 1;
4391 char* vpName1 =
new char[nVPName];
4392 strncpy(vpName1, vpNameStr.c_str(), nVPName);
4394 int size = This->viewPtList.size();
4395 for (
int i = 0; i < size; i++) {
4396 if (!strcmp(vpName1, This->viewPtList[i].viewPtName)) {
4398 String dialogName = (
char *)
"Existing Viewpoint";
4399 std::string msg =
"'";
4401 msg +=
"' already exists. Choose a different name";
4409 XmString vpNameXmStr = XmStringCreateLocalized(vpName1);
4411 if (XmListGetSelectedPos(This->myViewPtList, &pos_list, &pos_cnt)) {
4412 XmListReplaceItemsPos(This->myViewPtList, &vpNameXmStr, 1, pos_list[0]);
4413 This->renameViewPt(vpName1);
4414 XtFree((
char *) pos_list);
4417 if (This->currentState == VIEWPOINT)
4418 This->scheduleRedraw();
4420 XmStringFree(vpNameXmStr);
4425void G4OpenInventorXtExaminerViewer::sortBookmarksCB(Widget,
4426 XtPointer client_data,
4431 XmString *strList, *newStrList;
4432 std::vector<std::string> charList;
4435 if (This->viewPtList.size() < 2)
4439 XtVaGetValues(This->myViewPtList, XmNitemCount, &size, XmNitems, &strList,
4442 for (
int i = 0; i < size; i++) {
4443 vpName = (
char *) XmStringUnparse(strList[i], XmFONTLIST_DEFAULT_TAG,
4444 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
4445 charList.push_back(vpName);
4449 std::sort(charList.begin(), charList.end());
4451 newStrList = (XmString *) XtMalloc(size *
sizeof(XmString));
4452 for (
int i = 0; i < size; i++) {
4454 if (!strcmp(charList[i].c_str(), This->curViewPtName))
4455 This->viewPtIdx = i;
4456 const int nVPName = charList[i].size() + 1;
4457 char *vpName2 =
new char[nVPName];
4458 strncpy(vpName2, charList[i].c_str(), nVPName);
4459 newStrList[i] = XmStringCreateLocalized(vpName2);
4463 XmListDeleteAllItems(This->myViewPtList);
4464 XmListAddItemsUnselected(This->myViewPtList, newStrList, size, 1);
4466 This->sortViewPts(charList);
4468 if (newStrList != NULL) {
4469 for (
int i = 0; i < size; i++)
4470 XmStringFree(newStrList[i]);
4471 XtFree((
char *) newStrList);
4476void G4OpenInventorXtExaminerViewer::evenOutRefParticlePts()
4478 if(this->refParticleTrajectory.empty())
4481 SbVec3f p1, p2, p3, dirNow, dirNxt, dir, p2_tmp, p_start, p_corner, p_nxt;
4482 float avgDistBtwPts = 0;
4483 float totalDistBtwPts = 0;
4484 std::vector<SbVec3f> newRefParticleTrajectory;
4486 int size = refParticleTrajectory.size() - 1;
4488 for (
int i = 0; i < size; i++) {
4489 p1 = refParticleTrajectory[i];
4490 p2 = refParticleTrajectory[i + 1];
4494 totalDistBtwPts += (p2 - p1).length();
4497 if (numOfPts <= 2)
return;
4499 avgDistBtwPts = totalDistBtwPts / numOfPts;
4500 float minDistAllowed = 0.75 * avgDistBtwPts;
4506 p1 = refParticleTrajectory[i];
4507 p2 = refParticleTrajectory[i + 1];
4510 p1.getValue(x, y, z);
4512 newRefParticleTrajectory.push_back(refPoint);
4515 while ((p2 - p1).length() < minDistAllowed && j < (size - 1)) {
4518 p1 = refParticleTrajectory[j];
4519 p2 = refParticleTrajectory[j + 1];
4527 refParticleTrajectory.clear();
4528 refParticleTrajectory = newRefParticleTrajectory;
4534void G4OpenInventorXtExaminerViewer::closeMainWindowCB(Widget,
4535 XtPointer client_data,
4541 if (This->openFileDialog)
4542 XtUnmanageChild(This->openFileDialog);
4544 if (This->newFileDialog)
4545 XtUnmanageChild(This->newFileDialog);
4547 if (This->listsDialog)
4548 closeListsDialogCB(NULL, This, NULL);
4552void G4OpenInventorXtExaminerViewer::saveCurCamera()
4554 SoCamera *cam = getCamera();
4555 camB4Animation.viewportMapping = cam->viewportMapping.getValue();
4556 camB4Animation.position = cam->position.getValue();
4557 camB4Animation.orientation = cam->orientation.getValue();
4558 camB4Animation.aspectRatio = cam->aspectRatio.getValue();
4559 camB4Animation.nearDistance = cam->nearDistance.getValue();
4560 camB4Animation.farDistance = cam->farDistance.getValue();
4561 camB4Animation.focalDistance = cam->focalDistance.getValue();
4563 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
4564 camB4Animation.height =
4565 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
4566 camB4Animation.camType = PERSPECTIVE;
4567 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4568 camB4Animation.height =
4569 ((SoOrthographicCamera *) cam)->height.getValue();
4570 camB4Animation.camType = ORTHOGRAPHIC;
4575void G4OpenInventorXtExaminerViewer::restoreCamera()
4577 SoCamera *cam = getCamera();
4579 cam->viewportMapping = camB4Animation.viewportMapping;
4580 cam->position = camB4Animation.position;
4581 cam->orientation = camB4Animation.orientation;
4582 cam->aspectRatio = camB4Animation.aspectRatio;
4583 cam->nearDistance = camB4Animation.nearDistance;
4584 cam->farDistance = camB4Animation.farDistance;
4585 cam->focalDistance = camB4Animation.focalDistance;
4587 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
4588 if (camB4Animation.camType == ORTHOGRAPHIC) {
4591 ((SoOrthographicCamera *) cam)->height.setValue(
4592 camB4Animation.height);
4594 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
4595 camB4Animation.height);
4596 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4597 if (camB4Animation.camType == PERSPECTIVE) {
4600 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
4601 camB4Animation.height);
4603 ((SoOrthographicCamera *) cam)->height.setValue(
4604 camB4Animation.height);
4609void G4OpenInventorXtExaminerViewer::animateSensorRotationCB(
void *data,
4612 SbTime curTime = SbTime::getTimeOfDay();
4614 SoTimerSensor *s = (SoTimerSensor *) sensor;
4616 float t = float((curTime - s->getBaseTime()).getValue())
4617 / This->animateBtwPtsPeriod;
4619 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
4621 SbBool end = (t == 1.0f);
4624 This->animateSensorRotation->unschedule();
4631 This->currentState = This->prevState;
4641void G4OpenInventorXtExaminerViewer::animateSensorCB(
void *data,
4644 SbTime curTime = SbTime::getTimeOfDay();
4646 SoCamera *cam = This->getCamera();
4647 SoTimerSensor *s = (SoTimerSensor *) sensor;
4649 float t = float((curTime - s->getBaseTime()).getValue())
4650 / This->animateBtwPtsPeriod;
4652 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
4654 SbBool end = (t == 1.0f);
4656 cam->orientation = SbRotation::slerp(This->camStartOrient, This->camEndOrient, t);
4657 cam->position = This->camStartPos + (This->camEndPos - This->camStartPos) * t;
4660 This->animateSensor->unschedule();
4662 if (This->currentState == ANIMATION) {
4663 if (This->refParticleIdx < (
int) (This->refParticleTrajectory.size() - 1))
4664 This->animateRefParticle();
4666 This->animateBtwPtsPeriod = MIN_SPEED;
4667 This->speedStep = START_STEP;
4670 if (This->currentState == REVERSED_ANIMATION) {
4671 if (This->refParticleIdx >= 1)
4672 This->animateRefParticle();
4674 This->animateBtwPtsPeriod = MIN_SPEED;
4675 This->speedStep = START_STEP;
4682void G4OpenInventorXtExaminerViewer::setStartingPtForAnimation()
4684 if (SoXtExaminerViewer::isAnimating())
4688 SbVec3f p1, p2, p2_tmp, camUpV, camD, camD_tmp, leftRightAxis;
4689 float x1, y1, z1, x2, y2, z2;
4691 if (currentState == ANIMATION) {
4692 p1 = refParticleTrajectory[refParticleIdx];
4693 p2 = refParticleTrajectory[++(refParticleIdx)];
4694 }
else if (currentState == REVERSED_ANIMATION) {
4695 p2 = refParticleTrajectory[refParticleIdx];
4696 p1 = refParticleTrajectory[--(refParticleIdx)];
4697 }
else if (currentState == PAUSED_ANIMATION) {
4698 if (refParticleIdx < (
int) refParticleTrajectory.size()) {
4699 p1 = refParticleTrajectory[refParticleIdx];
4700 p2 = refParticleTrajectory[refParticleIdx + 1];
4702 p1 = refParticleTrajectory[refParticleIdx - 1];
4703 p2 = refParticleTrajectory[refParticleIdx];
4706 p1.getValue(x1, y1, z1);
4707 p2.getValue(x2, y2, z2);
4712 p2_tmp.setValue(x2, y1, z2);
4713 camD_tmp = p2_tmp - p1;
4714 camD_tmp.normalize();
4716 camUpV.setValue(0, 1, 0);
4717 rot.setValue(camD_tmp, camD);
4718 rot.multVec(camUpV, camUpV);
4720 leftRightAxis = camD.cross(camUpV);
4722 myCam->position = p1;
4723 myCam->pointAt(p2, camUpV);
4726 p1 = p1 + (up_down * camUpV) + (left_right * leftRightAxis);
4727 myCam->position = p1;
4729 int idx = refParticleIdx + pathLookahead;
4730 idx = std::min(idx, (
int)refParticleTrajectory.size() - 1);
4731 myCam->pointAt(refParticleTrajectory[idx], camUpV);
4733 myCam->focalDistance = 0.1f;
4737void G4OpenInventorXtExaminerViewer::gotoRefPathStart()
4739 G4OpenInventorXtExaminerViewer::gotoRefPathStartCB(NULL, (
void *)
this,
4744void G4OpenInventorXtExaminerViewer::gotoRefPathStartCB(Widget,
4745 XtPointer client_data,
4750 if (!This->refParticleTrajectory.size()) {
4751 String dialogName = (
char *)
"No Reference Trajectory";
4752 std::string msg =
"You need to start a run or load a reference trajectory from a file";
4757 if (This->currentState == ROTATING)
4759 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
4760 || This->currentState == PAUSED_ANIMATION) {
4761 if (This->animateSensor->isScheduled())
4762 This->animateSensor->unschedule();
4763 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
4764 This->maxSpeed = 0.0f;
4765 This->scheduleRedraw();
4767 This->saveCurCamera();
4768 This->prevState = This->currentState;
4769 This->prevRefIdx = This->refParticleIdx;
4772 if (This->SoXtExaminerViewer::isAnimating())
4773 This->stopAnimating();
4776 This->left_right = 0;
4779 This->refParticleIdx = 0;
4780 This->currentState = BEAMLINE;
4781 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
4782 This->axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
4783 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
4784 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
4785 This->scheduleRedraw();
4792 This->prevParticleDir = SbVec3f(0,0,0);
4795 SbVec3f p1 = This->refParticleTrajectory[0];
4796 SbVec3f pN = This->refParticleTrajectory[This->refParticleTrajectory.size() - 1];
4797 This->distance = (pN - p1).length() / 10;
4803void G4OpenInventorXtExaminerViewer::invertRefPathCB(Widget,
4804 XtPointer client_data,
4809 This->invertRefPath();
4813void G4OpenInventorXtExaminerViewer::invertRefPath()
4815 std::reverse(this->refParticleTrajectory.begin(),
4816 this->refParticleTrajectory.end());
4817 this->setReferencePathZPos();
4818 this->sortElements();
4822void G4OpenInventorXtExaminerViewer::animateRefParticleCB(Widget,
4823 XtPointer client_data,
4828 if (!This->refParticleTrajectory.size()) {
4829 This->returnToAnim =
true;
4830 String dialogName = (
char *)
"No Reference Trajectory";
4831 std::string msg =
"You need to start a run or load a reference trajectory from a file";
4836 if (!This->refParticleTrajectory.size())
4840 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
4841 This->maxSpeed = SPEED_INDICATOR_STEP;
4842 This->axisSwitch->whichChild.setValue(SO_SWITCH_ALL);
4843 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
4844 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
4845 This->scheduleRedraw();
4848 SoCamera *cam = This->getCamera();
4851 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
4852 || This->currentState == ROTATING)
4855 if (This->currentState != PAUSED_ANIMATION) {
4857 This->saveCurCamera();
4858 This->prevState = This->currentState;
4859 This->prevRefIdx = This->refParticleIdx;
4861 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4862 This->toggleCameraType();
4863 cam = This->getCamera();
4866 This->refParticleIdx = 0;
4867 This->animateBtwPtsPeriod = MIN_SPEED;
4868 This->speedStep = START_STEP;
4869 This->left_right = This->up_down = 0;
4871 cam->focalDistance = 0.1f;
4872 ((SoPerspectiveCamera *) cam)->heightAngle = 0.50f;
4875 This->currentState = ANIMATION;
4876 This->setStartingPtForAnimation();
4878 cam->position = (This->myCam)->
position.getValue();
4879 cam->orientation = (This->myCam)->orientation.getValue();
4880 This->animateRefParticle();
4884void G4OpenInventorXtExaminerViewer::animateRefParticle()
4886 SoCamera *cam = getCamera();
4888 camStartPos = cam->position.getValue();
4889 camStartOrient = cam->orientation.getValue();
4891 if (currentState != BEAMLINE)
4892 setStartingPtForAnimation();
4894 camEndPos = myCam->position.getValue();
4895 camEndOrient = myCam->orientation.getValue();
4897 if (animateSensor->isScheduled())
4898 animateSensor->unschedule();
4900 animateSensor->setBaseTime(SbTime::getTimeOfDay());
4901 animateSensor->setInterval(SbTime(0.02));
4903 animateSensor->schedule();
4908 void (*callback)(
void *),
void *
object)
4910 this->escapeCallback = callback;
4911 this->examinerObject = object;
4915void G4OpenInventorXtExaminerViewer::sceneChangeCB(
void *
userData, SoSensor *)
4919 if(This->newEvents){
4920 This->findAndSetRefPath();
4921 This->newEvents =
false;
4939 this->viewer->newEvents =
true;
G4GLOB_DLL std::ostream G4cout
const std::vector< const std::vector< G4AttValue > * > & GetAttValues() const
const std::vector< const std::map< G4String, G4AttDef > * > & GetAttDefs() const
void warningMsgDialog(std::string, String, XtCallbackProc)
friend class HookEventProcState
void addButton(Widget menu, std::string name, XtCallbackProc)
virtual void createViewerButtons(Widget parent, SbPList *buttonlist)
bool viewingBeforePickRef
std::string saveRefCoordsFileName
virtual SbBool processSoEvent(const SoEvent *const event)
G4OpenInventorXtExaminerViewer(Widget parent=NULL, const char *name=NULL, SbBool embed=TRUE, SoXtFullViewer::BuildFlag flag=BUILD_ALL, SoXtViewer::Type type=BROWSER)
~G4OpenInventorXtExaminerViewer()
virtual void afterRealizeHook()
void addEscapeCallback(void(*cb)(void *), void *)
void moveCamera(float dist=0, bool lookdown=false)
Widget saveRefCoordsWidget
Widget addMenu(std::string name)
void parseString(T &t, const std::string &s, bool &error)
std::string saveScenegraphFileName
Widget saveScenegraphWidget
Widget buildWidget(Widget parent)
virtual G4bool Notify(G4ApplicationState requiredState)
HookEventProcState(G4OpenInventorXtExaminerViewer *)
static Pixmap createPixmapFromXpm(Widget button, const char **xpm, SbBool ghost=FALSE)
const char * name(G4int ptype)
void xmAddMouseEventHandler(Widget w)