39#include <X11/keysym.h>
44#include <Xm/MessageB.h>
46#include <Xm/ToggleB.h>
47#include <Xm/CascadeB.h>
48#include <Xm/ArrowBG.h>
50#include <Xm/RowColumn.h>
52#include <Xm/SelectioB.h>
53#include <Xm/Protocols.h>
54#include <Xm/SeparatoG.h>
55#include <Xm/DialogS.h>
59#include <Xm/DrawingA.h>
61#include <Inventor/Xt/SoXt.h>
63#include <Inventor/Xt/SoXtCursor.h>
64#include <Inventor/events/SoKeyboardEvent.h>
65#include <Inventor/events/SoMouseButtonEvent.h>
66#include <Inventor/events/SoLocation2Event.h>
67#include <Inventor/nodes/SoSeparator.h>
68#include <Inventor/nodes/SoOrthographicCamera.h>
69#include <Inventor/nodes/SoPerspectiveCamera.h>
72#include <Inventor/nodes/SoLineSet.h>
73#include <Inventor/nodes/SoMaterial.h>
74#include <Inventor/errors/SoDebugError.h>
75#include <Inventor/SoPickedPoint.h>
76#include <Inventor/actions/SoWriteAction.h>
81#include <Inventor/sensors/SoTimerSensor.h>
82#include <Inventor/sensors/SoNodeSensor.h>
97#include <Inventor/nodes/SoCallback.h>
98#include <Inventor/nodes/SoSwitch.h>
99#include <Inventor/nodes/SoScale.h>
100#include <Inventor/nodes/SoTranslation.h>
101#include <Inventor/actions/SoSearchAction.h>
102#include <Inventor/actions/SoGetBoundingBoxAction.h>
104#include <Inventor/nodes/SoCoordinate3.h>
106#include <Inventor/nodes/SoText2.h>
107#include <Inventor/nodes/SoFont.h>
108#include <Inventor/nodes/SoPointSet.h>
109#include <Inventor/nodes/SoDrawStyle.h>
110#include <Inventor/nodes/SoBaseColor.h>
113#include <Inventor/nodekits/SoBaseKit.h>
116#include <Inventor/SbVec3f.h>
120static const char* thisClassName =
"G4OpenInventorXtExaminerViewer";
123#define START_STEP 0.3
124#define SPEED_INDICATOR_STEP 0.045
125#define MAX_SPEED_INDICATOR 0.81
131 const char *name, SbBool embed,
132 SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type) :
133 SoXtExaminerViewer(parent, name, embed, flag, type,
FALSE)
136 this->constructor(
TRUE);
141 const char *name, SbBool embed,
142 SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type,
144 SoXtExaminerViewer(parent, name, embed, flag, type,
FALSE)
146 this->constructor(build);
150void G4OpenInventorXtExaminerViewer::constructor(
const SbBool build)
152 setClassName(thisClassName);
155 this->newEvents =
false;
157 fileName =
".bookmarkFile";
159 animateSensor =
new SoTimerSensor(
160 G4OpenInventorXtExaminerViewer::animateSensorCB,
this);
161 animateSensorRotation =
new SoTimerSensor(
162 G4OpenInventorXtExaminerViewer::animateSensorRotationCB,
this);
164 currentState = GENERAL;
165 myCam =
new SoPerspectiveCamera;
169 curViewPtName =
new char[MAX_VP_NAME + 1];
170 left_right = up_down = 0;
176 lshiftdown = rshiftdown =
false;
179 lctrldown = rctrldown =
false;
183 prevColorField = NULL;
186 openFileDialog = newFileDialog = listsDialog = (Widget) NULL;
187 loadRefCoordsDialog = saveRefCoordsDialog = NULL;
188 loadSceneGraphDialog = saveSceneGraphDialog = NULL;
189 myElementList = NULL;
193 newSceneGraph = NULL;
194 zcoordSetFlag =
false;
201 static const char * superimposed[] = {
202 "#Inventor V2.1 ascii",
"",
209 " OrthographicCamera ",
215 " DEF soxt->callback Callback { }",
218 " DEF soxt->translation Translation ",
220 " translation 0 0 0",
222 " DEF soxt->scale Scale ",
224 " scaleFactor 1 1 1",
226 " DEF soxt->geometry Coordinate3 ",
230 " -0.81 -0.04 0, -0.81 0 0,",
231 " -0.81 0.04 0, 0 -0.04 0,",
233 " 0.81 -0.04 0, 0.81 0 0,",
236 " 0.81 0.02 0, 0.81 -0.02 0,",
239 " 0.4 0.01 0, 0.4 -0.01 0,",
244 " DEF soxt->animSpeedOutlineSwitch Switch ",
249 " emissiveColor 0 0 0",
255 " 12, 11, 10, 9, -1",
260 " DEF soxt->axisSwitch Switch ",
279 " DEF soxt->animSpeedSwitch Switch ",
284 " emissiveColor 0 1 0",
290 " 16, 15, 14, 13, -1",
296 " DEF soxt->curInfoSwitch Switch ",
299 " DEF soxt->curInfoTrans Translation ",
301 " translation 10 20 30 ",
303 " DEF soxt->curInfoFont Font ",
305 " name defaultFont:Bold",
308 " DEF soxt->curInfoText Text2 ",
317 " DEF soxt->mouseOverTransLogName Translation ",
319 " translation 0 0 0 ",
321 " DEF soxt->mouseOverFontLogName Font ",
323 " name defaultFont:Bold",
326 " DEF soxt->mouseOverTextLogName Text2 { } ",
330 " DEF soxt->mouseOverTransSolid Translation ",
332 " translation 0 0 0 ",
334 " DEF soxt->mouseOverFontSolid Font ",
336 " name defaultFont:Bold",
339 " DEF soxt->mouseOverTextSolid Text2 { } ",
343 " DEF soxt->mouseOverTransMaterial Translation ",
345 " translation 0 0 0 ",
347 " DEF soxt->mouseOverFontMaterial Font ",
349 " name defaultFont:Bold",
352 " DEF soxt->mouseOverTextMaterial Text2 { } ",
356 " DEF soxt->mouseOverTransZPos Translation ",
358 " translation 0 0 0 ",
360 " DEF soxt->mouseOverFontZPos Font ",
362 " name defaultFont:Bold",
365 " DEF soxt->mouseOverTextZPos Text2 { } ",
371 for (i = bufsize = 0; superimposed[i]; i++)
372 bufsize += strlen(superimposed[i]) + 1;
373 char * buf =
new char[bufsize + 1];
374 for (i = bufsize = 0; superimposed[i]; i++) {
375 strcpy(buf + bufsize, superimposed[i]);
376 bufsize += strlen(superimposed[i]);
380 SoInput * input =
new SoInput;
381 input->setBuffer(buf, bufsize);
382 SbBool ok = SoDB::read(input, this->superimposition);
387 this->superimposition->ref();
389 this->sscale = (SoScale *) this->getSuperimpositionNode(
390 this->superimposition,
"soxt->scale");
391 this->stranslation = (SoTranslation *) this->getSuperimpositionNode(
392 this->superimposition,
"soxt->translation");
393 this->sgeometry = (SoCoordinate3 *) this->getSuperimpositionNode(
394 this->superimposition,
"soxt->geometry");
395 this->axisSwitch = (SoSwitch *) this->getSuperimpositionNode(
396 this->superimposition,
"soxt->axisSwitch");
397 this->animSpeedOutlineSwitch = (SoSwitch *) this->getSuperimpositionNode(
398 this->superimposition,
"soxt->animSpeedOutlineSwitch");
399 this->animSpeedSwitch = (SoSwitch *) this->getSuperimpositionNode(
400 this->superimposition,
"soxt->animSpeedSwitch");
401 this->curInfoSwitch = (SoSwitch *) this->getSuperimpositionNode(
402 this->superimposition,
"soxt->curInfoSwitch");
403 this->curInfoTrans = (SoTranslation *) this->getSuperimpositionNode(
404 this->superimposition,
"soxt->curInfoTrans");
405 this->curInfoFont = (SoFont *) this->getSuperimpositionNode(
406 this->superimposition,
"soxt->curInfoFont");
407 this->curInfoText = (SoText2 *) this->getSuperimpositionNode(
408 this->superimposition,
"soxt->curInfoText");
409 this->mouseOverTransLogName = (SoTranslation*)this->getSuperimpositionNode(
410 this->superimposition,
"soxt->mouseOverTransLogName");
411 this->mouseOverFontLogName = (SoFont *) this->getSuperimpositionNode(
412 this->superimposition,
"soxt->mouseOverFontLogName");
413 this->mouseOverTextLogName = (SoText2 *) this->getSuperimpositionNode(
414 this->superimposition,
"soxt->mouseOverTextLogName");
415 this->mouseOverTransSolid = (SoTranslation *) this->getSuperimpositionNode(
416 this->superimposition,
"soxt->mouseOverTransSolid");
417 this->mouseOverFontSolid = (SoFont *) this->getSuperimpositionNode(
418 this->superimposition,
"soxt->mouseOverFontSolid");
419 this->mouseOverTextSolid = (SoText2 *) this->getSuperimpositionNode(
420 this->superimposition,
"soxt->mouseOverTextSolid");
421 this->mouseOverTransMaterial = (SoTranslation*)this->getSuperimpositionNode(
422 this->superimposition,
"soxt->mouseOverTransMaterial");
423 this->mouseOverFontMaterial = (SoFont *) this->getSuperimpositionNode(
424 this->superimposition,
"soxt->mouseOverFontMaterial");
425 this->mouseOverTextMaterial = (SoText2 *) this->getSuperimpositionNode(
426 this->superimposition,
"soxt->mouseOverTextMaterial");
427 this->mouseOverTransZPos = (SoTranslation *) this->getSuperimpositionNode(
428 this->superimposition,
"soxt->mouseOverTransZPos");
429 this->mouseOverFontZPos = (SoFont *) this->getSuperimpositionNode(
430 this->superimposition,
"soxt->mouseOverFontZPos");
431 this->mouseOverTextZPos = (SoText2 *) this->getSuperimpositionNode(
432 this->superimposition,
"soxt->mouseOverTextZPos");
434 SoCallback * cb = (SoCallback *) this->getSuperimpositionNode(
435 this->superimposition,
"soxt->callback");
436 cb->setCallback(superimpositionCB,
this);
438 this->addSuperimposition(this->superimposition);
439 this->setSuperimpositionEnabled(this->superimposition,
FALSE);
440 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
441 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
442 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
471G4OpenInventorXtExaminerViewer::getSuperimpositionNode(SoNode *root,
475 this->searcher =
new SoSearchAction;
477 searcher->setName(SbName(name));
478 searcher->setInterest(SoSearchAction::FIRST);
479 searcher->setSearchingAll(
TRUE);
480 searcher->apply(root);
481 assert(searcher->getPath());
482 return searcher->getPath()->getTail();
486void G4OpenInventorXtExaminerViewer::superimpositionCB(
void * closure,
496void G4OpenInventorXtExaminerViewer::superimpositionEvent(SoAction * action)
499 if (!action->isOfType(SoGLRenderAction::getClassTypeId()))
501 SbViewportRegion vpRegion =
502 ((SoGLRenderAction *) action)->getViewportRegion();
503 SbVec2s viewportSize = vpRegion.getViewportSizePixels();
505 float aspect = float(viewportSize[0]) / float(viewportSize[1]);
506 float factorx = 1.0f / float(viewportSize[1]) * 220.0f;
507 float factory = factorx;
510 this->stranslation->translation.setValue(SbVec3f(0.0f, -0.4f, 0.0f));
512 this->stranslation->translation.setValue(
513 SbVec3f(0.0f, -0.4f / aspect, 0.0f));
517 if (viewportSize[0] > 500)
518 factorx *= 500.0f / 400.0f;
520 factorx *= float(viewportSize[0]) / 400.0f;
521 this->sscale->scaleFactor.setValue(SbVec3f(factorx, factory, 1.0f));
523 float xInfo, yInfo, xMouseLogName, yMouseLogName, xMouseSolid, yMouseSolid,
524 xMouseMaterial, yMouseMaterial, xMouseZPos, yMouseZPos;
528 yMouseLogName = -.75;
531 xMouseMaterial = 0.0;
532 yMouseMaterial = -.81;
538 xMouseSolid *= aspect;
539 xMouseMaterial *= aspect;
540 this->curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
541 this->mouseOverTransLogName->translation.setValue(
542 SbVec3f(xMouseLogName, yMouseLogName, 0.0));
543 this->mouseOverTransSolid->translation.setValue(
544 SbVec3f(xMouseSolid, yMouseSolid, 0.0));
545 this->mouseOverTransMaterial->translation.setValue(
546 SbVec3f(xMouseMaterial, yMouseMaterial, 0.0));
547 this->mouseOverTransZPos->translation.setValue(
548 SbVec3f(xMouseZPos, yMouseZPos, 0.0));
551 yMouseSolid /= aspect;
552 yMouseMaterial /= aspect;
553 this->curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
554 this->mouseOverTransLogName->translation.setValue(
555 SbVec3f(xMouseLogName, yMouseLogName, 0.0));
556 this->mouseOverTransSolid->translation.setValue(
557 SbVec3f(xMouseSolid, yMouseSolid, 0.0));
558 this->mouseOverTransMaterial->translation.setValue(
559 SbVec3f(xMouseMaterial, yMouseMaterial, 0.0));
560 this->mouseOverTransZPos->translation.setValue(
561 SbVec3f(xMouseZPos, yMouseZPos, 0.0));
564 if (currentState == VIEWPOINT) {
565 this->curInfoFont->size.setValue(15);
566 this->curInfoFont->name.setValue(
"defaultFont:Italic");
567 this->curInfoText->string.setValue(SbString(curViewPtName));
569 else if(currentState == GENERAL) {
570 this->curInfoFont->size.setValue(16);
571 this->curInfoFont->name.setValue(
"defaultFont:Bold");
572 this->curInfoText->string.setValue(SbString(
""));
575 if (refParticleIdx < (
int) refParticleTrajectory.size() - 1) {
576 this->curInfoFont->size.setValue(16);
577 this->curInfoFont->name.setValue(
"defaultFont:Bold");
579 snprintf(zPos,
sizeof zPos,
"%7.2f [m]", refZPositions[refParticleIdx] / 1000);
580 this->curInfoText->string.setValue(SbString(zPos));
588 if (superimposition != NULL) {
589 removeSuperimposition(superimposition);
590 superimposition->unref();
591 superimposition = NULL;
593 if (animateSensor->isScheduled())
594 animateSensor->unschedule();
595 delete animateSensor;
596 delete sceneChangeSensor;
598 delete[] curViewPtName;
609 Atom WM_DELETE_WINDOW;
612 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::buildWidget",
"Error: Parent is null.");
615 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
616 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
617 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
618 XtSetArg(args[3], XmNbottomAttachment, XmATTACH_FORM);
619 Widget form = XmCreateForm(parent, (
char *)
"Form", args, 4);
622 shell = XtParent(form);
623 WM_DELETE_WINDOW = XInternAtom(XtDisplay(parent),
"WM_DELETE_WINDOW",
625 XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW,
626 (XtCallbackProc)closeMainWindowCB,
this);
628 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
629 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
630 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
631 menuBar = XmCreateMenuBar(form, (
char *)
"MenuBar", args, 3);
632 XtManageChild(menuBar);
635 this->
addButton(fileMenu,
"Open Viewpoint File...", openViewPtFileCB);
636 addButton(fileMenu,
"New Viewpoint File", newViewPtFileCB);
637 addButton(fileMenu,
"Load Ref. Coords", loadRefCoordsDialogCB);
638 addButton(fileMenu,
"Save Ref. Coords", saveRefCoordsDialogCB);
639 addButton(fileMenu,
"Load Scene Graph", loadSceneGraphDialogCB);
640 addButton(fileMenu,
"Save Scene Graph", saveSceneGraphDialogCB);
642 XmCreateSeparatorGadget(fileMenu, (
char *)
"Separator", NULL, 0));
644 Widget menu =
addMenu(
"Tools");
645 addButton(menu,
"Animate Ref. Particle", animateRefParticleCB);
646 addButton(menu,
"Go to start of Ref path", gotoRefPathStartCB);
647 addButton(menu,
"Invert Ref path", invertRefPathCB);
649 Widget viewerBase = SoXtFullViewer::buildWidget(form);
651 XtSetArg(args[0], XmNtopAttachment, XmATTACH_WIDGET);
652 XtSetArg(args[1], XmNtopWidget, menuBar);
653 XtSetArg(args[2], XmNleftAttachment, XmATTACH_FORM);
654 XtSetArg(args[3], XmNrightAttachment, XmATTACH_FORM);
655 XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM);
656 XtSetValues(viewerBase, args, 5);
666 Widget menu = XmCreatePulldownMenu(menuBar, (
char *) name.c_str(), NULL, 0);
668 XtSetArg(args[0], XmNsubMenuId, menu);
669 Widget w = XmCreateCascadeButton(menuBar, (
char *) name.c_str(), args, 1);
680 Widget button = XmCreatePushButton(menu, (
char *) name.c_str(), NULL, 0);
681 XtManageChild(button);
682 XtAddCallback(button, XmNactivateCallback, cb,
this);
688 SbPList * buttonlist)
692 Widget saveViewPtButton, abbrOutputButton, pickRefPathButton;
693 Widget switchWireFrameButton;
696 SoXtExaminerViewer::createViewerButtons(parent, buttonlist);
699 Widget emptyButton = XtVaCreateManagedWidget(
"", xmPushButtonWidgetClass,
701 buttonlist->append(emptyButton);
705 XtSetArg(args[n], XmNtopPosition, 1); n++;
706 XtSetArg(args[n], XmNbottomPosition, 2); n++;
707 XtSetArg(args[n], XmNleftPosition, 0); n++;
708 XtSetArg(args[n], XmNrightPosition, 1); n++;
709 XtSetArg(args[n], XmNarrowDirection, XmARROW_LEFT); n++;
710 XtSetArg(args[n], XmNsensitive, False); n++;
711 prevViewPtButton = XmCreateArrowButtonGadget(parent, (
char *)
"ArrowL",
713 XtManageChild(prevViewPtButton);
714 XtAddCallback(prevViewPtButton, XmNactivateCallback,
715 G4OpenInventorXtExaminerViewer::prevViewPtCB,
this);
716 buttonlist->append(prevViewPtButton);
720 XtSetArg(args[n], XmNtopPosition, 1); n++;
721 XtSetArg(args[n], XmNbottomPosition, 2); n++;
722 XtSetArg(args[n], XmNleftPosition, 0); n++;
723 XtSetArg(args[n], XmNrightPosition, 1); n++;
724 XtSetArg(args[n], XmNarrowDirection, XmARROW_RIGHT); n++;
725 XtSetArg(args[n], XmNsensitive, False); n++;
726 nextViewPtButton = XmCreateArrowButtonGadget(parent, (
char *)
"ArrowR",
728 XtManageChild(nextViewPtButton);
729 XtAddCallback(nextViewPtButton, XmNactivateCallback,
730 G4OpenInventorXtExaminerViewer::nextViewPtCB,
this);
731 buttonlist->append(nextViewPtButton);
734 saveViewPtButton = XtVaCreateManagedWidget(
"Save", xmPushButtonWidgetClass,
736 XtAddCallback(saveViewPtButton, XmNactivateCallback,
737 G4OpenInventorXtExaminerViewer::saveViewPtCB,
this);
738 Pixmap saveVP, saveVP_ins;
742 saveViewPt_xpm,
TRUE);
743 XtVaSetValues(saveViewPtButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
744 saveVP, XmNselectPixmap, saveVP, XmNlabelInsensitivePixmap,
745 saveVP_ins, XmNselectInsensitivePixmap, saveVP_ins, NULL);
746 buttonlist->append(saveViewPtButton);
749 abbrOutputButton = XtVaCreateManagedWidget(
"Abbr",
750 xmToggleButtonWidgetClass, parent, XmNindicatorOn, False, NULL);
751 XtAddCallback(abbrOutputButton, XmNdisarmCallback, G4OpenInventorXtExaminerViewer::abbrOutputCB,
753 Pixmap pickextxpm, pickextxpm_ins;
758 XtVaSetValues(abbrOutputButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
759 pickextxpm, XmNselectPixmap, pickextxpm, XmNlabelInsensitivePixmap,
760 pickextxpm_ins, XmNselectInsensitivePixmap, pickextxpm_ins, NULL);
769 buttonlist->append(abbrOutputButton);
772 pickRefPathButton = XtVaCreateManagedWidget(
"Refpath", xmPushButtonWidgetClass,
774 XtAddCallback(pickRefPathButton, XmNactivateCallback,
775 G4OpenInventorXtExaminerViewer::pickRefPathCB,
this);
776 Pixmap pickrefxpm, pickrefxpm_ins;
781 XtVaSetValues(pickRefPathButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
782 pickrefxpm, XmNselectPixmap, pickrefxpm, XmNlabelInsensitivePixmap,
783 pickrefxpm_ins, XmNselectInsensitivePixmap, pickrefxpm_ins, NULL);
785 buttonlist->append(pickRefPathButton);
788 switchWireFrameButton = XtVaCreateManagedWidget(
"Wireframe",
789 xmToggleButtonWidgetClass, parent, XmNindicatorOn, False, NULL);
790 XtAddCallback(switchWireFrameButton, XmNvalueChangedCallback,
791 G4OpenInventorXtExaminerViewer::switchWireFrameCB,
this);
792 Pixmap wireframe, wireframe_ins;
796 wireframe_xpm,
TRUE);
797 XtVaSetValues(switchWireFrameButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
798 wireframe, XmNselectPixmap, wireframe, XmNlabelInsensitivePixmap,
799 wireframe_ins, XmNselectInsensitivePixmap, wireframe_ins, NULL);
800 buttonlist->append(switchWireFrameButton);
808 SoXtExaminerViewer::afterRealizeHook();
812 SoCamera *cam = getCamera();
814 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
816 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
819 ((SoOrthographicCamera *) cam)->height.getValue();
823 ((SoOrthographicCamera *) cam)->height.getValue();
826 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
828 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
834 fileIn.open(fileName.c_str());
835 if (!fileIn.fail()) {
837 String dialogName = (
char *)
"Error Loading File";
838 std::string msg =
"Wrong or corrupted input file.";
842 fileOut.open(fileName.c_str(), std::ios::in);
843 fileOut.seekp(0, std::ios::end);
844 constructListsDialog(getParentWidget(),
this, NULL);
845 if (viewPtList.size()) {
849 XtSetSensitive(nextViewPtButton, True);
850 XtSetSensitive(prevViewPtButton, True);
856 fileOut.open(fileName.c_str());
857 constructListsDialog(getParentWidget(),
this, NULL);
862 SoSeparator *root = (SoSeparator *) (getSceneManager()->getSceneGraph());
864 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::afterRealizeHook",
"Root is null.");
866 root->addChild(myCam);
869 sceneChangeSensor =
new SoNodeSensor;
870 sceneChangeSensor->setFunction(sceneChangeCB);
871 sceneChangeSensor->attach(root);
872 sceneChangeSensor->setData(
this);
878 SoEventCallback *moCB =
new SoEventCallback;
879 moCB->addEventCallback(
880 SoLocation2Event::getClassTypeId(),
881 mouseoverCB,
static_cast<void *
>(
this));
882 root->addChild(moCB);
886 SoEventCallback *pickCB =
new SoEventCallback;
887 pickCB->addEventCallback(
888 SoMouseButtonEvent::getClassTypeId(),
889 pickingCB,
static_cast<void *
>(
this));
890 root->addChild(pickCB);
899 SoCamera *cam = getCamera();
905 SbVec3f camPosNew = prevPt - (
camDir*distance);
906 cam->position = camPosNew;
908 cam->focalDistance = (prevPt - camPosNew).length();
912 if (animateSensorRotation->isScheduled()) {
913 animateSensorRotation->unschedule();
916 animateSensorRotation->setBaseTime(SbTime::getTimeOfDay());
917 animateSensorRotation->setInterval(SbTime(0.02));
918 animateSensorRotation->schedule();
927 SoCamera *cam = getCamera();
928 SbVec3f p1(0), p2(0);
930 SbVec3f camPosNew(0);
932 if(refParticleTrajectory.size() == 0) {
937 distance = (cam->position.getValue() - center).length();
939 cam->position.setValue(center + offsetFromCenter*distance);
940 cam->focalDistance = (cam->position.getValue() - center).length();
941 cam->pointAt(center, upVector);
947 if (refParticleIdx >= (
int) refParticleTrajectory.size() - 1) {
948 prevPt = refParticleTrajectory[refParticleIdx - step];
949 dist = (prevPt - cam->position.getValue()).length();
954 if (refParticleIdx < 0) {
955 prevPt = refParticleTrajectory[refParticleIdx + step];
956 dist = (prevPt - cam->position.getValue()).length();
957 refParticleIdx = refParticleTrajectory.size() - 2;
961 p1 = refParticleTrajectory[refParticleIdx];
962 p2 = refParticleTrajectory[refParticleIdx + step];
965 particleDir = p2 - p1;
966 particleDir.normalize();
968 if(prevParticleDir == SbVec3f(0,0,0)){
979 SbRotation rot(SbVec3f(0,0,1), particleDir);
984 else if(particleDir != prevParticleDir) {
987 SbRotation rot(prevParticleDir, particleDir);
993 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
995 distance = (prevPt - cam->position.getValue()).length();
1009 float x(0.),y(0.),z(0.);
1010 prevPt.getValue(x,y,z);
1013 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1014 camPosNew = p2 - (
camDir*distance);
1016 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
1018 camPosNew = p2 - (
camDir*cam->focalDistance.getValue());
1022 cam->position = camPosNew;
1024 cam->focalDistance = (p2 - camPosNew).length();
1027 camPosNew.getValue(x,y,z);
1029 prevParticleDir = particleDir;
1037void G4OpenInventorXtExaminerViewer::pickingCB(
void *aThis,
1038 SoEventCallback *eventCB)
1040 SoHandleEventAction* action = eventCB->getAction();
1041 const SoPickedPoint *pp = action->getPickedPoint();
1046 SoPath* path = pp->getPath();
1047 SoNode* node = ((SoFullPath*)path)->getTail();
1049 if(node->getTypeId() == SoLineSet::getClassTypeId()){
1056 This->setComponentCursor(SoXtCursor(SoXtCursor::DEFAULT));
1059 SoLineSet * trajectory = (SoLineSet *)node;
1065 SoSeparator * grpNode =
1066 (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1071 int nodeIndex = grpNode->findChild(trajectory);
1074 SoCoordinate3 * coords = 0;
1078 for(
int i = 0; i < 100; ++i) {
1081 tmpNode = grpNode->getChild(nodeIndex);
1082 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()){
1084 coords = (SoCoordinate3 *)tmpNode;
1090 String dialogName = (
char *)
"No coordinates";
1091 std::string msg =
"Could not find the coordinates node"
1092 " for the picked trajectory."
1093 " Reference trajectory not set";
1099 if ((This->lshiftdown) || (This->rshiftdown))
1100 This->setReferencePath(trajectory, coords,
true);
1102 This->setReferencePath(trajectory, coords,
false);
1110 if(attHolder && attHolder->
GetAttDefs().size()) {
1112 std::string strTrajPoint =
"G4TrajectoryPoint:";
1113 std::ostringstream oss;
1114 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1119 if(oss.str().find(strTrajPoint) != std::string::npos) {
1134 G4String cls((
char*)node->getTypeId().getName().getString());
1135 G4cout <<
"SoNode : " << node
1136 <<
" SoType : " << cls
1137 <<
" name : " <<
name
1154 if(attHolder && attHolder->
GetAttDefs().size()) {
1155 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1161 G4String cls((
char*)node->getTypeId().getName().getString());
1162 G4cout <<
"SoNode : " << node
1163 <<
" SoType : " << cls
1164 <<
" name : " <<
name
1170 eventCB->setHandled();
1175void G4OpenInventorXtExaminerViewer::mouseoverCB(
void *aThis, SoEventCallback *eventCB)
1177 SoHandleEventAction* action = eventCB->getAction();
1178 const SoPickedPoint*
pp = action->getPickedPoint();
1186 const SbViewportRegion & viewportRegion = action->getViewportRegion();
1188 std::string sLogName;
1190 std::stringstream ssZPos;
1191 std::stringstream ssSolids;
1192 std::stringstream ssMaterials;
1193 SoPath * path =
pp->getPath();
1194 SoNode* node = ((SoFullPath*)path)->getTail();
1196 if(node->getTypeId() == Geant4_SoPolyhedron::getClassTypeId()) {
1198 sLogName =
"Logical Volume: ";
1201 SoGetBoundingBoxAction bAction(viewportRegion);
1202 bAction.apply((SoFullPath*)path);
1203 SbBox3f bBox = bAction.getBoundingBox();
1204 SbVec3f center = bBox.getCenter();
1205 center.getValue(x,y,z);
1206 ssZPos <<
"Pos: " << x <<
" " << y <<
" " << z;
1209 if(attHolder && attHolder->
GetAttDefs().size()) {
1211 std::vector<const std::map<G4String,G4AttDef>*> vecDefs =
1213 std::vector<const std::vector<G4AttValue>*> vecVals =
1215 for (
size_t i = 0; i < vecDefs.size(); ++i) {
1216 const std::vector<G4AttValue> * vals = vecVals[i];
1218 std::vector<G4AttValue>::const_iterator iValue;
1220 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1221 const G4String& valueName = iValue->GetName();
1222 const G4String& value = iValue->GetValue();
1224 if(valueName ==
"Solid") {
1225 if(ssSolids.str() ==
"")
1226 ssSolids <<
"Solid Name: " << value;
1228 ssSolids <<
", " << value;
1231 if(valueName ==
"Material") {
1232 if(ssMaterials.str() ==
"")
1233 ssMaterials <<
"Material Name: " << value;
1235 ssMaterials <<
", " << value;
1242 else if(node->getTypeId() == SoLineSet::getClassTypeId()) {
1245 if(attHolder && attHolder->
GetAttDefs().size()) {
1246 std::string strTrajPoint =
"G4TrajectoryPoint:";
1247 std::ostringstream oss;
1249 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1252 const std::vector<G4AttValue>* vals = attHolder->
GetAttValues()[i];
1253 std::vector<G4AttValue>::const_iterator iValue;
1254 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1255 const G4String& valueName = iValue->GetName();
1256 const G4String& value = iValue->GetValue();
1260 if (valueName ==
"PN") t1 = value;
1261 if (valueName ==
"Ch") {
1262 if (atof(value.c_str()) > 0)
1268 if (valueName ==
"PDG") {
1272 This->mouseOverTextLogName->string.setValue(t1);
1276 if (valueName ==
"EventID") t2 =
"Evt " + value;
1277 if (valueName ==
"ID") t2 +=
" Trk " + value;
1278 if (valueName ==
"PID") {
1279 t2 +=
" Prt " + value;
1280 This->mouseOverTextSolid->string.setValue(t2);
1283 if (valueName ==
"IKE") t3 =
"KE " + value;
1284 if (valueName ==
"IMom") {
1286 unsigned ipos = value.rfind(
" ");
1289 t3 +=
" P (" + value1 +
")";
1291 if (valueName ==
"IMag") {
1292 t3 +=
" " + value +
"/c";
1294 This->mouseOverTextMaterial->string.setValue(t3);
1297 if (valueName ==
"NTP") {
1298 std::ostringstream t4oss;
1299 t4oss <<
"TrjPts " << value;
1300 t4oss <<
" Pos " <<
pp->getPoint()[0] <<
" " <<
pp->getPoint()[1] <<
1301 " " <<
pp->getPoint()[2];
1302 This->mouseOverTextZPos->string.setValue(SbString(t4oss.str().c_str()));
1323 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
1324 This->scheduleRedraw();
1325 eventCB->setHandled();
1329 bool redraw =
false;
1330 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) != sLogName) {
1331 This->mouseOverTextLogName->string.setValue(SbString(sLogName.c_str()));
1334 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) != ssSolids.str()) {
1335 This->mouseOverTextSolid->string.setValue(SbString(ssSolids.str().c_str()));
1338 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) != ssMaterials.str()){
1339 This->mouseOverTextMaterial->string.setValue(SbString(ssMaterials.str().c_str()));
1342 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) != ssZPos.str()) {
1343 This->mouseOverTextZPos->string.setValue(SbString(ssZPos.str().c_str()));
1348 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
1349 This->scheduleRedraw();
1352 eventCB->setHandled();
1355 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) !=
"") {
1356 This->mouseOverTextLogName->string.setValue(SbString(
""));
1357 This->scheduleRedraw();
1359 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) !=
"") {
1360 This->mouseOverTextSolid->string.setValue(SbString(
""));
1361 This->scheduleRedraw();
1363 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) !=
"") {
1364 This->mouseOverTextMaterial->string.setValue(SbString(
""));
1365 This->scheduleRedraw();
1367 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) !=
"") {
1368 This->mouseOverTextZPos->string.setValue(SbString(
""));
1369 This->scheduleRedraw();
1376 SoCamera *cam = getCamera();
1377 const SoType type(ev->getTypeId());
1379 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
1380 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
1382 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1383 || currentState == PAUSED_ANIMATION) {
1384 switch (me->getButton()) {
1385 case SoMouseButtonEvent::BUTTON4:
1386 if (me->getState() == SoButtonEvent::DOWN) {
1387 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1389 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1390 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1393 }
else if (cam->isOfType(
1394 SoOrthographicCamera::getClassTypeId())) {
1396 ((SoOrthographicCamera *) cam)->height.getValue();
1397 ((SoOrthographicCamera *) cam)->height = height + 5;
1402 case SoMouseButtonEvent::BUTTON5:
1403 if (me->getState() == SoButtonEvent::DOWN) {
1404 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1406 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1408 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1411 }
else if (cam->isOfType(
1412 SoOrthographicCamera::getClassTypeId())) {
1414 ((SoOrthographicCamera *) cam)->height.getValue();
1416 ((SoOrthographicCamera *) cam)->height = height - 5;
1425 if (currentState == GENERAL) {
1430 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
1431 SoKeyboardEvent * ke = (SoKeyboardEvent *) ev;
1433 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
1434 switch (ke->getKey()) {
1435 case SoKeyboardEvent::LEFT_SHIFT:
1436 this->lshiftdown =
true;
1438 case SoKeyboardEvent::RIGHT_SHIFT:
1439 this->rshiftdown =
true;
1441 case SoKeyboardEvent::LEFT_CONTROL:
1442 this->lctrldown =
true;
1444 case SoKeyboardEvent::RIGHT_CONTROL:
1445 this->rctrldown =
true;
1447 case SoKeyboardEvent::SPACE:
1448 if (currentState == ANIMATION
1449 || currentState == REVERSED_ANIMATION) {
1450 beforePausing = currentState;
1451 currentState = PAUSED_ANIMATION;
1452 if (animateSensor->isScheduled())
1453 animateSensor->unschedule();
1455 }
else if (currentState == PAUSED_ANIMATION) {
1457 if ((beforePausing == ANIMATION
1459 < (
int) refParticleTrajectory.size() - 1)
1460 || (beforePausing == REVERSED_ANIMATION
1461 && refParticleIdx > 0)) {
1462 currentState = beforePausing;
1463 animateRefParticle();
1469 case SoKeyboardEvent::ESCAPE:
1470 if (currentState == ANIMATION
1471 || currentState == REVERSED_ANIMATION
1472 || currentState == PAUSED_ANIMATION) {
1474 if (animateSensor->isScheduled())
1475 animateSensor->unschedule();
1476 currentState = prevState;
1477 refParticleIdx = prevRefIdx;
1478 setSuperimpositionEnabled(superimposition,
FALSE);
1483 if (currentState == VIEWPOINT) {
1484 setSuperimpositionEnabled(superimposition,
TRUE);
1485 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
1486 animSpeedOutlineSwitch->whichChild.setValue(
1488 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1496 case SoKeyboardEvent::DELETE:
1497 if (viewPtList.size()
1498 && (currentState != ANIMATION
1499 && currentState != REVERSED_ANIMATION
1500 && currentState != PAUSED_ANIMATION)) {
1501 String dialogName = (
char *)
"Delete Viewpoint";
1502 std::string msg =
"Are you sure you want to delete current viewpoint?";
1507 case SoKeyboardEvent::LEFT_ARROW:
1508 switch (currentState) {
1510 if ((this->lshiftdown) || (this->rshiftdown)){
1511 refParticleIdx -= step;
1514 else if ((this->lctrldown) || (this->rctrldown)){
1515 if (SoXtExaminerViewer::isAnimating())
1517 prevState = currentState;
1518 currentState = ROTATING;
1519 animateBtwPtsPeriod = 0.08f;
1531 if (SoXtExaminerViewer::isAnimating())
1533 prevState = currentState;
1534 currentState = ROTATING;
1535 animateBtwPtsPeriod = 0.08f;
1550 case REVERSED_ANIMATION:
1553 case PAUSED_ANIMATION:
1555 setStartingPtForAnimation();
1556 cam->position = myCam->position;
1560 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1563 this->bottomWheelMotion(
1564 this->getBottomWheelValue() + 0.1f);
1574 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1575 "Unhandled viewer state");
1580 case SoKeyboardEvent::RIGHT_ARROW:
1581 switch(currentState){
1583 if ((this->lshiftdown) || (this->rshiftdown)){
1584 refParticleIdx += step;
1587 else if ((this->lctrldown) || (this->rctrldown)){
1588 if (SoXtExaminerViewer::isAnimating())
1590 prevState = currentState;
1591 currentState = ROTATING;
1592 animateBtwPtsPeriod = 0.08f;
1602 if (SoXtExaminerViewer::isAnimating())
1604 prevState = currentState;
1605 currentState = ROTATING;
1606 animateBtwPtsPeriod = 0.08f;
1618 case REVERSED_ANIMATION:
1621 case PAUSED_ANIMATION:
1623 setStartingPtForAnimation();
1624 cam->position = myCam->position;
1628 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1631 this->bottomWheelMotion(
1632 this->getBottomWheelValue() - 0.1f);
1641 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1642 "Unhandled viewer state");
1647 case SoKeyboardEvent::DOWN_ARROW:
1648 switch(currentState){
1651 if ((this->lshiftdown) || (this->rshiftdown)){
1652 refParticleIdx -= step;
1656 if (SoXtExaminerViewer::isAnimating())
1658 prevState = currentState;
1659 currentState = ROTATING;
1660 animateBtwPtsPeriod = 0.08f;
1673 case REVERSED_ANIMATION:
1676 case PAUSED_ANIMATION:
1678 setStartingPtForAnimation();
1679 cam->position = myCam->position;
1685 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1686 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
1695 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1696 "Unhandled viewer state");
1701 case SoKeyboardEvent::UP_ARROW:
1702 switch(currentState){
1704 if ((this->lshiftdown) || (this->rshiftdown)){
1705 refParticleIdx -= step;
1709 if (SoXtExaminerViewer::isAnimating())
1711 prevState = currentState;
1712 currentState = ROTATING;
1713 animateBtwPtsPeriod = 0.08f;
1726 case REVERSED_ANIMATION:
1729 case PAUSED_ANIMATION:
1731 setStartingPtForAnimation();
1732 cam->position = myCam->position;
1738 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1739 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
1748 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1749 "Unhandled viewer state");
1754 case SoKeyboardEvent::PAGE_UP:
1755 switch(currentState){
1757 if (step < (
int) refParticleTrajectory.size() / 5)
1768 case REVERSED_ANIMATION:
1769 if(!animateSensor->isScheduled()){
1770 currentState = ANIMATION;
1772 < (
int) refParticleTrajectory.size() - 1) {
1776 animateRefParticle();
1785 case PAUSED_ANIMATION:
1790 if (beforePausing == ANIMATION) {
1795 beforePausing = ANIMATION;
1805 case SoKeyboardEvent::PAGE_DOWN:
1806 switch(currentState){
1812 if(!animateSensor->isScheduled()){
1813 currentState = REVERSED_ANIMATION;
1814 if (refParticleIdx > 1) {
1818 animateRefParticle();
1827 case REVERSED_ANIMATION:
1830 if (maxSpeed < -0.8)
1834 case PAUSED_ANIMATION:
1836 if (maxSpeed < -0.8)
1838 if (beforePausing == REVERSED_ANIMATION) {
1843 beforePausing = REVERSED_ANIMATION;
1853 case SoKeyboardEvent::E:
1854 this->escapeCallback(this->examinerObject);
1861 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
1862 switch (ke->getKey()) {
1863 case SoKeyboardEvent::LEFT_SHIFT:
1864 this->lshiftdown =
false;
1866 case SoKeyboardEvent::RIGHT_SHIFT:
1867 this->rshiftdown =
false;
1869 case SoKeyboardEvent::LEFT_CONTROL:
1870 this->lctrldown =
false;
1872 case SoKeyboardEvent::RIGHT_CONTROL:
1873 this->rctrldown =
false;
1881 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1882 || currentState == ROTATING)
1885 return SoXtExaminerViewer::processSoEvent(ev);
1889void G4OpenInventorXtExaminerViewer::incSpeed() {
1890 if (std::ceil(animateBtwPtsPeriod * 100) >= 4) {
1891 if (speedStep > 0.08)
1895 animateBtwPtsPeriod -= speedStep;
1897 animateBtwPtsPeriod = 0.0;
1899 if (currentState != PAUSED_ANIMATION) {
1900 int lastIdx = refParticleTrajectory.size() - 1;
1901 if (refParticleIdx < lastIdx && !animateSensor->isScheduled())
1902 animateRefParticle();
1907void G4OpenInventorXtExaminerViewer::decSpeed() {
1908 animateBtwPtsPeriod += speedStep;
1910 if (std::floor(animateBtwPtsPeriod * 100) == 12) {
1912 }
else if (animateBtwPtsPeriod > 0.12)
1918 if (animateSensor->isScheduled())
1919 animateSensor->unschedule();
1924void G4OpenInventorXtExaminerViewer::updateSpeedIndicator(
void) {
1925 assert(this->sgeometry != NULL);
1927 SbVec3f * points = this->sgeometry->point.startEditing();
1929 if (points[10][0] == 0.0f)
1930 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
1931 if (points[14][0] == 0.0f)
1932 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
1933 points[10][0] = this->maxSpeed;
1934 points[11][0] = this->maxSpeed;
1935 points[14][0] = this->maxSpeed;
1936 points[15][0] = this->maxSpeed;
1937 this->sgeometry->point.finishEditing();
1939 if (this->maxSpeed == 0.0f) {
1940 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
1941 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1945void G4OpenInventorXtExaminerViewer::actualRedraw(
void) {
1946 switch (currentState) {
1948 case REVERSED_ANIMATION:
1949 case PAUSED_ANIMATION:
1950 updateSpeedIndicator();
1951 SoXtExaminerViewer::actualRedraw();
1954 SoXtExaminerViewer::actualRedraw();
1959void G4OpenInventorXtExaminerViewer::setReferencePath(SoLineSet *lineset, SoCoordinate3 *coords,
bool append)
2000 SbVec3f refParticlePt;
2003 this->refParticleTrajectory.clear();
2005 for(
int i = 0; i < lineset->numVertices.getNum(); ++i){
2006 for(
int j = 0; j < lineset->numVertices[i]; ++j){
2007 refParticlePt = coords->point[j];
2008 this->refParticleTrajectory.push_back(refParticlePt);
2012 this->evenOutRefParticlePts();
2013 this->setReferencePathZPos();
2014 this->sortElements();
2018void G4OpenInventorXtExaminerViewer::setReferencePathZPos()
2020 refZPositions.clear();
2021 refZPositions.push_back(0);
2023 for(
unsigned int i=0; i < this->refParticleTrajectory.size() - 1; ++i){
2024 dist = (refParticleTrajectory[i] -
2025 refParticleTrajectory[i + 1]).length();
2026 refZPositions.push_back(refZPositions[i] + dist);
2031void G4OpenInventorXtExaminerViewer::findAndSetRefPath()
2033 SoSearchAction action;
2034 action.setType(SoLineSet::getClassTypeId(),
false);
2035 action.setInterest(SoSearchAction::ALL);
2036 action.apply(this->getSceneGraph());
2038 SoPathList &pathList = action.getPaths();
2040 if(pathList.getLength() != 0){
2042 SoCoordinate3 * coords = NULL;
2043 std::vector<SoCoordinate3 *> coordvec;
2044 std::vector<SoLineSet *> linevec;
2046 bool refPathFound =
false;
2047 for(
int i = 0; i < pathList.getLength(); ++i) {
2048 SoFullPath *path = (SoFullPath *)pathList[i];
2051 for (
size_t j = 0; j < attHolder->
GetAttDefs().size(); ++j) {
2052 std::ostringstream oss;
2055 std::string findStr =
"Type of trajectory (Type): ";
2056 std::string compareValue =
"REFERENCE";
2057 size_t idx = oss.str().find(findStr);
2059 if(idx != std::string::npos) {
2060 if(oss.str().substr(idx + findStr.size(), compareValue.size()) == compareValue) {
2061 coords = this->getCoordsNode(path);
2063 refPathFound =
true;
2064 coordvec.push_back(coords);
2065 linevec.push_back((SoLineSet *)path->getTail());
2071 findStr =
"Track ID (ID): ";
2072 idx = oss.str().find(findStr);
2073 if(idx != std::string::npos) {
2075 std::string tmpstr = oss.str().substr(idx + findStr.size(),1);
2076 std::istringstream buffer(tmpstr);
2084 char nextChar = oss.str().at(idx+findStr.size()+1);
2087 if(std::isdigit(nextChar))
2091 coords = this->getCoordsNode(path);
2093 coordvec.push_back(coords);
2094 linevec.push_back((SoLineSet *)path->getTail());
2110 if(coordvec.empty())
2115 this->setReferencePath(linevec.back(), coordvec.back());
2121 float longestLength = 0.0;
2123 for(
unsigned int i=0;i < linevec.size(); ++i){
2126 std::vector<SbVec3f> trajectory;
2128 for(
int j=0; j < linevec[i]->numVertices.getNum(); ++j){
2130 for(
int k=0; k < linevec[i]->numVertices[j]; ++k){
2131 trajectory.push_back(coordvec[i]->point[k]);
2136 float tmpLength=0.0;
2137 for(
unsigned int j=0; j < trajectory.size() - 1; ++j){
2138 tmpLength += (trajectory[j] - trajectory[j + 1]).length();
2141 if(tmpLength > longestLength){
2143 longestLength = tmpLength;
2148 this->setReferencePath(linevec[longestIdx], coordvec[longestIdx]);
2153SoCoordinate3 * G4OpenInventorXtExaminerViewer::getCoordsNode(SoFullPath *path)
2155 SoLineSet *trajectory = (SoLineSet *)path->getTail();
2156 SoSeparator * grpNode = (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
2157 int nodeIndex = grpNode->findChild(trajectory);
2162 for(
int i = 0; i < 100; ++i){
2165 tmpNode = grpNode->getChild(nodeIndex);
2166 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()){
2168 return (SoCoordinate3 *)tmpNode;
2177void G4OpenInventorXtExaminerViewer::getSceneElements()
2179 std::string field, eltName;
2181 std::map<std::string, int> duplicates;
2182 std::map<std::string, int> sceneElts;
2183 SoSearchAction search;
2185 SoGroup *root = (SoGroup *)getSceneManager()->getSceneGraph();
2187 SoBaseKit::setSearchingChildren(
TRUE);
2190 search.setSearchingAll(
TRUE);
2191 search.setInterest(SoSearchAction::ALL);
2192 search.setType(Geant4_SoPolyhedron::getClassTypeId(), 0);
2195 SoPathList &pl = search.getPaths();
2199 for(
int i = 0; i < pl.getLength(); i++) {
2200 SoFullPath *path = (SoFullPath *)pl[i];
2202 eltName = node->getName();
2203 if(duplicates.count(eltName))
2204 duplicates[eltName]++;
2206 duplicates[eltName] = 1;
2209 for(
int i = 0; i < pl.getLength(); i++) {
2211 std::stringstream ssCount;
2212 SoFullPath *path = (SoFullPath *)pl[i];
2214 eltName = node->getName();
2216 if(duplicates[eltName] == 1)
2219 if(sceneElts.count(eltName))
2220 sceneElts[eltName]++;
2222 sceneElts[eltName] = 1;
2224 ssCount << sceneElts[eltName];
2228 field += ssCount.str();
2230 SoGetBoundingBoxAction bAction(getViewportRegion());
2231 bAction.apply(path);
2232 SbBox3f bBox = bAction.getBoundingBox();
2234 SbVec3f centr = bBox.getCenter();
2235 centr.getValue(x,y,z);
2238 sceneElement el = { field, path, centr, 0.0 };
2239 this->sceneElements.push_back(el);
2244float G4OpenInventorXtExaminerViewer::sqrlen(
const SbVec3f &a)
2248 return x*x + y*y + z*z;
2252void G4OpenInventorXtExaminerViewer::distanceToTrajectory(
const SbVec3f &q,
2254 SbVec3f &closestPoint,
2289 const size_t count = this->refParticleTrajectory.size();
2292 SbVec3f b = this->refParticleTrajectory[0];
2293 SbVec3f dbq = b - q;
2294 float sqrDist = sqrlen(dbq);
2297 for (
size_t i = 1; i < count; ++i) {
2298 const SbVec3f a = b;
2299 const SbVec3f daq = dbq;
2300 b = this->refParticleTrajectory[i];
2302 const SbVec3f dab = a - b;
2304 float dab_x, dab_y, dab_z;
2305 dab.getValue(dab_x,dab_y,dab_z);
2306 float daq_x, daq_y, daq_z;
2307 daq.getValue(daq_x, daq_y, daq_z);
2308 float dbq_x, dbq_y, dbq_z;
2309 dbq.getValue(dbq_x, dbq_y, dbq_z);
2311 const float inv_sqrlen = 1./sqrlen(dab);
2312 const float t = (dab_x*daq_x + dab_y*daq_y + dab_z*daq_z)*inv_sqrlen;
2323 current_dist = daq_x*daq_x + daq_y*daq_y + daq_z*daq_z
2324 - t*(daq_x*dab_x + daq_y*dab_y + daq_z*dab_z)
2325 + t*t*(dab_x*dab_x + dab_y*dab_y + dab_z*dab_z);
2330 current_dist = sqrlen(dbq);
2333 if (current_dist < sqrDist){
2334 sqrDist = current_dist;
2335 closestPoint = a + t*(b-a);
2340 dist = std::sqrt(sqrDist);
2344void G4OpenInventorXtExaminerViewer::sortElements()
2346 if(this->refParticleTrajectory.empty())
2349 float * trajLength =
new float[this->refParticleTrajectory.size()];
2350 typedef std::map<elementForSorting, sceneElement> sortedMap;
2356 std::vector<SbVec3f>::iterator itRef = this->refParticleTrajectory.begin();
2359 trajLength[trajIndex] = 0.0;
2362 for(; itRef != this->refParticleTrajectory.end(); ++itRef, ++trajIndex){
2363 trajLength[trajIndex] = trajLength[trajIndex-1] + (*itRef - prevPoint).length();
2371 SoGetBoundingBoxAction bAction(this->getViewportRegion());
2372 SbVec3f elementCoord;
2373 std::vector<sceneElement>::iterator itEl;
2375 elementForSorting el;
2376 for(itEl = this->sceneElements.begin(), elementIndex = 0;
2377 itEl != this->sceneElements.end(); ++itEl, ++elementIndex){
2378 bAction.apply(itEl->path);
2381 elementCoord = itEl->center;
2390 distanceToTrajectory(elementCoord, el.smallestDistance, el.closestPoint, index);
2391 itEl->closestPointZCoord = el.closestPointZCoord = trajLength[index];
2392 el.distanceToBeamlineStart = (itEl->center - this->refParticleTrajectory[0]).length();
2399 sorted.insert(std::make_pair(el,*itEl));
2403 this->sceneElements.clear();
2405 sortedMap::iterator itSorted = sorted.begin();
2406 for(; itSorted != sorted.end(); itSorted++)
2407 this->sceneElements.push_back(itSorted->second);
2409 this->zcoordSetFlag =
true;
2412 Widget formTop = XtNameToWidget(this->listsDialog,
"FormTop");
2413 Widget formTopRight = XtNameToWidget(formTop,
"FormTopRight");
2415 this->createElementsList(formTopRight);
2417 delete[] trajLength;
2421void G4OpenInventorXtExaminerViewer::createElementsList(Widget formTopRight)
2423 if(this->myElementList != NULL)
2424 XtUnmanageChild(this->myElementList);
2426 int size = this->sceneElements.size();
2427 XmString *elements = (XmString *) XtMalloc(size *
sizeof(XmString));
2429 std::vector<sceneElement>::const_iterator it;
2431 std::stringstream ss;
2432 for(it=this->sceneElements.begin(); it!=this->sceneElements.end(); ++it) {
2435 ss <<
" [" << it->closestPointZCoord <<
"]";
2436 elements[count] = XmStringCreateLocalized((
char *)ss.str().c_str());
2447 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2449 labelRight = XmCreateLabelGadget(formTopRight, (
char*)
"Element [S mm]",
2451 XtManageChild(labelRight);
2455 XtSetArg(args[n], XmNvisibleItemCount, 7);
n++;
2456 XtSetArg(args[n], XmNitemCount, size);
n++;
2457 XtSetArg(args[n], XmNitems, elements);
n++;
2458 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2459 XtSetArg(args[n], XmNtopWidget, labelRight);
n++;
2460 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2461 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2463 XtSetArg(args[n], XmNwidth, 240);
n++;
2467 this->myElementList = XmCreateScrolledList(formTopRight, (
char *)
"ListRight", args, n);
2469 XtAddCallback(this->myElementList, XmNbrowseSelectionCallback,
2470 (XtCallbackProc) lookAtSceneElementCB,
this);
2472 XtManageChild(this->myElementList);
2474 if (elements != NULL) {
2475 for (
int i = 0; i < size; i++)
2476 XmStringFree(elements[i]);
2477 XtFree((
char *) elements);
2485void G4OpenInventorXtExaminerViewer::constructListsDialog(Widget w,
2486 XtPointer client_data,
2491 if (This->listsDialog) {
2495 if (This->currentState == ANIMATION || This->currentState == PAUSED_ANIMATION) {
2496 if (This->animateSensor->isScheduled())
2497 This->animateSensor->unschedule();
2498 This->refParticleIdx = This->prevRefIdx;
2499 This->restoreCamera();
2500 This->currentState = This->prevState;
2504 This->refParticleIdx = 0;
2505 if (This->refParticleTrajectory.size()){
2506 This->prevPt = This->refParticleTrajectory[0];
2509 This->getSceneElements();
2513 Atom WM_DELETE_WINDOW;
2525 std::string dialogNameStr = This->fileName.substr(This->fileName.rfind(
'/') + 1);
2526 const int nDialog = dialogNameStr.size() + 1;
2527 char *dialogName =
new char[nDialog];
2528 strncpy(dialogName, dialogNameStr.c_str(), nDialog);
2531 XtSetArg(args[n], XmNx, 610);
n++;
2532 This->myShellDialog = XmCreateDialogShell(topShell, dialogName, args, n);
2534 delete[] dialogName;
2535 WM_DELETE_WINDOW = XInternAtom(XtDisplay(w),
"WM_DELETE_WINDOW", False);
2536 XmAddWMProtocolCallback(This->myShellDialog, WM_DELETE_WINDOW,
2537 (XtCallbackProc)closeListsDialogCB, This);
2541 XtSetArg(args[n], XmNsashWidth, 1);
n++;
2542 XtSetArg(args[n], XmNsashHeight, 1);
n++;
2543 XtSetArg(args[n], XmNseparatorOn, False);
n++;
2545 This->listsDialog = XmCreatePanedWindow(This->myShellDialog, (
char *)
"MainPane",
2553 Widget formTop = XmCreateForm(This->listsDialog, (
char *)
"FormTop", args, n);
2556 XtSetArg(args[n], XmNmarginWidth, 8);
n++;
2557 XtSetArg(args[n], XmNmarginHeight, 8);
n++;
2558 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2559 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2560 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2561 Widget formTopRight = XmCreateForm(formTop, (
char *)
"FormTopRight", args,
2565 XtSetArg(args[n], XmNmarginWidth, 8);
n++;
2566 XtSetArg(args[n], XmNmarginHeight, 8);
n++;
2567 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2568 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2569 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET);
n++;
2570 XtSetArg(args[n], XmNrightWidget, formTopRight);
n++;
2571 XtSetArg(args[n], XmNrightOffset, 10);
n++;
2572 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2573 Widget formTopLeft = XmCreateForm(formTop, (
char *)
"FormTopLeft", args, n);
2577 This->createElementsList(formTopRight);
2578 XtManageChild(formTopRight);
2584 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2585 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2586 Widget labelLeft = XmCreateLabelGadget(formTopLeft, (
char *)
"ViewPoints",
2588 XtManageChild(labelLeft);
2592 XtSetArg(args[n], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE);
n++;
2593 XtSetArg(args[n], XmNvisibleItemCount, 7);
n++;
2595 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2596 XtSetArg(args[n], XmNtopWidget, labelLeft);
n++;
2597 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET);
n++;
2598 XtSetArg(args[n], XmNrightWidget, This->myElementList);
n++;
2599 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2600 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2602 XtSetArg(args[n], XmNwidth, 160);
n++;
2605 This->myViewPtList = XmCreateScrolledList(formTopLeft, (
char *)
"ListLeft",
2607 if (This->viewPtList.size())
2608 This->addViewPoints();
2609 XtAddCallback(This->myViewPtList, XmNbrowseSelectionCallback,
2610 (XtCallbackProc) loadBookmarkCB, This);
2613 XtManageChild(This->myViewPtList);
2615 XtManageChild(formTopLeft);
2617 XtManageChild(formTop);
2621 XtSetArg(args[n], XmNmarginWidth, 6);
n++;
2624 Widget formMiddle = XmCreateForm(This->listsDialog, (
char *)
"MiddleForm", args, n);
2628 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2629 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2630 XtSetArg(args[n], XmNtopWidget, This->myViewPtList);
n++;
2631 Widget label = XmCreateLabelGadget(formMiddle, (
char *)
"Selection", args,
2633 XtManageChild(label);
2637 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2638 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2639 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2640 XtSetArg(args[n], XmNtopWidget, label);
n++;
2641 XtSetArg(args[n], XmNtopOffset, 3);
n++;
2642 XtSetArg(args[n], XmNmaxLength, This->MAX_VP_NAME);
n++;
2643 This->viewPtSelection = XmCreateText(formMiddle, (
char *)
"Txt", args, n);
2644 XtManageChild(This->viewPtSelection);
2646 Dimension h1, h2, h;
2647 XtVaGetValues(label, XmNheight, &h1, NULL);
2648 XtVaGetValues(This->viewPtSelection, XmNheight, &h2, NULL);
2650 h = (Dimension) (1.1 * (h1 + h2));
2652 XtVaSetValues(formMiddle, XmNpaneMaximum, h, XmNpaneMinimum, h, NULL);
2653 XtManageChild(formMiddle);
2658 XtSetArg(args[n], XmNfractionBase, 4);
n++;
2659 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2660 XtSetArg(args[n], XmNtopWidget, This->viewPtSelection);
n++;
2663 Widget formAction = XmCreateForm(This->listsDialog, (
char *)
"ActionForm", args, n);
2666 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2667 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2668 XtSetArg(args[n], XmNtopOffset, 3);
n++;
2669 XtSetArg(args[n], XmNbottomOffset, 5);
n++;
2670 Widget separator = XmCreateSeparatorGadget(formAction, (
char *)
"Sep", args, n);
2672 XtManageChild(separator);
2674 Widget button = XmCreatePushButton(formAction, (
char *)
"Delete", NULL, 0);
2675 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2676 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2677 XmATTACH_POSITION, XmNleftPosition, 0, XmNrightAttachment,
2678 XmATTACH_POSITION, XmNrightPosition, 1,
2679 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2682 XtAddCallback(button, XmNactivateCallback,
2683 (XtCallbackProc) deleteBookmarkCB, This);
2684 XtManageChild(button);
2686 button = XmCreatePushButton(formAction, (
char *)
"Rename", NULL, 0);
2687 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2688 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2689 XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment,
2690 XmATTACH_POSITION, XmNrightPosition, 2,
2691 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2694 XtAddCallback(button, XmNactivateCallback,
2695 (XtCallbackProc) renameBookmarkCB, This);
2696 XtManageChild(button);
2698 button = XmCreatePushButton(formAction, (
char *)
"Sort", NULL, 0);
2699 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2700 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2701 XmATTACH_POSITION, XmNleftPosition, 2, XmNrightAttachment,
2702 XmATTACH_POSITION, XmNrightPosition, 3,
2703 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2706 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc) sortBookmarksCB, This);
2707 XtManageChild(button);
2709 button = XmCreatePushButton(formAction, (
char *)
"Close", NULL, 0);
2710 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2711 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2712 XmATTACH_POSITION, XmNleftPosition, 3, XmNrightAttachment,
2713 XmATTACH_POSITION, XmNrightPosition, 4,
2714 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2717 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc) closeListsDialogCB, This);
2718 XtManageChild(button);
2720 XtManageChild(formAction);
2721 XtVaGetValues(button, XmNheight, &h1, NULL);
2722 XtVaSetValues(formAction, XmNpaneMaximum, h1, XmNpaneMinimum, h1, NULL);
2724 XtManageChild(This->listsDialog);
2732void G4OpenInventorXtExaminerViewer::lookAtSceneElementCB(Widget,
2733 XtPointer client_data,
2734 XtPointer call_data)
2737 std::string elementField;
2739 SoCamera * cam = This->getCamera();
2741 if (This->SoXtExaminerViewer::isAnimating())
2742 This->stopAnimating();
2744 XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
2746 value = (
char *) XmStringUnparse(cbs->item, XmFONTLIST_DEFAULT_TAG,
2747 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
2748 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
2749 || This->currentState == PAUSED_ANIMATION ) {
2750 if (This->animateSensor->isScheduled())
2751 This->animateSensor->unschedule();
2752 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
2753 This->maxSpeed = 0.0f;
2754 This->scheduleRedraw();
2755 This->restoreCamera();
2756 This->currentState = This->prevState;
2757 }
else if (This->currentState == VIEWPOINT)
2758 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
2760 elementField = value;
2762 int idx = elementField.find_last_of(
"[");
2764 idx = elementField.size();
2770 SoSearchAction search;
2771 SoNode *root = This->getSceneManager()->getSceneGraph();
2772 int counter(1), idxUnderscore = elementField.find_last_of(
"_");
2774 This->
parseString<
int>(counter, elementField.substr(idxUnderscore + 1, idx), error);
2776 SoBaseKit::setSearchingChildren(
TRUE);
2778 search.setSearchingAll(
TRUE);
2781 This->
curEltName = elementField.substr(0, idx);
2785 path = (SoFullPath *)search.getPath();
2788 This->
curEltName = elementField.substr(0, idxUnderscore);
2789 search.setInterest(SoSearchAction::ALL);
2793 SoPathList &pl = search.getPaths();
2794 path = (SoFullPath *)pl[counter - 1];
2799 if ((idx > 0) && (path)) {
2801 if(!This->refParticleTrajectory.empty()){
2803 SoGetBoundingBoxAction bAction(This->getViewportRegion());
2804 bAction.apply(path);
2805 SbBox3f bBox = bAction.getBoundingBox();
2806 SbVec3f elementCoord = bBox.getCenter();
2808 This->refParticleIdx = 0;
2811 float absLengthNow, absLengthMin;
2812 int maxIdx = This->refParticleTrajectory.size() - 2;
2816 p = This->refParticleTrajectory[This->refParticleIdx];
2817 absLengthMin = (p - elementCoord).length();
2818 This->refParticleIdx++;
2821 while (This->refParticleIdx < maxIdx) {
2822 p = This->refParticleTrajectory[This->refParticleIdx];
2823 absLengthNow = (p - elementCoord).length();
2825 if (absLengthNow < absLengthMin) {
2826 absLengthMin = absLengthNow;
2827 targetIdx = This->refParticleIdx;
2829 This->refParticleIdx++;
2832 if (This->currentState != BEAMLINE) {
2834 This->currentState = BEAMLINE;
2835 This->prevParticleDir = SbVec3f(0,0,0);
2837 p1 = This->prevPt = This->refParticleTrajectory[0];
2838 pN = This->refParticleTrajectory[This->refParticleTrajectory.size() - 1];
2839 This->distance = (pN - p1).length() / 10;
2851 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2852 ((SoPerspectiveCamera*)cam)->heightAngle.setValue(This->defaultHeightAngle);
2855 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2856 This->distance = (This->prevPt - cam->position.getValue()).length();
2858 This->refParticleIdx = targetIdx;
2861 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
2862 This->axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2863 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2864 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2865 This->scheduleRedraw();
2874 This->offsetFromCenter.setValue(0, 0, 1);
2875 This->distance = 50;
2876 This->upVector.setValue(0, 1, 0);
2878 cam->viewAll(path, This->getViewportRegion());
2882 XmTextSetString(This->viewPtSelection, NULL);
2888void G4OpenInventorXtExaminerViewer::closeListsDialogCB(Widget,
2889 XtPointer client_data,
2894 This->sceneElements.clear();
2895 This->refParticleTrajectory.clear();
2897 This->currentState = GENERAL;
2898 XtDestroyWidget(This->myShellDialog);
2899 This->listsDialog = NULL;
2903void G4OpenInventorXtExaminerViewer::prevViewPtCB(Widget, XtPointer client_data,
2907 if (This->viewPtIdx == 0)
2908 This->viewPtIdx = This->viewPtList.size() - 1;
2912 This->writeViewPtIdx();
2917void G4OpenInventorXtExaminerViewer::nextViewPtCB(Widget, XtPointer client_data,
2921 if (This->viewPtIdx >= (
int) This->viewPtList.size() - 1)
2922 This->viewPtIdx = 0;
2926 This->writeViewPtIdx();
2933void G4OpenInventorXtExaminerViewer::writeViewPtIdx()
2936 std::stringstream out;
2939 fileOut.seekp(0, std::ios::beg);
2941 while ((
int) idxStr.length() < MAX_VP_IDX) {
2945 fileOut << idxStr <<
"\n";
2947 fileOut.seekp(0, std::ios::end);
2953void G4OpenInventorXtExaminerViewer::setViewPt()
2955 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
2956 || currentState == ROTATING) {
2958 if (animateSensor->isScheduled())
2959 animateSensor->unschedule();
2960 setSuperimpositionEnabled(superimposition,
FALSE);
2965 SoCamera * camera = getCamera();
2966 if (camera == NULL) {
2967 String dialogName = (
char *)
"Missing Camera Node";
2968 std::string msg =
"Camera is null. Unable to set the viewpoint.";
2973 if (!viewPtList.size()) {
2974 String dialogName = (
char *)
"Missing Viewpoints";
2975 std::string msg =
"There are no viewpoints to load.";
2980 if (SoXtExaminerViewer::isAnimating())
2983 if (currentState != VIEWPOINT) {
2984 currentState = VIEWPOINT;
2986 setSuperimpositionEnabled(superimposition,
TRUE);
2987 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2988 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2989 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2995 curViewPtName = viewPtList[viewPtIdx].viewPtName;
2996 camera->viewportMapping = viewPtList[viewPtIdx].viewportMapping;
2997 camera->position = viewPtList[viewPtIdx].position;
2998 camera->orientation = viewPtList[viewPtIdx].orientation;
2999 camera->aspectRatio = viewPtList[viewPtIdx].aspectRatio;
3000 camera->nearDistance = viewPtList[viewPtIdx].nearDistance;
3001 camera->farDistance = viewPtList[viewPtIdx].farDistance;
3002 camera->focalDistance = viewPtList[viewPtIdx].focalDistance;
3005 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3006 if (viewPtList[viewPtIdx].camType == ORTHOGRAPHIC) {
3008 camera = getCamera();
3009 ((SoOrthographicCamera *) camera)->height.setValue(
3010 viewPtList[viewPtIdx].height);
3012 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3013 viewPtList[viewPtIdx].height);
3014 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3015 if (viewPtList[viewPtIdx].camType == PERSPECTIVE) {
3017 camera = getCamera();
3018 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3019 viewPtList[viewPtIdx].height);
3021 ((SoOrthographicCamera *) camera)->height.setValue(
3022 viewPtList[viewPtIdx].height);
3024 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::setViewPt",
3025 "Only Perspective and Orthographic cameras are supported.");
3034void G4OpenInventorXtExaminerViewer::saveViewPtCB(Widget w,
3035 XtPointer client_data,
3040 if (This->fileName.empty()) {
3041 newViewPtFileCB(w, This, NULL);
3042 This->returnToSaveVP =
true;
3048 Widget nameViewPtDialog;
3049 Widget parent = This->getParentWidget();
3050 XmString label = XmStringCreateLocalized((
char *)
"Name the viewpoint:");
3052 XtSetArg(args[n], XmNselectionLabelString, label);
n++;
3054 XtSetArg(args[n], XmNautoUnmanage, False);
n++;
3056 XtSetArg(args[n], XmNtitle,
"Save Bookmark");
n++;
3057 nameViewPtDialog = XmCreatePromptDialog(parent, String(
"Save Bookmark"),
3060 XmStringFree(label);
3061 XtAddCallback(nameViewPtDialog, XmNokCallback, getViewPtNameCB, This);
3062 XtAddCallback(nameViewPtDialog, XmNcancelCallback,
3063 getViewPtNameCancelCB, This);
3067 Widget text = XtNameToWidget(nameViewPtDialog,
"Text");
3068 XtVaSetValues(text, XmNmaxLength, This->MAX_VP_NAME, NULL);
3069 std::string autoName =
"";
3071 autoName = This->viewPtAutoName();
3074 XmTextSetString(text, (
char *) autoName.c_str());
3075 XmTextSetInsertionPosition(text, autoName.length());
3077 XtUnmanageChild(XtNameToWidget(nameViewPtDialog,
"Help"));
3078 XtManageChild(nameViewPtDialog);
3082std::string G4OpenInventorXtExaminerViewer::viewPtAutoName()
3085 std::stringstream sstream;
3086 std::vector<int> existingViewPts;
3090 for (
unsigned int i = 0; i < this->viewPtList.size(); ++i) {
3091 viewPt = this->viewPtList[i].viewPtName;
3092 if (viewPt.find(
"viewpoint_") != std::string::npos) {
3093 tmp = atoi(viewPt.substr(10).c_str());
3096 if (!viewPt.compare(
"viewpoint_0"))
3097 existingViewPts.push_back(0);
3099 existingViewPts.push_back(tmp);
3107 if (existingViewPts.size() > 0) {
3110 if (std::find(existingViewPts.begin(), existingViewPts.end(), vpNum)
3111 == existingViewPts.end()) {
3112 sstream <<
"viewpoint_" << vpNum;
3113 return sstream.str();
3118 return "viewpoint_0";
3124void G4OpenInventorXtExaminerViewer::abbrOutputCB(Widget,
3125 XtPointer client_data,
3135void G4OpenInventorXtExaminerViewer::pickRefPathCB(Widget,
3136 XtPointer client_data,
3143 if(This->isViewing())
3144 This->setViewing(
false);
3145 This->setComponentCursor(SoXtCursor(SoXtCursor::CROSSHAIR));
3150void G4OpenInventorXtExaminerViewer::switchWireFrameCB(Widget w,
3151 XtPointer client_data,
3157 if (XmToggleButtonGetState(w)) {
3158 This->setDrawStyle(SoXtViewer::STILL, SoXtViewer::VIEW_LINE);
3159 This->setDrawStyle(SoXtViewer::INTERACTIVE, SoXtViewer::VIEW_LINE);
3161 This->setDrawStyle(SoXtViewer::STILL, SoXtViewer::VIEW_AS_IS);
3162 This->setDrawStyle(SoXtViewer::INTERACTIVE,
3163 SoXtViewer::VIEW_SAME_AS_STILL);
3170void G4OpenInventorXtExaminerViewer::getViewPtNameCB(Widget w,
3171 XtPointer client_data,
3172 XtPointer call_data)
3175 std::string strName;
3177 XmSelectionBoxCallbackStruct *cbs =
3178 (XmSelectionBoxCallbackStruct *) call_data;
3179 XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &name);
3192 int beg = strName.find_first_not_of(
' ');
3193 int end = strName.find_last_not_of(
' ');
3194 strName = strName.substr(beg, end - beg + 1);
3196 bool nameExists =
false;
3197 int size = This->viewPtList.size();
3198 for (
int i = 0; i < size; i++) {
3199 if (!strcmp(This->viewPtList[i].viewPtName, strName.c_str())) {
3206 const int nVPName = This->MAX_VP_NAME + 1;
3207 name =
new char[nVPName];
3208 strncpy(name, strName.c_str(), nVPName);
3209 if (This->viewPtIdx == -1)
3210 This->viewPtIdx = 0;
3211 This->saveViewPt(name);
3212 if (This->listsDialog) {
3213 XmListAddItemUnselected(This->myViewPtList, cbs->value, 0);
3218 String dialogName = (
char *)
"Existing Viewpoint";
3219 std::string msg =
"The viewpoint already exists.";
3225void G4OpenInventorXtExaminerViewer::getViewPtNameCancelCB(Widget w,
3235void G4OpenInventorXtExaminerViewer::saveViewPt(
char *name)
3239 float x, y, z, angle;
3240 SoCamera * camera = getCamera();
3242 if (viewPtList.size() == 0) {
3244 XtSetSensitive(nextViewPtButton, True);
3245 XtSetSensitive(prevViewPtButton, True);
3248 tmp.viewPtName =
name;
3249 tmp.viewportMapping = camera->viewportMapping.getValue();
3250 tmp.position = camera->position.getValue();
3251 tmp.orientation = camera->orientation.getValue();
3252 tmp.aspectRatio = camera->aspectRatio.getValue();
3253 tmp.nearDistance = camera->nearDistance.getValue();
3254 tmp.farDistance = camera->farDistance.getValue();
3255 tmp.focalDistance = camera->focalDistance.getValue();
3258 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3259 tmp.height = ((SoPerspectiveCamera *) camera)->heightAngle.getValue();
3260 tmp.camType = PERSPECTIVE;
3261 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3262 tmp.height = ((SoOrthographicCamera *) camera)->height.getValue();
3263 tmp.camType = ORTHOGRAPHIC;
3265 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::saveViewPtCB",
3266 "Only Perspective and Orthographic cameras are supported.");
3270 viewPtList.push_back(tmp);
3273 std::string vpName =
name;
3275 while ((
int) vpName.size() <= MAX_VP_NAME)
3278 fileOut << vpName << std::endl;
3279 tmp.position.getValue(x, y, z);
3280 fileOut << x <<
" " << y <<
" " << z << std::endl;
3283 tmp.orientation.getValue(axis, angle);
3284 axis.getValue(x, y, z);
3285 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3287 fileOut << tmp.camType <<
" " << tmp.height << std::endl;
3288 fileOut << tmp.focalDistance <<
" ";
3289 fileOut << tmp.nearDistance <<
" ";
3290 fileOut << tmp.farDistance << std::endl;
3291 fileOut << tmp.viewportMapping <<
" ";
3292 fileOut << tmp.aspectRatio <<
"\n" << std::endl;
3298void G4OpenInventorXtExaminerViewer::deleteViewPtCB(Widget,
3299 XtPointer client_data,
3304 This->deleteViewPt();
3311void G4OpenInventorXtExaminerViewer::deleteViewPt(
char *vpName)
3315 fileIn.open(fileName.c_str());
3316 std::ofstream out(
"temporaryFile.txt");
3319 vpName = viewPtList[viewPtIdx].viewPtName;
3322 XmString vpNameStr = XmStringCreateLocalized(vpName);
3324 XmListDeleteItem(myViewPtList, vpNameStr);
3325 XmStringFree(vpNameStr);
3328 getline(fileIn, line);
3329 out << line <<
"\n";
3331 while (getline(fileIn, line)) {
3332 end = line.find_last_not_of(
' ');
3333 line = line.substr(0, end + 1);
3334 if (!strcmp(line.c_str(), vpName)) {
3335 while (line.size()) {
3336 getline(fileIn, line);
3339 while (getline(fileIn, line))
3340 out << line <<
"\n";
3342 while (line.size()) {
3343 out << line <<
"\n";
3344 getline(fileIn, line);
3351 int size = viewPtList.size();
3352 while (idx < size) {
3353 if (!strcmp(viewPtList[idx].viewPtName, vpName)) {
3354 viewPtList.erase(viewPtList.begin() + idx);
3366 int istat = remove(fileName.c_str());
3368 char dialogName[] =
"Warning";
3372 istat = rename(
"temporaryFile.txt", fileName.c_str());
3374 char dialogName[] =
"Warning";
3378 fileOut.open(fileName.c_str(), std::ios::in);
3379 fileOut.seekp(0, std::ios::end);
3381 if (!viewPtList.size()) {
3382 curViewPtName = (
char *)
"";
3384 XtSetSensitive(nextViewPtButton, False);
3385 XtSetSensitive(prevViewPtButton, False);
3387 if (viewPtIdx >= (
int) viewPtList.size())
3397void G4OpenInventorXtExaminerViewer::renameViewPt(
char *vpName)
3399 int idx = 0, end,
pos;
3400 int size = viewPtList.size();
3401 std::string line, newName;
3402 fileIn.open(fileName.c_str());
3405 while ((
int) newName.size() < MAX_VP_NAME)
3408 getline(fileIn, line);
3409 pos = fileIn.tellg();
3410 while (getline(fileIn, line)) {
3411 end = line.find_last_not_of(
' ');
3412 line = line.substr(0, end + 1);
3413 if (!strcmp(line.c_str(), curViewPtName)) {
3416 fileOut.seekp(0, std::ios::end);
3420 getline(fileIn, line);
3421 pos = fileIn.tellg();
3427 while (idx < size) {
3428 if (!strcmp(viewPtList[idx].viewPtName, curViewPtName)) {
3429 strcpy(viewPtList[idx].viewPtName, vpName);
3439void G4OpenInventorXtExaminerViewer::sortViewPts(std::vector<std::string> sortedViewPts)
3442 float x, y, z, angle;
3443 int sortIdx = 0, unsortIdx = 0;
3445 if (fileOut.is_open())
3448 fileOut.open(fileName.c_str());
3452 int size = sortedViewPts.size();
3453 while (sortIdx < size) {
3454 while (strcmp(sortedViewPts[sortIdx].c_str(),
3455 viewPtList[unsortIdx].viewPtName))
3458 std::string vpName = viewPtList[unsortIdx].viewPtName;
3460 while ((
int) vpName.size() < MAX_VP_NAME)
3462 fileOut << vpName << std::endl;
3463 viewPtList[unsortIdx].position.getValue(x, y, z);
3464 fileOut << x <<
" " << y <<
" " << z << std::endl;
3467 viewPtList[unsortIdx].orientation.getValue(axis, angle);
3468 axis.getValue(x, y, z);
3469 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3471 fileOut << viewPtList[unsortIdx].camType <<
" "
3472 << viewPtList[unsortIdx].height << std::endl;
3473 fileOut << viewPtList[unsortIdx].focalDistance <<
" ";
3475 fileOut << viewPtList[unsortIdx].nearDistance <<
" ";
3477 fileOut << viewPtList[unsortIdx].farDistance << std::endl;
3479 fileOut << viewPtList[unsortIdx].viewportMapping <<
" ";
3480 fileOut << viewPtList[unsortIdx].aspectRatio <<
"\n" << std::endl;
3498 float x(0.), y(0.), z(0.), angle(0.);
3502 parseString<int>(viewPtIdx, token, error);
3503 getline(fileIn, token);
3505 while (getline(fileIn, token)) {
3507 int end = token.find_last_not_of(
' ');
3508 token = token.substr(0, end + 1);
3510 char *vpName =
new char[token.size() + 1];
3511 strcpy(vpName, token.c_str());
3512 tmp.viewPtName = vpName;
3515 parseString<float>(x, token, error);
3517 parseString<float>(y, token, error);
3519 parseString<float>(z, token, error);
3521 tmp.position = axis.setValue(x, y, z);
3523 parseString<float>(x, token, error);
3525 parseString<float>(y, token, error);
3527 parseString<float>(z, token, error);
3529 parseString<float>(angle, token, error);
3531 orient.setValue(axis.setValue(x, y, z), angle);
3532 tmp.orientation = orient.getValue();
3535 parseString<int>(camType, token, error);
3537 tmp.camType = (CameraType) camType;
3539 parseString<float>(tmp.height, token, error);
3541 parseString<float>(tmp.focalDistance, token, error);
3543 parseString<float>(tmp.nearDistance, token, error);
3545 parseString<float>(tmp.farDistance, token, error);
3547 parseString<int>(tmp.viewportMapping, token, error);
3549 parseString<float>(tmp.aspectRatio, token, error);
3551 getline(fileIn, token);
3552 getline(fileIn, token);
3559 viewPtList.push_back(tmp);
3572 std::istringstream str(s);
3573 if ((str >> t).fail())
3580void G4OpenInventorXtExaminerViewer::popUpFileSelDialog(Widget &dialog,
3581 std::string dialogName,
3582 std::string buttonLabel,
3583 XtCallbackProc cbOK)
3587 Widget parent, scrollWidget;
3588 parent = SoXt::getShellWidget(getParentWidget());
3590 if (dialog == NULL) {
3593 XmString str = XmStringCreateLocalized((
char *) buttonLabel.c_str());
3596 XtSetArg(args[n], XmNokLabelString, str); n++;
3597 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
3599 dialog = XmCreateFileSelectionDialog(parent,
3600 (
char *) dialogName.c_str(), args, n);
3602 XtAddCallback(dialog, XmNokCallback, cbOK,
this);
3603 XtAddCallback(dialog, XmNcancelCallback, cancelFileSelDialogCB,
this);
3606 scrollWidget = XmFileSelectionBoxGetChild(dialog, XmDIALOG_DIR_LIST);
3609 scrollWidget = XmFileSelectionBoxGetChild(dialog, XmDIALOG_LIST);
3613 XtUnmanageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
3616 XtManageChild(dialog);
3622void G4OpenInventorXtExaminerViewer::cancelFileSelDialogCB(Widget w,
3632void G4OpenInventorXtExaminerViewer::openViewPtFileCB(Widget,
3633 XtPointer client_data,
3638 This->popUpFileSelDialog(This->openFileDialog,
"Open File",
"Load",
3639 viewPtFileSelectedCB);
3643void G4OpenInventorXtExaminerViewer::viewPtFileSelectedCB(Widget w,
3644 XtPointer client_data,
3645 XtPointer call_data)
3649 XmFileSelectionBoxCallbackStruct *cbs =
3650 (XmFileSelectionBoxCallbackStruct *) call_data;
3654 if (!(file = (
char *) XmStringUnparse(cbs->value,
3655 XmFONTLIST_DEFAULT_TAG, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0,
3657 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::fileSelectedCB",
3658 "Internal error during file opening");
3662 This->fileIn.open(file);
3663 if (!This->fileIn.fail()) {
3665 This->cleanUpAfterPrevFile();
3667 String dialogName = (
char *)
"Error Loading File";
3668 std::string msg =
"Wrong or corrupted input file.";
3671 This->fileName = file;
3672 This->fileOut.open(This->fileName.c_str(), std::ios::in);
3673 This->fileOut.seekp(0, std::ios::end);
3675 if (!This->listsDialog)
3676 constructListsDialog(w, This, NULL);
3678 This->addViewPoints();
3680 std::string newDialogName = This->fileName.substr(
3681 This->fileName.rfind(
'/') + 1);
3682 XtVaSetValues(This->myShellDialog, XmNtitle,
3683 (
char *) newDialogName.c_str(), NULL);
3685 if (This->viewPtList.size()) {
3687 XmTextSetString(This->viewPtSelection, NULL);
3688 XtSetSensitive(This->nextViewPtButton, True);
3689 XtSetSensitive(This->prevViewPtButton, True);
3691 XtSetSensitive(This->nextViewPtButton, False);
3692 XtSetSensitive(This->prevViewPtButton, False);
3698 This->fileIn.close();
3700 String dialogName = (
char *)
"Nonexistent File";
3701 std::string msg =
"Unable to open file.";
3706 This->fileIn.clear();
3713void G4OpenInventorXtExaminerViewer::addViewPoints()
3715 int size = viewPtList.size();
3721 viewPts = (XmString *) XtMalloc(size *
sizeof(XmString));
3722 for (
int i = 0; i < size; i++)
3723 viewPts[i] = XmStringCreateLocalized(viewPtList[i].viewPtName);
3725 XmListAddItemsUnselected(myViewPtList, viewPts, size, 1);
3727 if (viewPts != NULL) {
3728 for (
int i = 0; i < size; i++)
3729 XmStringFree(viewPts[i]);
3730 XtFree((
char *) viewPts);
3738void G4OpenInventorXtExaminerViewer::cleanUpAfterPrevFile()
3742 setSuperimpositionEnabled(superimposition,
FALSE);
3744 currentState = GENERAL;
3745 if (fileOut.is_open())
3748 XmListDeleteAllItems(myViewPtList);
3760 XmString warningMsg;
3762 warningMsg = XmStringCreateLocalized((
char *)msg.c_str());
3765 XtSetArg(args[n], XmNmessageString, warningMsg); n++;
3766 Widget warningDialog = XmCreateWarningDialog(getParentWidget(), dialogName, args, n);
3768 XtAddCallback(warningDialog, XmNokCallback, cb,
this);
3770 XmStringFree(warningMsg);
3772 XtVaSetValues (warningDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
3773 XtUnmanageChild(XtNameToWidget(warningDialog,
"Help"));
3774 XtUnmanageChild(XtNameToWidget(warningDialog,
"Cancel"));
3776 XtManageChild(warningDialog);
3780void G4OpenInventorXtExaminerViewer::newViewPtFileCB(Widget,
3781 XtPointer client_data,
3786 This->popUpFileSelDialog(This->newFileDialog,
"New File",
"Save",
3791void G4OpenInventorXtExaminerViewer::createNewVPFileCB(Widget w,
3792 XtPointer client_data,
3793 XtPointer call_data)
3798 XmFileSelectionBoxCallbackStruct *cbs =
3799 (XmFileSelectionBoxCallbackStruct *) call_data;
3803 if (!(file = (
char *) XmStringUnparse(cbs->value,
3804 XmFONTLIST_DEFAULT_TAG, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0,
3806 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::createNewVPFileCB",
3807 "Internal error during file opening");
3811 This->fileName = file;
3812 fName = This->fileName.substr(This->fileName.rfind(
'/') + 1);
3813 This->fileIn.open(file);
3814 if (This->fileIn.fail()) {
3815 This->cleanUpAfterPrevFile();
3816 This->fileOut.open(file);
3817 XtSetSensitive(This->nextViewPtButton, False);
3818 XtSetSensitive(This->prevViewPtButton, False);
3819 if (This->listsDialog)
3820 closeListsDialogCB(w, This, NULL);
3821 constructListsDialog(w, This, NULL);
3823 if (This->returnToSaveVP) {
3824 This->returnToSaveVP =
false;
3825 saveViewPtCB(NULL, This, NULL);
3828 String dialogName = (
char *)
"Existing File";
3829 std::string msg =
"'" + fName +
"' already exists. Do you want to overwrite it?";
3831 This->fileIn.close();
3833 This->fileIn.clear();
3839void G4OpenInventorXtExaminerViewer::overwriteFileCB(Widget,
3840 XtPointer client_data,
3844 This->cleanUpAfterPrevFile();
3845 XtSetSensitive(This->nextViewPtButton, False);
3846 XtSetSensitive(This->prevViewPtButton, False);
3848 XtUnmanageChild(This->newFileDialog);
3850 This->fileOut.open(This->fileName.c_str());
3852 if (This->returnToSaveVP) {
3853 This->returnToSaveVP =
false;
3854 saveViewPtCB(NULL, This, NULL);
3859void G4OpenInventorXtExaminerViewer::loadRefCoordsDialogCB(Widget,
3860 XtPointer client_data,
3865 This->popUpFileSelDialog(This->loadRefCoordsDialog,
"Load Ref Coords",
3866 "Load", loadRefCoordsCB);
3870void G4OpenInventorXtExaminerViewer::loadRefCoordsCB(Widget w,
3871 XtPointer client_data,
3872 XtPointer call_data)
3876 XmFileSelectionBoxCallbackStruct *cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
3881 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3882 XmCHARSET_TEXT, XmCHARSET_TEXT,
3883 NULL, 0, XmOUTPUT_ALL);
3885 std::ifstream ifs(file);
3887 This->refParticleTrajectory.clear();
3889 while(ifs >> x >> y >> z){
3890 This->refParticleTrajectory.push_back(SbVec3f(x,y,z));
3896 String dialogName = (
char *)
"Problem reading file";
3897 std::string msg =
"Problem reading file";
3908void G4OpenInventorXtExaminerViewer::saveRefCoordsDialogCB(Widget,
3909 XtPointer client_data,
3914 if (!This->refParticleTrajectory.size()) {
3915 String dialogName = (
char *)
"No Reference Trajectory";
3916 std::string msg =
"You need to start a run or load a reference trajectory from a file";
3923 Widget parent, scrollWidget;
3924 parent = SoXt::getShellWidget(This->getParentWidget());
3926 if (This->saveRefCoordsDialog == NULL) {
3929 XmString str = XmStringCreateLocalized((
char *)
"Save");
3932 XtSetArg(args[n], XmNokLabelString, str);
n++;
3933 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE);
n++;
3935 This->saveRefCoordsDialog = XmCreateFileSelectionDialog(parent,(
char *)
"Save Ref Coords", args, n);
3937 XtAddCallback(This->saveRefCoordsDialog, XmNokCallback, saveRefCoordsCB, This);
3938 XtAddCallback(This->saveRefCoordsDialog, XmNcancelCallback, cancelFileSelDialogCB, This);
3941 scrollWidget = XmFileSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_DIR_LIST);
3944 scrollWidget = XmFileSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_LIST);
3948 XtUnmanageChild(XmSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_HELP_BUTTON));
3954 XtManageChild(This->saveRefCoordsDialog);
3959void G4OpenInventorXtExaminerViewer::saveRefCoordsCB(Widget w,
3960 XtPointer client_data,
3961 XtPointer call_data)
3965 XmFileSelectionBoxCallbackStruct *cbs =
3966 (XmFileSelectionBoxCallbackStruct *) call_data;
3971 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3972 XmCHARSET_TEXT, XmCHARSET_TEXT,
3973 NULL, 0, XmOUTPUT_ALL);
3975 std::ifstream ifile(file);
3980 Widget parent = This->getParentWidget();
3981 Widget confirmOverwriteDialog;
3984 confirmOverwriteDialog = XmCreateQuestionDialog (parent, (
char *)
"Confirm overwrite", args, 0);
3985 msg = XmStringCreateLocalized ((
char *)
"File exists. Overwrite?");
3986 XtVaSetValues (confirmOverwriteDialog, XmNmessageString, msg, NULL);
3991 XtVaSetValues (confirmOverwriteDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
3992 XtAddCallback (confirmOverwriteDialog, XmNokCallback, saveRefCoordsOverWriteCB, client_data);
3993 XtAddCallback (confirmOverwriteDialog, XmNcancelCallback, saveRefCoordsOverWriteCB, client_data);
4001 XtUnmanageChild(XtNameToWidget(confirmOverwriteDialog,
"Help"));
4002 XtManageChild(confirmOverwriteDialog);
4008 std::ofstream ofs(file);
4011 for(
unsigned int i=0; i < This->refParticleTrajectory.size(); ++i){
4012 This->refParticleTrajectory[i].getValue(x,y,z);
4013 ofs << x <<
" " << y <<
" " << z <<
"\n";
4019 String dialogName = (
char *)
"Error opening file";
4020 std::string msg =
"There was a problem trying to open the file '";
4033void G4OpenInventorXtExaminerViewer::saveRefCoordsOverWriteCB(Widget w,
4034 XtPointer client_data,
4035 XtPointer call_data)
4037 XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
4040 switch (cbs->reason) {
4048 for(
unsigned int i=0; i < This->refParticleTrajectory.size(); ++i){
4049 This->refParticleTrajectory[i].getValue(x,y,z);
4050 ofs << x <<
" " << y <<
" " << z <<
"\n";
4057 String dialogName = (
char *)
"Error opening file";
4058 std::string msg =
"There was a problem trying to open the file '";
4072 XmProcessTraversal(XtNameToWidget(This->
saveRefCoordsWidget,
"Text"), XmTRAVERSE_CURRENT);
4085void G4OpenInventorXtExaminerViewer::loadSceneGraphDialogCB(Widget,
4086 XtPointer client_data,
4091 This->popUpFileSelDialog(This->loadSceneGraphDialog,
"Load Scene Graph",
4092 "Load", loadSceneGraphCB);
4097void G4OpenInventorXtExaminerViewer::loadSceneGraphCB(Widget w,
4098 XtPointer client_data,
4099 XtPointer call_data)
4103 XmFileSelectionBoxCallbackStruct *cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
4107 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
4108 XmCHARSET_TEXT, XmCHARSET_TEXT,
4109 NULL, 0, XmOUTPUT_ALL);
4112 if (!sceneInput.openFile(file)) {
4113 String dialogName = (
char *)
"Problem opening file";
4114 std::string msg =
"Cannot open file ";
4118 sceneInput.closeFile();
4122 This->newSceneGraph = SoDB::readAll(&sceneInput);
4123 if (This->newSceneGraph == NULL) {
4124 String dialogName = (
char *)
"Problem reading file";
4125 std::string msg =
"Problem reading file";
4131 This->setSceneGraph(This->newSceneGraph);
4138void G4OpenInventorXtExaminerViewer::saveSceneGraphDialogCB(Widget,
4139 XtPointer client_data,
4146 Widget parent, scrollWidget;
4147 parent = SoXt::getShellWidget(This->getParentWidget());
4149 if (This->saveSceneGraphDialog == NULL) {
4152 XmString str = XmStringCreateLocalized((
char *)
"Save");
4155 XtSetArg(args[n], XmNokLabelString, str);
n++;
4156 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE);
n++;
4158 This->saveSceneGraphDialog = XmCreateFileSelectionDialog(parent,(
char *)
"Save Scene Graph", args, n);
4160 XtAddCallback(This->saveSceneGraphDialog, XmNokCallback, saveSceneGraphCB, This);
4161 XtAddCallback(This->saveSceneGraphDialog, XmNcancelCallback, cancelFileSelDialogCB, This);
4164 scrollWidget = XmFileSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_DIR_LIST);
4167 scrollWidget = XmFileSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_LIST);
4171 XtUnmanageChild(XmSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_HELP_BUTTON));
4177 XtManageChild(This->saveSceneGraphDialog);
4183void G4OpenInventorXtExaminerViewer::saveSceneGraphCB(Widget w,
4184 XtPointer client_data,
4185 XtPointer call_data)
4189 XmFileSelectionBoxCallbackStruct *cbs =
4190 (XmFileSelectionBoxCallbackStruct *) call_data;
4194 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
4195 XmCHARSET_TEXT, XmCHARSET_TEXT,
4196 NULL, 0, XmOUTPUT_ALL);
4198 std::ifstream ifile(file);
4203 Widget parent = This->getParentWidget();
4204 Widget confirmOverwriteDialog;
4207 confirmOverwriteDialog = XmCreateQuestionDialog (parent, (
char *)
"Confirm overwrite", args, 0);
4208 msg = XmStringCreateLocalized ((
char *)
"File exists. Overwrite?");
4209 XtVaSetValues (confirmOverwriteDialog, XmNmessageString, msg, NULL);
4214 XtVaSetValues (confirmOverwriteDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
4215 XtAddCallback (confirmOverwriteDialog, XmNokCallback, saveSceneGraphOverWriteCB, client_data);
4216 XtAddCallback (confirmOverwriteDialog, XmNcancelCallback, saveSceneGraphOverWriteCB, client_data);
4224 XtUnmanageChild(XtNameToWidget(confirmOverwriteDialog,
"Help"));
4225 XtManageChild(confirmOverwriteDialog);
4231 SoWriteAction writeAction;
4232 SoSeparator *root = (SoSeparator *) (This->getSceneGraph());
4234 SoOutput * out = writeAction.getOutput();
4236 if(out->openFile(file)){
4237 out->setBinary(
FALSE);
4238 writeAction.apply(root);
4244 String dialogName = (
char *)
"Error opening file";
4245 std::string msg =
"There was a problem trying to open the file '";
4260void G4OpenInventorXtExaminerViewer::saveSceneGraphOverWriteCB(Widget w,
4261 XtPointer client_data,
4262 XtPointer call_data)
4264 XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
4267 switch (cbs->reason) {
4272 SoWriteAction writeAction;
4273 SoSeparator *root = (SoSeparator *) (This->getSceneGraph());
4275 SoOutput * out = writeAction.getOutput();
4277 out->setBinary(
FALSE);
4278 writeAction.apply(root);
4287 String dialogName = (
char *)
"Error opening file";
4288 std::string msg =
"There was a problem trying to open the file '";
4319void G4OpenInventorXtExaminerViewer::loadBookmarkCB(Widget,
4320 XtPointer client_data,
4321 XtPointer call_data)
4325 XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
4327 vpName = (
char *) XmStringUnparse(cbs->item, XmFONTLIST_DEFAULT_TAG,
4328 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
4330 for (
int i = 0; i < (int) This->viewPtList.size(); i++) {
4331 if (!strcmp(This->viewPtList[i].viewPtName, vpName)) {
4332 This->viewPtIdx = i;
4336 XmTextSetString(This->viewPtSelection, vpName);
4338 This->writeViewPtIdx();
4345void G4OpenInventorXtExaminerViewer::deleteBookmarkCB(Widget,
4346 XtPointer client_data,
4352 vpName = XmTextGetString(This->viewPtSelection);
4354 XmString vpNameStr = XmStringCreateLocalized(vpName);
4356 if (XmListItemExists(This->myViewPtList, vpNameStr)) {
4357 XmListDeleteItem(This->myViewPtList, vpNameStr);
4358 This->deleteViewPt(vpName);
4361 XmStringFree(vpNameStr);
4362 XmTextSetString(This->viewPtSelection, NULL);
4367void G4OpenInventorXtExaminerViewer::renameBookmarkCB(Widget,
4368 XtPointer client_data,
4371 std::string vpNameStr;
4373 int *pos_list, pos_cnt;
4376 vpName = XmTextGetString(This->viewPtSelection);
4378 if (!strlen(vpName) || !strcmp(This->curViewPtName, vpName)) {
4385 int beg = vpNameStr.find_first_not_of(
' ');
4386 int end = vpNameStr.find_last_not_of(
' ');
4387 vpNameStr = vpNameStr.substr(beg, end - beg + 1);
4388 const int nVPName = vpNameStr.size() + 1;
4389 char* vpName1 =
new char[nVPName];
4390 strncpy(vpName1, vpNameStr.c_str(), nVPName);
4392 int size = This->viewPtList.size();
4393 for (
int i = 0; i < size; i++) {
4394 if (!strcmp(vpName1, This->viewPtList[i].viewPtName)) {
4396 String dialogName = (
char *)
"Existing Viewpoint";
4397 std::string msg =
"'";
4399 msg +=
"' already exists. Choose a different name";
4407 XmString vpNameXmStr = XmStringCreateLocalized(vpName1);
4409 if (XmListGetSelectedPos(This->myViewPtList, &pos_list, &pos_cnt)) {
4410 XmListReplaceItemsPos(This->myViewPtList, &vpNameXmStr, 1, pos_list[0]);
4411 This->renameViewPt(vpName1);
4412 XtFree((
char *) pos_list);
4415 if (This->currentState == VIEWPOINT)
4416 This->scheduleRedraw();
4418 XmStringFree(vpNameXmStr);
4423void G4OpenInventorXtExaminerViewer::sortBookmarksCB(Widget,
4424 XtPointer client_data,
4429 XmString *strList, *newStrList;
4430 std::vector<std::string> charList;
4433 if (This->viewPtList.size() < 2)
4437 XtVaGetValues(This->myViewPtList, XmNitemCount, &size, XmNitems, &strList,
4440 for (
int i = 0; i < size; i++) {
4441 vpName = (
char *) XmStringUnparse(strList[i], XmFONTLIST_DEFAULT_TAG,
4442 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
4443 charList.push_back(vpName);
4447 std::sort(charList.begin(), charList.end());
4449 newStrList = (XmString *) XtMalloc(size *
sizeof(XmString));
4450 for (
int i = 0; i < size; i++) {
4452 if (!strcmp(charList[i].c_str(), This->curViewPtName))
4453 This->viewPtIdx = i;
4454 const int nVPName = charList[i].size() + 1;
4455 char *vpName2 =
new char[nVPName];
4456 strncpy(vpName2, charList[i].c_str(), nVPName);
4457 newStrList[i] = XmStringCreateLocalized(vpName2);
4461 XmListDeleteAllItems(This->myViewPtList);
4462 XmListAddItemsUnselected(This->myViewPtList, newStrList, size, 1);
4464 This->sortViewPts(charList);
4466 if (newStrList != NULL) {
4467 for (
int i = 0; i < size; i++)
4468 XmStringFree(newStrList[i]);
4469 XtFree((
char *) newStrList);
4474void G4OpenInventorXtExaminerViewer::evenOutRefParticlePts()
4476 if(this->refParticleTrajectory.empty())
4479 SbVec3f p1, p2, p3, dirNow, dirNxt, dir, p2_tmp, p_start, p_corner, p_nxt;
4480 float avgDistBtwPts = 0;
4481 float totalDistBtwPts = 0;
4482 std::vector<SbVec3f> newRefParticleTrajectory;
4484 int size = refParticleTrajectory.size() - 1;
4486 for (
int i = 0; i < size; i++) {
4487 p1 = refParticleTrajectory[i];
4488 p2 = refParticleTrajectory[i + 1];
4492 totalDistBtwPts += (p2 - p1).length();
4495 if (numOfPts <= 2)
return;
4497 avgDistBtwPts = totalDistBtwPts / numOfPts;
4498 float minDistAllowed = 0.75 * avgDistBtwPts;
4504 p1 = refParticleTrajectory[i];
4505 p2 = refParticleTrajectory[i + 1];
4508 p1.getValue(x, y, z);
4510 newRefParticleTrajectory.push_back(refPoint);
4513 while ((p2 - p1).length() < minDistAllowed && j < (size - 1)) {
4516 p1 = refParticleTrajectory[j];
4517 p2 = refParticleTrajectory[j + 1];
4525 refParticleTrajectory.clear();
4526 refParticleTrajectory = newRefParticleTrajectory;
4532void G4OpenInventorXtExaminerViewer::closeMainWindowCB(Widget,
4533 XtPointer client_data,
4539 if (This->openFileDialog)
4540 XtUnmanageChild(This->openFileDialog);
4542 if (This->newFileDialog)
4543 XtUnmanageChild(This->newFileDialog);
4545 if (This->listsDialog)
4546 closeListsDialogCB(NULL, This, NULL);
4550void G4OpenInventorXtExaminerViewer::saveCurCamera()
4552 SoCamera *cam = getCamera();
4553 camB4Animation.viewportMapping = cam->viewportMapping.getValue();
4554 camB4Animation.position = cam->position.getValue();
4555 camB4Animation.orientation = cam->orientation.getValue();
4556 camB4Animation.aspectRatio = cam->aspectRatio.getValue();
4557 camB4Animation.nearDistance = cam->nearDistance.getValue();
4558 camB4Animation.farDistance = cam->farDistance.getValue();
4559 camB4Animation.focalDistance = cam->focalDistance.getValue();
4561 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
4562 camB4Animation.height =
4563 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
4564 camB4Animation.camType = PERSPECTIVE;
4565 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4566 camB4Animation.height =
4567 ((SoOrthographicCamera *) cam)->height.getValue();
4568 camB4Animation.camType = ORTHOGRAPHIC;
4573void G4OpenInventorXtExaminerViewer::restoreCamera()
4575 SoCamera *cam = getCamera();
4577 cam->viewportMapping = camB4Animation.viewportMapping;
4578 cam->position = camB4Animation.position;
4579 cam->orientation = camB4Animation.orientation;
4580 cam->aspectRatio = camB4Animation.aspectRatio;
4581 cam->nearDistance = camB4Animation.nearDistance;
4582 cam->farDistance = camB4Animation.farDistance;
4583 cam->focalDistance = camB4Animation.focalDistance;
4585 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
4586 if (camB4Animation.camType == ORTHOGRAPHIC) {
4589 ((SoOrthographicCamera *) cam)->height.setValue(
4590 camB4Animation.height);
4592 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
4593 camB4Animation.height);
4594 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4595 if (camB4Animation.camType == PERSPECTIVE) {
4598 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
4599 camB4Animation.height);
4601 ((SoOrthographicCamera *) cam)->height.setValue(
4602 camB4Animation.height);
4607void G4OpenInventorXtExaminerViewer::animateSensorRotationCB(
void *data,
4610 SbTime curTime = SbTime::getTimeOfDay();
4612 SoTimerSensor *s = (SoTimerSensor *) sensor;
4614 float t = float((curTime - s->getBaseTime()).getValue())
4615 / This->animateBtwPtsPeriod;
4617 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
4619 SbBool end = (t == 1.0f);
4622 This->animateSensorRotation->unschedule();
4629 This->currentState = This->prevState;
4639void G4OpenInventorXtExaminerViewer::animateSensorCB(
void *data,
4642 SbTime curTime = SbTime::getTimeOfDay();
4644 SoCamera *cam = This->getCamera();
4645 SoTimerSensor *s = (SoTimerSensor *) sensor;
4647 float t = float((curTime - s->getBaseTime()).getValue())
4648 / This->animateBtwPtsPeriod;
4650 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
4652 SbBool end = (t == 1.0f);
4654 cam->orientation = SbRotation::slerp(This->camStartOrient, This->camEndOrient, t);
4655 cam->position = This->camStartPos + (This->camEndPos - This->camStartPos) * t;
4658 This->animateSensor->unschedule();
4660 if (This->currentState == ANIMATION) {
4661 if (This->refParticleIdx < (
int) (This->refParticleTrajectory.size() - 1))
4662 This->animateRefParticle();
4668 if (This->currentState == REVERSED_ANIMATION) {
4669 if (This->refParticleIdx >= 1)
4670 This->animateRefParticle();
4680void G4OpenInventorXtExaminerViewer::setStartingPtForAnimation()
4682 if (SoXtExaminerViewer::isAnimating())
4686 SbVec3f p1(0), p2(0), p2_tmp(0), camUpV(0), camD, camD_tmp, leftRightAxis;
4687 float x1(0.), y1(0.), z1(0.), x2(0.), y2(0.), z2(0.);
4689 if (currentState == ANIMATION) {
4690 p1 = refParticleTrajectory[refParticleIdx];
4691 p2 = refParticleTrajectory[++(refParticleIdx)];
4692 }
else if (currentState == REVERSED_ANIMATION) {
4693 p2 = refParticleTrajectory[refParticleIdx];
4694 p1 = refParticleTrajectory[--(refParticleIdx)];
4695 }
else if (currentState == PAUSED_ANIMATION) {
4696 if (refParticleIdx < (
int) refParticleTrajectory.size()) {
4697 p1 = refParticleTrajectory[refParticleIdx];
4698 p2 = refParticleTrajectory[refParticleIdx + 1];
4700 p1 = refParticleTrajectory[refParticleIdx - 1];
4701 p2 = refParticleTrajectory[refParticleIdx];
4704 p1.getValue(x1, y1, z1);
4705 p2.getValue(x2, y2, z2);
4710 p2_tmp.setValue(x2, y1, z2);
4711 camD_tmp = p2_tmp - p1;
4712 camD_tmp.normalize();
4714 camUpV.setValue(0, 1, 0);
4715 rot.setValue(camD_tmp, camD);
4716 rot.multVec(camUpV, camUpV);
4718 leftRightAxis = camD.cross(camUpV);
4720 myCam->position = p1;
4721 myCam->pointAt(p2, camUpV);
4724 p1 = p1 + (up_down * camUpV) + (left_right * leftRightAxis);
4725 myCam->position = p1;
4727 int idx = refParticleIdx + pathLookahead;
4728 idx = std::min(idx, (
int)refParticleTrajectory.size() - 1);
4729 myCam->pointAt(refParticleTrajectory[idx], camUpV);
4731 myCam->focalDistance = 0.1f;
4735void G4OpenInventorXtExaminerViewer::gotoRefPathStart()
4737 G4OpenInventorXtExaminerViewer::gotoRefPathStartCB(NULL, (
void *)
this,
4742void G4OpenInventorXtExaminerViewer::gotoRefPathStartCB(Widget,
4743 XtPointer client_data,
4748 if (!This->refParticleTrajectory.size()) {
4749 String dialogName = (
char *)
"No Reference Trajectory";
4750 std::string msg =
"You need to start a run or load a reference trajectory from a file";
4755 if (This->currentState == ROTATING)
4757 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
4758 || This->currentState == PAUSED_ANIMATION) {
4759 if (This->animateSensor->isScheduled())
4760 This->animateSensor->unschedule();
4761 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
4762 This->maxSpeed = 0.0f;
4763 This->scheduleRedraw();
4765 This->saveCurCamera();
4766 This->prevState = This->currentState;
4767 This->prevRefIdx = This->refParticleIdx;
4770 if (This->SoXtExaminerViewer::isAnimating())
4771 This->stopAnimating();
4774 This->left_right = 0;
4777 This->refParticleIdx = 0;
4778 This->currentState = BEAMLINE;
4779 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
4780 This->axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
4781 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
4782 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
4783 This->scheduleRedraw();
4790 This->prevParticleDir = SbVec3f(0,0,0);
4793 SbVec3f p1 = This->refParticleTrajectory[0];
4794 SbVec3f pN = This->refParticleTrajectory[This->refParticleTrajectory.size() - 1];
4795 This->distance = (pN - p1).length() / 10;
4801void G4OpenInventorXtExaminerViewer::invertRefPathCB(Widget,
4802 XtPointer client_data,
4807 This->invertRefPath();
4811void G4OpenInventorXtExaminerViewer::invertRefPath()
4813 std::reverse(this->refParticleTrajectory.begin(),
4814 this->refParticleTrajectory.end());
4815 this->setReferencePathZPos();
4816 this->sortElements();
4820void G4OpenInventorXtExaminerViewer::animateRefParticleCB(Widget,
4821 XtPointer client_data,
4826 if (!This->refParticleTrajectory.size()) {
4827 This->returnToAnim =
true;
4828 String dialogName = (
char *)
"No Reference Trajectory";
4829 std::string msg =
"You need to start a run or load a reference trajectory from a file";
4834 if (!This->refParticleTrajectory.size())
4838 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
4840 This->axisSwitch->whichChild.setValue(SO_SWITCH_ALL);
4841 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
4842 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
4843 This->scheduleRedraw();
4846 SoCamera *cam = This->getCamera();
4849 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
4850 || This->currentState == ROTATING)
4853 if (This->currentState != PAUSED_ANIMATION) {
4855 This->saveCurCamera();
4856 This->prevState = This->currentState;
4857 This->prevRefIdx = This->refParticleIdx;
4859 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4860 This->toggleCameraType();
4861 cam = This->getCamera();
4864 This->refParticleIdx = 0;
4867 This->left_right = This->up_down = 0;
4869 cam->focalDistance = 0.1f;
4870 ((SoPerspectiveCamera *) cam)->heightAngle = 0.50f;
4873 This->currentState = ANIMATION;
4874 This->setStartingPtForAnimation();
4876 cam->position = (This->myCam)->
position.getValue();
4877 cam->orientation = (This->myCam)->orientation.getValue();
4878 This->animateRefParticle();
4882void G4OpenInventorXtExaminerViewer::animateRefParticle()
4884 SoCamera *cam = getCamera();
4886 camStartPos = cam->position.getValue();
4887 camStartOrient = cam->orientation.getValue();
4889 if (currentState != BEAMLINE)
4890 setStartingPtForAnimation();
4892 camEndPos = myCam->position.getValue();
4893 camEndOrient = myCam->orientation.getValue();
4895 if (animateSensor->isScheduled())
4896 animateSensor->unschedule();
4898 animateSensor->setBaseTime(SbTime::getTimeOfDay());
4899 animateSensor->setInterval(SbTime(0.02));
4901 animateSensor->schedule();
4906 void (*callback)(
void *),
void *
object)
4908 this->escapeCallback = callback;
4909 this->examinerObject = object;
4913void G4OpenInventorXtExaminerViewer::sceneChangeCB(
void *userData, SoSensor *)
4917 if(This->newEvents){
4918 This->findAndSetRefPath();
4919 This->newEvents =
false;
#define MAX_SPEED_INDICATOR
#define SPEED_INDICATOR_STEP
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)
virtual SbBool processSoEvent(const SoEvent *const event)
friend class HookEventProcState
void addButton(Widget menu, std::string name, XtCallbackProc)
bool viewingBeforePickRef
std::string saveRefCoordsFileName
G4OpenInventorXtExaminerViewer(Widget parent=NULL, const char *name=NULL, SbBool embed=TRUE, SoXtFullViewer::BuildFlag flag=BUILD_ALL, SoXtViewer::Type type=BROWSER)
~G4OpenInventorXtExaminerViewer()
virtual void createViewerButtons(Widget parent, SbPList *buttonlist)
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)
virtual void afterRealizeHook()
std::string saveScenegraphFileName
Widget saveScenegraphWidget
Widget buildWidget(Widget parent)
virtual G4bool Notify(G4ApplicationState requestedState)
HookEventProcState(G4OpenInventorQtExaminerViewer *)
static Pixmap createPixmapFromXpm(Widget button, const char **xpm, SbBool ghost=FALSE)
const char * name(G4int ptype)
void xmAddMouseEventHandler(Widget w)