38#include <X11/keysym.h>
43#include <Xm/MessageB.h>
45#include <Xm/ToggleB.h>
46#include <Xm/CascadeB.h>
47#include <Xm/ArrowBG.h>
49#include <Xm/RowColumn.h>
51#include <Xm/SelectioB.h>
52#include <Xm/Protocols.h>
53#include <Xm/SeparatoG.h>
54#include <Xm/DialogS.h>
58#include <Xm/DrawingA.h>
60#include <Inventor/Xt/SoXt.h>
62#include <Inventor/Xt/SoXtCursor.h>
63#include <Inventor/events/SoKeyboardEvent.h>
64#include <Inventor/events/SoMouseButtonEvent.h>
65#include <Inventor/events/SoLocation2Event.h>
66#include <Inventor/nodes/SoSeparator.h>
67#include <Inventor/nodes/SoOrthographicCamera.h>
68#include <Inventor/nodes/SoPerspectiveCamera.h>
69#include <Inventor/nodes/SoEventCallback.h>
70#include <Inventor/nodes/SoLineSet.h>
71#include <Inventor/nodes/SoMaterial.h>
72#include <Inventor/errors/SoDebugError.h>
73#include <Inventor/SoPickedPoint.h>
74#include <Inventor/actions/SoWriteAction.h>
79#include <Inventor/sensors/SoTimerSensor.h>
80#include <Inventor/sensors/SoNodeSensor.h>
92#include <Inventor/nodes/SoCallback.h>
93#include <Inventor/nodes/SoSwitch.h>
94#include <Inventor/nodes/SoScale.h>
95#include <Inventor/nodes/SoTranslation.h>
96#include <Inventor/actions/SoSearchAction.h>
97#include <Inventor/actions/SoGetBoundingBoxAction.h>
99#include <Inventor/nodes/SoCoordinate3.h>
101#include <Inventor/nodes/SoText2.h>
102#include <Inventor/nodes/SoFont.h>
103#include <Inventor/nodes/SoPointSet.h>
104#include <Inventor/nodes/SoDrawStyle.h>
105#include <Inventor/nodes/SoBaseColor.h>
108#include <Inventor/nodekits/SoBaseKit.h>
112static const char* thisClassName =
"G4OpenInventorXtExaminerViewer";
115#define START_STEP 0.3
116#define SPEED_INDICATOR_STEP 0.045
117#define MAX_SPEED_INDICATOR 0.81
123 const char *name, SbBool embed,
124 SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type) :
125 SoXtExaminerViewer(parent, name, embed, flag, type,
FALSE)
128 this->constructor(
TRUE);
133 const char *name, SbBool embed,
134 SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type,
136 SoXtExaminerViewer(parent, name, embed, flag, type,
FALSE)
138 this->constructor(build);
142void G4OpenInventorXtExaminerViewer::constructor(
const SbBool build)
144 setClassName(thisClassName);
147 this->newEvents =
false;
149 fileName =
".bookmarkFile";
151 animateSensor =
new SoTimerSensor(
152 G4OpenInventorXtExaminerViewer::animateSensorCB,
this);
153 animateSensorRotation =
new SoTimerSensor(
154 G4OpenInventorXtExaminerViewer::animateSensorRotationCB,
this);
156 currentState = GENERAL;
157 myCam =
new SoPerspectiveCamera;
161 curViewPtName =
new char[MAX_VP_NAME + 1];
162 left_right = up_down = 0;
168 lshiftdown = rshiftdown =
false;
171 lctrldown = rctrldown =
false;
175 prevColorField = NULL;
178 openFileDialog = newFileDialog = listsDialog = (Widget) NULL;
179 loadRefCoordsDialog = saveRefCoordsDialog = NULL;
180 loadSceneGraphDialog = saveSceneGraphDialog = NULL;
181 myElementList = NULL;
183 newSceneGraph = NULL;
184 zcoordSetFlag =
false;
191 static const char * superimposed[] = {
192 "#Inventor V2.1 ascii",
"",
199 " OrthographicCamera ",
205 " DEF soxt->callback Callback { }",
208 " DEF soxt->translation Translation ",
210 " translation 0 0 0",
212 " DEF soxt->scale Scale ",
214 " scaleFactor 1 1 1",
216 " DEF soxt->geometry Coordinate3 ",
220 " -0.81 -0.04 0, -0.81 0 0,",
221 " -0.81 0.04 0, 0 -0.04 0,",
223 " 0.81 -0.04 0, 0.81 0 0,",
226 " 0.81 0.02 0, 0.81 -0.02 0,",
229 " 0.4 0.01 0, 0.4 -0.01 0,",
234 " DEF soxt->animSpeedOutlineSwitch Switch ",
239 " emissiveColor 0 0 0",
245 " 12, 11, 10, 9, -1",
250 " DEF soxt->axisSwitch Switch ",
269 " DEF soxt->animSpeedSwitch Switch ",
274 " emissiveColor 0 1 0",
280 " 16, 15, 14, 13, -1",
286 " DEF soxt->curInfoSwitch Switch ",
289 " DEF soxt->curInfoTrans Translation ",
291 " translation 10 20 30 ",
293 " DEF soxt->curInfoFont Font ",
295 " name defaultFont:Bold",
298 " DEF soxt->curInfoText Text2 ",
307 " DEF soxt->mouseOverTransLogName Translation ",
309 " translation 0 0 0 ",
311 " DEF soxt->mouseOverFontLogName Font ",
313 " name defaultFont:Bold",
316 " DEF soxt->mouseOverTextLogName Text2 { } ",
320 " DEF soxt->mouseOverTransSolid Translation ",
322 " translation 0 0 0 ",
324 " DEF soxt->mouseOverFontSolid Font ",
326 " name defaultFont:Bold",
329 " DEF soxt->mouseOverTextSolid Text2 { } ",
333 " DEF soxt->mouseOverTransMaterial Translation ",
335 " translation 0 0 0 ",
337 " DEF soxt->mouseOverFontMaterial Font ",
339 " name defaultFont:Bold",
342 " DEF soxt->mouseOverTextMaterial Text2 { } ",
346 " DEF soxt->mouseOverTransZPos Translation ",
348 " translation 0 0 0 ",
350 " DEF soxt->mouseOverFontZPos Font ",
352 " name defaultFont:Bold",
355 " DEF soxt->mouseOverTextZPos Text2 { } ",
361 for (i = bufsize = 0; superimposed[i]; i++)
362 bufsize += strlen(superimposed[i]) + 1;
363 char * buf =
new char[bufsize + 1];
364 for (i = bufsize = 0; superimposed[i]; i++) {
365 strcpy(buf + bufsize, superimposed[i]);
366 bufsize += strlen(superimposed[i]);
370 SoInput * input =
new SoInput;
371 input->setBuffer(buf, bufsize);
372 SbBool ok = SoDB::read(input, this->superimposition);
377 this->superimposition->ref();
379 this->sscale = (SoScale *) this->getSuperimpositionNode(
380 this->superimposition,
"soxt->scale");
381 this->stranslation = (SoTranslation *) this->getSuperimpositionNode(
382 this->superimposition,
"soxt->translation");
383 this->sgeometry = (SoCoordinate3 *) this->getSuperimpositionNode(
384 this->superimposition,
"soxt->geometry");
385 this->axisSwitch = (SoSwitch *) this->getSuperimpositionNode(
386 this->superimposition,
"soxt->axisSwitch");
387 this->animSpeedOutlineSwitch = (SoSwitch *) this->getSuperimpositionNode(
388 this->superimposition,
"soxt->animSpeedOutlineSwitch");
389 this->animSpeedSwitch = (SoSwitch *) this->getSuperimpositionNode(
390 this->superimposition,
"soxt->animSpeedSwitch");
391 this->curInfoSwitch = (SoSwitch *) this->getSuperimpositionNode(
392 this->superimposition,
"soxt->curInfoSwitch");
393 this->curInfoTrans = (SoTranslation *) this->getSuperimpositionNode(
394 this->superimposition,
"soxt->curInfoTrans");
395 this->curInfoFont = (SoFont *) this->getSuperimpositionNode(
396 this->superimposition,
"soxt->curInfoFont");
397 this->curInfoText = (SoText2 *) this->getSuperimpositionNode(
398 this->superimposition,
"soxt->curInfoText");
399 this->mouseOverTransLogName = (SoTranslation*)this->getSuperimpositionNode(
400 this->superimposition,
"soxt->mouseOverTransLogName");
401 this->mouseOverFontLogName = (SoFont *) this->getSuperimpositionNode(
402 this->superimposition,
"soxt->mouseOverFontLogName");
403 this->mouseOverTextLogName = (SoText2 *) this->getSuperimpositionNode(
404 this->superimposition,
"soxt->mouseOverTextLogName");
405 this->mouseOverTransSolid = (SoTranslation *) this->getSuperimpositionNode(
406 this->superimposition,
"soxt->mouseOverTransSolid");
407 this->mouseOverFontSolid = (SoFont *) this->getSuperimpositionNode(
408 this->superimposition,
"soxt->mouseOverFontSolid");
409 this->mouseOverTextSolid = (SoText2 *) this->getSuperimpositionNode(
410 this->superimposition,
"soxt->mouseOverTextSolid");
411 this->mouseOverTransMaterial = (SoTranslation*)this->getSuperimpositionNode(
412 this->superimposition,
"soxt->mouseOverTransMaterial");
413 this->mouseOverFontMaterial = (SoFont *) this->getSuperimpositionNode(
414 this->superimposition,
"soxt->mouseOverFontMaterial");
415 this->mouseOverTextMaterial = (SoText2 *) this->getSuperimpositionNode(
416 this->superimposition,
"soxt->mouseOverTextMaterial");
417 this->mouseOverTransZPos = (SoTranslation *) this->getSuperimpositionNode(
418 this->superimposition,
"soxt->mouseOverTransZPos");
419 this->mouseOverFontZPos = (SoFont *) this->getSuperimpositionNode(
420 this->superimposition,
"soxt->mouseOverFontZPos");
421 this->mouseOverTextZPos = (SoText2 *) this->getSuperimpositionNode(
422 this->superimposition,
"soxt->mouseOverTextZPos");
424 SoCallback * cb = (SoCallback *) this->getSuperimpositionNode(
425 this->superimposition,
"soxt->callback");
426 cb->setCallback(superimpositionCB,
this);
428 this->addSuperimposition(this->superimposition);
429 this->setSuperimpositionEnabled(this->superimposition,
FALSE);
430 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
431 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
432 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
460G4OpenInventorXtExaminerViewer::getSuperimpositionNode(SoNode *root,
464 this->searcher =
new SoSearchAction;
466 searcher->setName(SbName(name));
467 searcher->setInterest(SoSearchAction::FIRST);
468 searcher->setSearchingAll(
TRUE);
469 searcher->apply(root);
470 assert(searcher->getPath());
471 return searcher->getPath()->getTail();
475void G4OpenInventorXtExaminerViewer::superimpositionCB(
void * closure,
485void G4OpenInventorXtExaminerViewer::superimpositionEvent(SoAction * action)
488 if (!action->isOfType(SoGLRenderAction::getClassTypeId()))
490 SbViewportRegion vpRegion =
491 ((SoGLRenderAction *) action)->getViewportRegion();
492 SbVec2s viewportSize = vpRegion.getViewportSizePixels();
494 float aspect = float(viewportSize[0]) / float(viewportSize[1]);
495 float factorx = 1.0f / float(viewportSize[1]) * 220.0f;
496 float factory = factorx;
499 this->stranslation->translation.setValue(SbVec3f(0.0f, -0.4f, 0.0f));
501 this->stranslation->translation.setValue(
502 SbVec3f(0.0f, -0.4f / aspect, 0.0f));
506 if (viewportSize[0] > 500)
507 factorx *= 500.0f / 400.0f;
509 factorx *= float(viewportSize[0]) / 400.0f;
510 this->sscale->scaleFactor.setValue(SbVec3f(factorx, factory, 1.0f));
512 float xInfo, yInfo, xMouseLogName, yMouseLogName, xMouseSolid, yMouseSolid,
513 xMouseMaterial, yMouseMaterial, xMouseZPos, yMouseZPos;
517 yMouseLogName = -.75;
520 xMouseMaterial = 0.0;
521 yMouseMaterial = -.81;
527 xMouseSolid *= aspect;
528 xMouseMaterial *= aspect;
529 this->curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
530 this->mouseOverTransLogName->translation.setValue(
531 SbVec3f(xMouseLogName, yMouseLogName, 0.0));
532 this->mouseOverTransSolid->translation.setValue(
533 SbVec3f(xMouseSolid, yMouseSolid, 0.0));
534 this->mouseOverTransMaterial->translation.setValue(
535 SbVec3f(xMouseMaterial, yMouseMaterial, 0.0));
536 this->mouseOverTransZPos->translation.setValue(
537 SbVec3f(xMouseZPos, yMouseZPos, 0.0));
540 yMouseSolid /= aspect;
541 yMouseMaterial /= aspect;
542 this->curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
543 this->mouseOverTransLogName->translation.setValue(
544 SbVec3f(xMouseLogName, yMouseLogName, 0.0));
545 this->mouseOverTransSolid->translation.setValue(
546 SbVec3f(xMouseSolid, yMouseSolid, 0.0));
547 this->mouseOverTransMaterial->translation.setValue(
548 SbVec3f(xMouseMaterial, yMouseMaterial, 0.0));
549 this->mouseOverTransZPos->translation.setValue(
550 SbVec3f(xMouseZPos, yMouseZPos, 0.0));
553 if (currentState == VIEWPOINT) {
554 this->curInfoFont->size.setValue(15);
555 this->curInfoFont->name.setValue(
"defaultFont:Italic");
556 this->curInfoText->string.setValue(SbString(curViewPtName));
558 else if(currentState == GENERAL) {
559 this->curInfoFont->size.setValue(16);
560 this->curInfoFont->name.setValue(
"defaultFont:Bold");
561 this->curInfoText->string.setValue(SbString(
""));
564 if (refParticleIdx < (
int) refParticleTrajectory.size() - 1) {
565 this->curInfoFont->size.setValue(16);
566 this->curInfoFont->name.setValue(
"defaultFont:Bold");
569 sprintf(zPos,
"%7.2f [m]", refZPositions[refParticleIdx] / 1000);
571 this->curInfoText->string.setValue(SbString(zPos));
579 if (superimposition != NULL) {
580 removeSuperimposition(superimposition);
581 superimposition->unref();
582 superimposition = NULL;
584 if (animateSensor->isScheduled())
585 animateSensor->unschedule();
586 delete animateSensor;
587 delete sceneChangeSensor;
589 delete[] curViewPtName;
600 Atom WM_DELETE_WINDOW;
603 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::buildWidget",
"Error: Parent is null.");
606 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
607 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
608 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
609 XtSetArg(args[3], XmNbottomAttachment, XmATTACH_FORM);
610 Widget form = XmCreateForm(parent, (
char *)
"Form", args, 4);
613 shell = XtParent(form);
614 WM_DELETE_WINDOW = XInternAtom(XtDisplay(parent),
"WM_DELETE_WINDOW",
616 XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW,
617 (XtCallbackProc)closeMainWindowCB,
this);
619 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
620 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
621 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
622 menuBar = XmCreateMenuBar(form, (
char *)
"MenuBar", args, 3);
623 XtManageChild(menuBar);
626 this->
addButton(fileMenu,
"Open Viewpoint File...", openViewPtFileCB);
627 addButton(fileMenu,
"New Viewpoint File", newViewPtFileCB);
628 addButton(fileMenu,
"Load Ref. Coords", loadRefCoordsDialogCB);
629 addButton(fileMenu,
"Save Ref. Coords", saveRefCoordsDialogCB);
630 addButton(fileMenu,
"Load Scene Graph", loadSceneGraphDialogCB);
631 addButton(fileMenu,
"Save Scene Graph", saveSceneGraphDialogCB);
633 XmCreateSeparatorGadget(fileMenu, (
char *)
"Separator", NULL, 0));
635 Widget menu =
addMenu(
"Tools");
636 addButton(menu,
"Animate Ref. Particle", animateRefParticleCB);
637 addButton(menu,
"Go to start of Ref path", gotoRefPathStartCB);
638 addButton(menu,
"Invert Ref path", invertRefPathCB);
640 Widget viewerBase = SoXtFullViewer::buildWidget(form);
642 XtSetArg(args[0], XmNtopAttachment, XmATTACH_WIDGET);
643 XtSetArg(args[1], XmNtopWidget, menuBar);
644 XtSetArg(args[2], XmNleftAttachment, XmATTACH_FORM);
645 XtSetArg(args[3], XmNrightAttachment, XmATTACH_FORM);
646 XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM);
647 XtSetValues(viewerBase, args, 5);
657 Widget menu = XmCreatePulldownMenu(menuBar, (
char *) name.c_str(), NULL, 0);
659 XtSetArg(args[0], XmNsubMenuId, menu);
660 Widget w = XmCreateCascadeButton(menuBar, (
char *) name.c_str(), args, 1);
671 Widget button = XmCreatePushButton(menu, (
char *) name.c_str(), NULL, 0);
672 XtManageChild(button);
673 XtAddCallback(button, XmNactivateCallback, cb,
this);
679 SbPList * buttonlist)
683 Widget saveViewPtButton, abbrOutputButton, pickRefPathButton;
686 SoXtExaminerViewer::createViewerButtons(parent, buttonlist);
689 Widget emptyButton = XtVaCreateManagedWidget(
"", xmPushButtonWidgetClass,
691 buttonlist->append(emptyButton);
695 XtSetArg(args[n], XmNtopPosition, 1); n++;
696 XtSetArg(args[n], XmNbottomPosition, 2); n++;
697 XtSetArg(args[n], XmNleftPosition, 0); n++;
698 XtSetArg(args[n], XmNrightPosition, 1); n++;
699 XtSetArg(args[n], XmNarrowDirection, XmARROW_LEFT); n++;
700 XtSetArg(args[n], XmNsensitive, False); n++;
701 prevViewPtButton = XmCreateArrowButtonGadget(parent, (
char *)
"ArrowL",
703 XtManageChild(prevViewPtButton);
704 XtAddCallback(prevViewPtButton, XmNactivateCallback,
705 G4OpenInventorXtExaminerViewer::prevViewPtCB,
this);
706 buttonlist->append(prevViewPtButton);
710 XtSetArg(args[n], XmNtopPosition, 1); n++;
711 XtSetArg(args[n], XmNbottomPosition, 2); n++;
712 XtSetArg(args[n], XmNleftPosition, 0); n++;
713 XtSetArg(args[n], XmNrightPosition, 1); n++;
714 XtSetArg(args[n], XmNarrowDirection, XmARROW_RIGHT); n++;
715 XtSetArg(args[n], XmNsensitive, False); n++;
716 nextViewPtButton = XmCreateArrowButtonGadget(parent, (
char *)
"ArrowR",
718 XtManageChild(nextViewPtButton);
719 XtAddCallback(nextViewPtButton, XmNactivateCallback,
720 G4OpenInventorXtExaminerViewer::nextViewPtCB,
this);
721 buttonlist->append(nextViewPtButton);
724 saveViewPtButton = XtVaCreateManagedWidget(
"Save", xmPushButtonWidgetClass,
726 XtAddCallback(saveViewPtButton, XmNactivateCallback,
727 G4OpenInventorXtExaminerViewer::saveViewPtCB,
this);
728 Pixmap saveVP, saveVP_ins;
732 saveViewPt_xpm,
TRUE);
733 XtVaSetValues(saveViewPtButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
734 saveVP, XmNselectPixmap, saveVP, XmNlabelInsensitivePixmap,
735 saveVP_ins, XmNselectInsensitivePixmap, saveVP_ins, NULL);
736 buttonlist->append(saveViewPtButton);
739 abbrOutputButton = XtVaCreateManagedWidget(
"Abbr",
740 xmToggleButtonWidgetClass, parent, XmNindicatorOn, False, NULL);
741 XtAddCallback(abbrOutputButton, XmNdisarmCallback, G4OpenInventorXtExaminerViewer::abbrOutputCB,
743 Pixmap consolexpm, consolexpm_ins;
748 XtVaSetValues(abbrOutputButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
749 consolexpm, XmNselectPixmap, consolexpm, XmNlabelInsensitivePixmap,
750 consolexpm_ins, XmNselectInsensitivePixmap, consolexpm_ins, NULL);
751 buttonlist->append(abbrOutputButton);
754 pickRefPathButton = XtVaCreateManagedWidget(
"Refpath", xmPushButtonWidgetClass,
756 XtAddCallback(pickRefPathButton, XmNactivateCallback,
757 G4OpenInventorXtExaminerViewer::pickRefPathCB,
this);
758 Pixmap favoritesxpm, favoritesxpm_ins;
762 favorites_xpm,
TRUE);
763 XtVaSetValues(pickRefPathButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
764 favoritesxpm, XmNselectPixmap, favoritesxpm, XmNlabelInsensitivePixmap,
765 favoritesxpm_ins, XmNselectInsensitivePixmap, favoritesxpm_ins, NULL);
766 buttonlist->append(pickRefPathButton);
775 SoXtExaminerViewer::afterRealizeHook();
779 SoCamera *cam = getCamera();
781 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
783 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
786 ((SoOrthographicCamera *) cam)->height.getValue();
790 ((SoOrthographicCamera *) cam)->height.getValue();
793 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
795 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
801 fileIn.open(fileName.c_str());
802 if (!fileIn.fail()) {
804 String dialogName = (
char *)
"Error Loading File";
805 std::string msg =
"Wrong or corrupted input file.";
809 fileOut.open(fileName.c_str(), std::ios::in);
810 fileOut.seekp(0, std::ios::end);
811 constructListsDialog(getParentWidget(),
this, NULL);
813 if (viewPtList.size()) {
817 XtSetSensitive(nextViewPtButton, True);
818 XtSetSensitive(prevViewPtButton, True);
825 fileOut.open(fileName.c_str());
826 constructListsDialog(getParentWidget(),
this, NULL);
831 SoSeparator *root = (SoSeparator *) (getSceneManager()->getSceneGraph());
833 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::afterRealizeHook",
"Root is null.");
835 root->addChild(myCam);
838 sceneChangeSensor =
new SoNodeSensor;
839 sceneChangeSensor->setFunction(sceneChangeCB);
840 sceneChangeSensor->attach(root);
841 sceneChangeSensor->setData(
this);
847 SoEventCallback *moCB =
new SoEventCallback;
848 moCB->addEventCallback(
849 SoLocation2Event::getClassTypeId(),
850 mouseoverCB,
static_cast<void *
>(
this));
851 root->addChild(moCB);
855 SoEventCallback *pickCB =
new SoEventCallback;
856 pickCB->addEventCallback(
857 SoMouseButtonEvent::getClassTypeId(),
858 pickingCB,
static_cast<void *
>(
this));
859 root->addChild(pickCB);
868 SoCamera *cam = getCamera();
874 SbVec3f camPosNew = prevPt - (
camDir*distance);
875 cam->position = camPosNew;
877 cam->focalDistance = (prevPt - camPosNew).length();
881 if (animateSensorRotation->isScheduled()) {
882 animateSensorRotation->unschedule();
885 animateSensorRotation->setBaseTime(SbTime::getTimeOfDay());
886 animateSensorRotation->setInterval(SbTime(0.02));
887 animateSensorRotation->schedule();
896 SoCamera *cam = getCamera();
901 if(refParticleTrajectory.size() == 0) {
906 distance = (cam->position.getValue() - center).length();
908 cam->position.setValue(center + offsetFromCenter*distance);
909 cam->focalDistance = (cam->position.getValue() - center).length();
910 cam->pointAt(center, upVector);
916 if (refParticleIdx >= (
int) refParticleTrajectory.size() - 1) {
917 prevPt = refParticleTrajectory[refParticleIdx - step];
918 dist = (prevPt - cam->position.getValue()).length();
923 if (refParticleIdx < 0) {
924 prevPt = refParticleTrajectory[refParticleIdx + step];
925 dist = (prevPt - cam->position.getValue()).length();
926 refParticleIdx = refParticleTrajectory.size() - 2;
930 p1 = refParticleTrajectory[refParticleIdx];
931 p2 = refParticleTrajectory[refParticleIdx + step];
934 particleDir = p2 - p1;
935 particleDir.normalize();
937 if(prevParticleDir == SbVec3f(0,0,0)){
948 SbRotation rot(SbVec3f(0,0,1), particleDir);
953 else if(particleDir != prevParticleDir) {
956 SbRotation rot(prevParticleDir, particleDir);
962 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
964 distance = (prevPt - cam->position.getValue()).length();
969 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
971 distance = (prevPt - cam->position.getValue()).length();
978 prevPt.getValue(x,y,z);
981 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
982 camPosNew = p2 - (
camDir*distance);
984 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
985 camPosNew = p2 - (
camDir);
988 cam->position = camPosNew;
995 camPosNew.getValue(x,y,z);
997 prevParticleDir = particleDir;
1005void G4OpenInventorXtExaminerViewer::pickingCB(
void *aThis,
1006 SoEventCallback *eventCB)
1008 SoHandleEventAction* action = eventCB->getAction();
1009 const SoPickedPoint *pp = action->getPickedPoint();
1014 SoPath* path = pp->getPath();
1015 SoNode* node = ((SoFullPath*)path)->getTail();
1017 if(node->getTypeId() == SoLineSet::getClassTypeId()){
1024 This->setComponentCursor(SoXtCursor(SoXtCursor::DEFAULT));
1027 SoLineSet * trajectory = (SoLineSet *)node;
1033 SoSeparator * grpNode =
1034 (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1039 int nodeIndex = grpNode->findChild(trajectory);
1042 SoCoordinate3 * coords = 0;
1046 for(
int i = 0; i < 100; ++i) {
1049 tmpNode = grpNode->getChild(nodeIndex);
1050 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()){
1052 coords = (SoCoordinate3 *)tmpNode;
1058 String dialogName = (
char *)
"No coordinates";
1059 std::string msg =
"Could not find the coordinates node"
1060 " for the picked trajectory."
1061 " Reference trajectory not set";
1067 if ((This->lshiftdown) || (This->rshiftdown))
1068 This->setReferencePath(trajectory, coords,
true);
1070 This->setReferencePath(trajectory, coords,
false);
1078 if(attHolder && attHolder->
GetAttDefs().size()) {
1080 std::string strTrajPoint =
"G4TrajectoryPoint:";
1081 std::ostringstream oss;
1082 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1087 if(oss.str().find(strTrajPoint) != std::string::npos) {
1101 G4String name((
char*)node->getName().getString());
1102 G4String cls((
char*)node->getTypeId().getName().getString());
1103 G4cout <<
"SoNode : " << node
1104 <<
" SoType : " << cls
1105 <<
" name : " << name
1122 if(attHolder && attHolder->
GetAttDefs().size()) {
1123 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1128 G4String name((
char*)node->getName().getString());
1129 G4String cls((
char*)node->getTypeId().getName().getString());
1130 G4cout <<
"SoNode : " << node
1131 <<
" SoType : " << cls
1132 <<
" name : " << name
1138 eventCB->setHandled();
1143void G4OpenInventorXtExaminerViewer::mouseoverCB(
void *aThis, SoEventCallback *eventCB)
1145 SoHandleEventAction* action = eventCB->getAction();
1146 const SoPickedPoint *
pp = action->getPickedPoint();
1154 const SbViewportRegion & viewportRegion = action->getViewportRegion();
1156 std::string sLogName;
1158 std::stringstream ssZPos;
1159 std::stringstream ssSolids;
1160 std::stringstream ssMaterials;
1161 SoPath * path =
pp->getPath();
1162 SoNode* node = ((SoFullPath*)path)->getTail();
1164 if(node->getTypeId() == Geant4_SoPolyhedron::getClassTypeId()) {
1166 sLogName =
"Logical Volume: ";
1169 SoGetBoundingBoxAction bAction(viewportRegion);
1170 bAction.apply((SoFullPath*)path);
1171 SbBox3f bBox = bAction.getBoundingBox();
1172 SbVec3f center = bBox.getCenter();
1173 center.getValue(x,y,z);
1174 ssZPos <<
"Pos: " << x <<
" " << y <<
" " << z;
1177 if(attHolder && attHolder->
GetAttDefs().size()) {
1179 std::vector<const std::map<G4String,G4AttDef>*> vecDefs =
1181 std::vector<const std::vector<G4AttValue>*> vecVals =
1183 for (
size_t i = 0; i < vecDefs.size(); ++i) {
1184 const std::vector<G4AttValue> * vals = vecVals[i];
1186 std::vector<G4AttValue>::const_iterator iValue;
1188 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1189 const G4String& valueName = iValue->GetName();
1190 const G4String& value = iValue->GetValue();
1192 if(valueName ==
"Solid") {
1193 if(ssSolids.str() ==
"")
1194 ssSolids <<
"Solid Name: " << value;
1196 ssSolids <<
", " << value;
1199 if(valueName ==
"Material") {
1200 if(ssMaterials.str() ==
"")
1201 ssMaterials <<
"Material Name: " << value;
1203 ssMaterials <<
", " << value;
1210 bool redraw =
false;
1211 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) != sLogName) {
1212 This->mouseOverTextLogName->string.setValue(SbString(sLogName.c_str()));
1215 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) != ssSolids.str()) {
1216 This->mouseOverTextSolid->string.setValue(SbString(ssSolids.str().c_str()));
1219 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) != ssMaterials.str()){
1220 This->mouseOverTextMaterial->string.setValue(SbString(ssMaterials.str().c_str()));
1223 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) != ssZPos.str()) {
1224 This->mouseOverTextZPos->string.setValue(SbString(ssZPos.str().c_str()));
1229 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
1230 This->scheduleRedraw();
1233 eventCB->setHandled();
1236 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) !=
"") {
1237 This->mouseOverTextLogName->string.setValue(SbString(
""));
1238 This->scheduleRedraw();
1240 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) !=
"") {
1241 This->mouseOverTextSolid->string.setValue(SbString(
""));
1242 This->scheduleRedraw();
1244 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) !=
"") {
1245 This->mouseOverTextMaterial->string.setValue(SbString(
""));
1246 This->scheduleRedraw();
1248 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) !=
"") {
1249 This->mouseOverTextZPos->string.setValue(SbString(
""));
1250 This->scheduleRedraw();
1257 SoCamera *cam = getCamera();
1258 const SoType type(ev->getTypeId());
1260 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
1261 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
1263 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1264 || currentState == PAUSED_ANIMATION) {
1265 switch (me->getButton()) {
1266 case SoMouseButtonEvent::BUTTON4:
1267 if (me->getState() == SoButtonEvent::DOWN) {
1268 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1270 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1271 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1274 }
else if (cam->isOfType(
1275 SoOrthographicCamera::getClassTypeId())) {
1277 ((SoOrthographicCamera *) cam)->height.getValue();
1278 ((SoOrthographicCamera *) cam)->height = height + 5;
1283 case SoMouseButtonEvent::BUTTON5:
1284 if (me->getState() == SoButtonEvent::DOWN) {
1285 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1287 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1289 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1292 }
else if (cam->isOfType(
1293 SoOrthographicCamera::getClassTypeId())) {
1295 ((SoOrthographicCamera *) cam)->height.getValue();
1297 ((SoOrthographicCamera *) cam)->height = height - 5;
1306 if (currentState == GENERAL) {
1311 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
1312 SoKeyboardEvent * ke = (SoKeyboardEvent *) ev;
1314 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
1315 switch (ke->getKey()) {
1316 case SoKeyboardEvent::LEFT_SHIFT:
1317 this->lshiftdown =
true;
1319 case SoKeyboardEvent::RIGHT_SHIFT:
1320 this->rshiftdown =
true;
1322 case SoKeyboardEvent::LEFT_CONTROL:
1323 this->lctrldown =
true;
1325 case SoKeyboardEvent::RIGHT_CONTROL:
1326 this->rctrldown =
true;
1328 case SoKeyboardEvent::SPACE:
1329 if (currentState == ANIMATION
1330 || currentState == REVERSED_ANIMATION) {
1331 beforePausing = currentState;
1332 currentState = PAUSED_ANIMATION;
1333 if (animateSensor->isScheduled())
1334 animateSensor->unschedule();
1336 }
else if (currentState == PAUSED_ANIMATION) {
1338 if ((beforePausing == ANIMATION
1340 < (
int) refParticleTrajectory.size() - 1)
1341 || (beforePausing == REVERSED_ANIMATION
1342 && refParticleIdx > 0)) {
1343 currentState = beforePausing;
1344 animateRefParticle();
1350 case SoKeyboardEvent::ESCAPE:
1351 if (currentState == ANIMATION
1352 || currentState == REVERSED_ANIMATION
1353 || currentState == PAUSED_ANIMATION) {
1355 if (animateSensor->isScheduled())
1356 animateSensor->unschedule();
1357 currentState = prevState;
1358 refParticleIdx = prevRefIdx;
1359 setSuperimpositionEnabled(superimposition,
FALSE);
1364 if (currentState == VIEWPOINT) {
1365 setSuperimpositionEnabled(superimposition,
TRUE);
1366 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
1367 animSpeedOutlineSwitch->whichChild.setValue(
1369 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1377 case SoKeyboardEvent::DELETE:
1378 if (viewPtList.size()
1379 && (currentState != ANIMATION
1380 || currentState != REVERSED_ANIMATION
1381 || currentState != PAUSED_ANIMATION)) {
1382 String dialogName = (
char *)
"Delete Viewpoint";
1383 std::string msg =
"Are you sure you want to delete current viewpoint?";
1388 case SoKeyboardEvent::LEFT_ARROW:
1389 switch (currentState) {
1391 if ((this->lshiftdown) || (this->rshiftdown)){
1392 refParticleIdx -= step;
1395 else if ((this->lctrldown) || (this->rctrldown)){
1396 if (SoXtExaminerViewer::isAnimating())
1398 prevState = currentState;
1399 currentState = ROTATING;
1400 animateBtwPtsPeriod = 0.08f;
1412 if (SoXtExaminerViewer::isAnimating())
1414 prevState = currentState;
1415 currentState = ROTATING;
1416 animateBtwPtsPeriod = 0.08f;
1431 case REVERSED_ANIMATION:
1434 case PAUSED_ANIMATION:
1436 setStartingPtForAnimation();
1437 cam->position = myCam->position;
1441 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1444 this->bottomWheelMotion(
1445 this->getBottomWheelValue() + 0.1f);
1455 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1456 "Unhandled viewer state");
1461 case SoKeyboardEvent::RIGHT_ARROW:
1462 switch(currentState){
1464 if ((this->lshiftdown) || (this->rshiftdown)){
1465 refParticleIdx += step;
1468 else if ((this->lctrldown) || (this->rctrldown)){
1469 if (SoXtExaminerViewer::isAnimating())
1471 prevState = currentState;
1472 currentState = ROTATING;
1473 animateBtwPtsPeriod = 0.08f;
1483 if (SoXtExaminerViewer::isAnimating())
1485 prevState = currentState;
1486 currentState = ROTATING;
1487 animateBtwPtsPeriod = 0.08f;
1499 case REVERSED_ANIMATION:
1502 case PAUSED_ANIMATION:
1504 setStartingPtForAnimation();
1505 cam->position = myCam->position;
1509 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1512 this->bottomWheelMotion(
1513 this->getBottomWheelValue() - 0.1f);
1522 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1523 "Unhandled viewer state");
1528 case SoKeyboardEvent::DOWN_ARROW:
1529 switch(currentState){
1532 if ((this->lshiftdown) || (this->rshiftdown)){
1533 refParticleIdx -= step;
1537 if (SoXtExaminerViewer::isAnimating())
1539 prevState = currentState;
1540 currentState = ROTATING;
1541 animateBtwPtsPeriod = 0.08f;
1554 case REVERSED_ANIMATION:
1557 case PAUSED_ANIMATION:
1559 setStartingPtForAnimation();
1560 cam->position = myCam->position;
1566 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1567 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
1576 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1577 "Unhandled viewer state");
1582 case SoKeyboardEvent::UP_ARROW:
1583 switch(currentState){
1585 if ((this->lshiftdown) || (this->rshiftdown)){
1586 refParticleIdx -= step;
1590 if (SoXtExaminerViewer::isAnimating())
1592 prevState = currentState;
1593 currentState = ROTATING;
1594 animateBtwPtsPeriod = 0.08f;
1607 case REVERSED_ANIMATION:
1610 case PAUSED_ANIMATION:
1612 setStartingPtForAnimation();
1613 cam->position = myCam->position;
1619 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1620 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
1629 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::processSoEvent",
1630 "Unhandled viewer state");
1635 case SoKeyboardEvent::PAGE_UP:
1636 switch(currentState){
1638 if (step < (
int) refParticleTrajectory.size() / 5)
1649 case REVERSED_ANIMATION:
1650 if(!animateSensor->isScheduled()){
1651 currentState = ANIMATION;
1653 < (
int) refParticleTrajectory.size() - 1) {
1657 animateRefParticle();
1666 case PAUSED_ANIMATION:
1671 if (beforePausing == ANIMATION) {
1676 beforePausing = ANIMATION;
1686 case SoKeyboardEvent::PAGE_DOWN:
1687 switch(currentState){
1693 if(!animateSensor->isScheduled()){
1694 currentState = REVERSED_ANIMATION;
1695 if (refParticleIdx > 1) {
1699 animateRefParticle();
1708 case REVERSED_ANIMATION:
1711 if (maxSpeed < -0.8)
1715 case PAUSED_ANIMATION:
1717 if (maxSpeed < -0.8)
1719 if (beforePausing == REVERSED_ANIMATION) {
1724 beforePausing = REVERSED_ANIMATION;
1734 case SoKeyboardEvent::E:
1735 this->escapeCallback(this->examinerObject);
1742 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
1743 switch (ke->getKey()) {
1744 case SoKeyboardEvent::LEFT_SHIFT:
1745 this->lshiftdown =
false;
1747 case SoKeyboardEvent::RIGHT_SHIFT:
1748 this->rshiftdown =
false;
1750 case SoKeyboardEvent::LEFT_CONTROL:
1751 this->lctrldown =
false;
1753 case SoKeyboardEvent::RIGHT_CONTROL:
1754 this->rctrldown =
false;
1762 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1763 || currentState == ROTATING)
1766 return SoXtExaminerViewer::processSoEvent(ev);
1770void G4OpenInventorXtExaminerViewer::incSpeed() {
1771 if (std::ceil(animateBtwPtsPeriod * 100) >= 4) {
1772 if (speedStep > 0.08)
1776 animateBtwPtsPeriod -= speedStep;
1778 animateBtwPtsPeriod = 0.0;
1780 if (currentState != PAUSED_ANIMATION) {
1781 int lastIdx = refParticleTrajectory.size() - 1;
1782 if (refParticleIdx < lastIdx && !animateSensor->isScheduled())
1783 animateRefParticle();
1788void G4OpenInventorXtExaminerViewer::decSpeed() {
1789 animateBtwPtsPeriod += speedStep;
1791 if (std::floor(animateBtwPtsPeriod * 100) == 12) {
1793 }
else if (animateBtwPtsPeriod > 0.12)
1799 if (animateSensor->isScheduled())
1800 animateSensor->unschedule();
1805void G4OpenInventorXtExaminerViewer::updateSpeedIndicator(
void) {
1806 assert(this->sgeometry != NULL);
1808 SbVec3f * points = this->sgeometry->point.startEditing();
1810 if (points[10][0] == 0.0f)
1811 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
1812 if (points[14][0] == 0.0f)
1813 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
1814 points[10][0] = this->maxSpeed;
1815 points[11][0] = this->maxSpeed;
1816 points[14][0] = this->maxSpeed;
1817 points[15][0] = this->maxSpeed;
1818 this->sgeometry->point.finishEditing();
1820 if (this->maxSpeed == 0.0f) {
1821 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
1822 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1826void G4OpenInventorXtExaminerViewer::actualRedraw(
void) {
1827 switch (currentState) {
1829 case REVERSED_ANIMATION:
1830 case PAUSED_ANIMATION:
1831 updateSpeedIndicator();
1832 SoXtExaminerViewer::actualRedraw();
1835 SoXtExaminerViewer::actualRedraw();
1840void G4OpenInventorXtExaminerViewer::setReferencePath(SoLineSet *lineset, SoCoordinate3 *coords,
bool append)
1881 SbVec3f refParticlePt;
1884 this->refParticleTrajectory.clear();
1886 for(
int i = 0; i < lineset->numVertices.getNum(); ++i){
1887 for(
int j = 0; j < lineset->numVertices[i]; ++j){
1888 refParticlePt = coords->point[j];
1889 this->refParticleTrajectory.push_back(refParticlePt);
1893 this->evenOutRefParticlePts();
1894 this->setReferencePathZPos();
1895 this->sortElements();
1899void G4OpenInventorXtExaminerViewer::setReferencePathZPos()
1901 refZPositions.clear();
1902 refZPositions.push_back(0);
1904 for(
unsigned int i=0; i < this->refParticleTrajectory.size() - 1; ++i){
1905 dist = (refParticleTrajectory[i] -
1906 refParticleTrajectory[i + 1]).length();
1907 refZPositions.push_back(refZPositions[i] + dist);
1912void G4OpenInventorXtExaminerViewer::findAndSetRefPath()
1914 SoSearchAction action;
1915 action.setType(SoLineSet::getClassTypeId(),
false);
1916 action.setInterest(SoSearchAction::ALL);
1917 action.apply(this->getSceneGraph());
1919 SoPathList &pathList = action.getPaths();
1921 if(pathList.getLength() != 0){
1923 SoCoordinate3 * coords = NULL;
1924 std::vector<SoCoordinate3 *> coordvec;
1925 std::vector<SoLineSet *> linevec;
1927 bool refPathFound =
false;
1928 for(
int i = 0; i < pathList.getLength(); ++i) {
1929 SoFullPath *path = (SoFullPath *)pathList[i];
1932 for (
size_t j = 0; j < attHolder->
GetAttDefs().size(); ++j) {
1933 std::ostringstream oss;
1936 std::string findStr =
"Type of trajectory (Type): ";
1937 std::string compareValue =
"REFERENCE";
1938 size_t idx = oss.str().find(findStr);
1940 if(idx != std::string::npos) {
1941 if(oss.str().substr(idx + findStr.size(), compareValue.size()) == compareValue) {
1942 coords = this->getCoordsNode(path);
1944 refPathFound =
true;
1945 coordvec.push_back(coords);
1946 linevec.push_back((SoLineSet *)path->getTail());
1952 findStr =
"Track ID (ID): ";
1953 idx = oss.str().find(findStr);
1954 if(idx != std::string::npos) {
1956 std::string tmpstr = oss.str().substr(idx + findStr.size(),1);
1957 std::istringstream
buffer(tmpstr);
1964 const char * nextChar =
1965 oss.str().substr(idx + findStr.size() + 1,1).c_str();
1966 if(std::isdigit(nextChar[0]))
1969 coords = this->getCoordsNode(path);
1971 coordvec.push_back(coords);
1972 linevec.push_back((SoLineSet *)path->getTail());
1988 if(coordvec.empty())
1993 this->setReferencePath(linevec.back(), coordvec.back());
1999 float longestLength = 0.0;
2001 for(
unsigned int i=0;i < linevec.size(); ++i){
2004 std::vector<SbVec3f> trajectory;
2006 for(
int j=0; j < linevec[i]->numVertices.getNum(); ++j){
2008 for(
int k=0; k < linevec[i]->numVertices[j]; ++k){
2009 trajectory.push_back(coordvec[i]->point[k]);
2014 float tmpLength=0.0;
2015 for(
unsigned int j=0; j < trajectory.size() - 1; ++j){
2016 tmpLength += (trajectory[j] - trajectory[j + 1]).length();
2019 if(tmpLength > longestLength){
2021 longestLength = tmpLength;
2026 this->setReferencePath(linevec[longestIdx], coordvec[longestIdx]);
2031SoCoordinate3 * G4OpenInventorXtExaminerViewer::getCoordsNode(SoFullPath *path)
2033 SoLineSet *trajectory = (SoLineSet *)path->getTail();
2034 SoSeparator * grpNode = (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
2035 int nodeIndex = grpNode->findChild(trajectory);
2040 for(
int i = 0; i < 100; ++i){
2043 tmpNode = grpNode->getChild(nodeIndex);
2044 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()){
2046 return (SoCoordinate3 *)tmpNode;
2055void G4OpenInventorXtExaminerViewer::getSceneElements()
2057 std::string field, eltName;
2059 std::map<std::string, int> duplicates;
2060 std::map<std::string, int> sceneElts;
2061 SoSearchAction search;
2063 SoGroup *root = (SoGroup *)getSceneManager()->getSceneGraph();
2065 SoBaseKit::setSearchingChildren(
TRUE);
2068 search.setSearchingAll(
TRUE);
2069 search.setInterest(SoSearchAction::ALL);
2070 search.setType(Geant4_SoPolyhedron::getClassTypeId(), 0);
2073 SoPathList &pl = search.getPaths();
2077 for(
int i = 0; i < pl.getLength(); i++) {
2078 SoFullPath *path = (SoFullPath *)pl[i];
2080 eltName = node->getName();
2081 if(duplicates.count(eltName))
2082 duplicates[eltName]++;
2084 duplicates[eltName] = 1;
2087 for(
int i = 0; i < pl.getLength(); i++) {
2089 std::stringstream ssCount;
2090 SoFullPath *path = (SoFullPath *)pl[i];
2092 eltName = node->getName();
2094 if(duplicates[eltName] == 1)
2097 if(sceneElts.count(eltName))
2098 sceneElts[eltName]++;
2100 sceneElts[eltName] = 1;
2102 ssCount << sceneElts[eltName];
2106 field += ssCount.str();
2108 SoGetBoundingBoxAction bAction(getViewportRegion());
2109 bAction.apply(path);
2110 SbBox3f bBox = bAction.getBoundingBox();
2112 SbVec3f centr = bBox.getCenter();
2113 centr.getValue(x,y,z);
2116 sceneElement el = { field, path, centr, 0.0 };
2117 this->sceneElements.push_back(el);
2122float G4OpenInventorXtExaminerViewer::sqrlen(
const SbVec3f &a)
2126 return x*x + y*y + z*z;
2130void G4OpenInventorXtExaminerViewer::distanceToTrajectory(
const SbVec3f &q,
2132 SbVec3f &closestPoint,
2167 const size_t count = this->refParticleTrajectory.size();
2170 SbVec3f b = this->refParticleTrajectory[0];
2171 SbVec3f dbq = b - q;
2172 float sqrDist = sqrlen(dbq);
2175 for (
size_t i = 1; i < count; ++i) {
2176 const SbVec3f a = b;
2177 const SbVec3f daq = dbq;
2178 b = this->refParticleTrajectory[i];
2180 const SbVec3f dab = a - b;
2182 float dab_x, dab_y, dab_z;
2183 dab.getValue(dab_x,dab_y,dab_z);
2184 float daq_x, daq_y, daq_z;
2185 daq.getValue(daq_x, daq_y, daq_z);
2186 float dbq_x, dbq_y, dbq_z;
2187 dbq.getValue(dbq_x, dbq_y, dbq_z);
2189 const float inv_sqrlen = 1./sqrlen(dab);
2190 const float t = (dab_x*daq_x + dab_y*daq_y + dab_z*daq_z)*inv_sqrlen;
2201 current_dist = daq_x*daq_x + daq_y*daq_y + daq_z*daq_z
2202 - t*(daq_x*dab_x + daq_y*dab_y + daq_z*dab_z)
2203 + t*t*(dab_x*dab_x + dab_y*dab_y + dab_z*dab_z);
2208 current_dist = sqrlen(dbq);
2211 if (current_dist < sqrDist){
2212 sqrDist = current_dist;
2213 closestPoint = a + t*(b-a);
2218 dist = std::sqrt(sqrDist);
2222void G4OpenInventorXtExaminerViewer::sortElements()
2224 if(this->refParticleTrajectory.empty())
2227 float * trajLength =
new float[this->refParticleTrajectory.size()];
2228 typedef std::map<elementForSorting, sceneElement> sortedMap;
2234 std::vector<SbVec3f>::iterator itRef = this->refParticleTrajectory.begin();
2237 trajLength[trajIndex] = 0.0;
2240 for(; itRef != this->refParticleTrajectory.end(); ++itRef, ++trajIndex){
2241 trajLength[trajIndex] = trajLength[trajIndex-1] + (*itRef - prevPoint).length();
2249 SoGetBoundingBoxAction bAction(this->getViewportRegion());
2250 SbVec3f elementCoord;
2251 std::vector<sceneElement>::iterator itEl;
2253 elementForSorting el;
2254 for(itEl = this->sceneElements.begin(), elementIndex = 0;
2255 itEl != this->sceneElements.end(); ++itEl, ++elementIndex){
2256 bAction.apply(itEl->path);
2257 elementCoord = bAction.getBoundingBox().getCenter();
2260 distanceToTrajectory(elementCoord, el.smallestDistance, el.closestPoint, index);
2261 itEl->closestPointZCoord = el.closestPointZCoord = trajLength[index];
2262 el.distanceToBeamlineStart = (itEl->center - this->refParticleTrajectory[0]).length();
2269 sorted.insert(std::make_pair(el,*itEl));
2273 this->sceneElements.clear();
2275 sortedMap::iterator itSorted = sorted.begin();
2276 for(; itSorted != sorted.end(); itSorted++)
2277 this->sceneElements.push_back(itSorted->second);
2279 this->zcoordSetFlag =
true;
2282 Widget formTop = XtNameToWidget(this->listsDialog,
"FormTop");
2283 Widget formTopRight = XtNameToWidget(formTop,
"FormTopRight");
2285 this->createElementsList(formTopRight);
2287 delete[] trajLength;
2291void G4OpenInventorXtExaminerViewer::createElementsList(Widget formTopRight)
2293 if(this->myElementList != NULL)
2294 XtUnmanageChild(this->myElementList);
2296 int size = this->sceneElements.size();
2297 XmString *elements = (XmString *) XtMalloc(size *
sizeof(XmString));
2299 std::vector<sceneElement>::const_iterator it;
2301 std::stringstream ss;
2302 for(it=this->sceneElements.begin(); it!=this->sceneElements.end(); ++it) {
2305 ss <<
" [" << it->closestPointZCoord <<
"]";
2306 elements[count] = XmStringCreateLocalized((
char *)ss.str().c_str());
2317 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2319 labelRight = XmCreateLabelGadget(formTopRight, (
char*)
"Element [S mm]",
2321 XtManageChild(labelRight);
2325 XtSetArg(args[n], XmNvisibleItemCount, 7);
n++;
2326 XtSetArg(args[n], XmNitemCount, size);
n++;
2327 XtSetArg(args[n], XmNitems, elements);
n++;
2328 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2329 XtSetArg(args[n], XmNtopWidget, labelRight);
n++;
2330 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2331 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2332 XtSetArg(args[n], XmNwidth, 280);
n++;
2335 this->myElementList = XmCreateScrolledList(formTopRight, (
char *)
"ListRight", args, n);
2337 XtAddCallback(this->myElementList, XmNbrowseSelectionCallback,
2338 (XtCallbackProc) lookAtSceneElementCB,
this);
2340 XtManageChild(this->myElementList);
2342 if (elements != NULL) {
2343 for (
int i = 0; i < size; i++)
2344 XmStringFree(elements[i]);
2345 XtFree((
char *) elements);
2353void G4OpenInventorXtExaminerViewer::constructListsDialog(Widget w,
2354 XtPointer client_data,
2358 if (This->listsDialog) {
2362 if (This->currentState == ANIMATION || This->currentState == PAUSED_ANIMATION) {
2363 if (This->animateSensor->isScheduled())
2364 This->animateSensor->unschedule();
2365 This->refParticleIdx = This->prevRefIdx;
2366 This->restoreCamera();
2367 This->currentState = This->prevState;
2371 This->refParticleIdx = 0;
2372 if (This->refParticleTrajectory.size()){
2373 This->prevPt = This->refParticleTrajectory[0];
2376 This->getSceneElements();
2380 Atom WM_DELETE_WINDOW;
2385 topShell = SoXt::getShellWidget(This->getParentWidget());
2388 std::string dialogNameStr = This->fileName.substr(This->fileName.rfind(
'/') + 1);
2389 char *dialogName =
new char[dialogNameStr.size() + 1];
2390 strcpy(dialogName, dialogNameStr.c_str());
2393 XtSetArg(args[n], XmNx, 610);
n++;
2394 This->myShellDialog = XmCreateDialogShell(topShell, dialogName, args, n);
2396 delete[] dialogName;
2397 WM_DELETE_WINDOW = XInternAtom(XtDisplay(w),
"WM_DELETE_WINDOW", False);
2398 XmAddWMProtocolCallback(This->myShellDialog, WM_DELETE_WINDOW,
2399 (XtCallbackProc)closeListsDialogCB, This);
2403 XtSetArg(args[n], XmNsashWidth, 1);
n++;
2404 XtSetArg(args[n], XmNsashHeight, 1);
n++;
2405 XtSetArg(args[n], XmNseparatorOn, False);
n++;
2406 This->listsDialog = XmCreatePanedWindow(This->myShellDialog, (
char *)
"MainPane",
2412 Widget formTop = XmCreateForm(This->listsDialog, (
char *)
"FormTop", args, n);
2415 XtSetArg(args[n], XmNmarginWidth, 8);
n++;
2416 XtSetArg(args[n], XmNmarginHeight, 8);
n++;
2417 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2418 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2419 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2420 Widget formTopRight = XmCreateForm(formTop, (
char *)
"FormTopRight", args,
2424 XtSetArg(args[n], XmNmarginWidth, 8);
n++;
2425 XtSetArg(args[n], XmNmarginHeight, 8);
n++;
2426 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2427 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2428 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET);
n++;
2429 XtSetArg(args[n], XmNrightWidget, formTopRight);
n++;
2430 XtSetArg(args[n], XmNrightOffset, 10);
n++;
2431 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2432 Widget formTopLeft = XmCreateForm(formTop, (
char *)
"FormTopLeft", args, n);
2436 This->createElementsList(formTopRight);
2437 XtManageChild(formTopRight);
2443 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);
n++;
2444 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2445 Widget labelLeft = XmCreateLabelGadget(formTopLeft, (
char *)
"ViewPoints",
2447 XtManageChild(labelLeft);
2451 XtSetArg(args[n], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE);
n++;
2452 XtSetArg(args[n], XmNvisibleItemCount, 7);
n++;
2454 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2455 XtSetArg(args[n], XmNtopWidget, labelLeft);
n++;
2456 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET);
n++;
2457 XtSetArg(args[n], XmNrightWidget, This->myElementList);
n++;
2458 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2459 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);
n++;
2460 XtSetArg(args[n], XmNwidth, 200);
n++;
2462 This->myViewPtList = XmCreateScrolledList(formTopLeft, (
char *)
"ListLeft",
2464 if (This->viewPtList.size())
2465 This->addViewPoints();
2466 XtAddCallback(This->myViewPtList, XmNbrowseSelectionCallback,
2467 (XtCallbackProc) loadBookmarkCB, This);
2470 XtManageChild(This->myViewPtList);
2472 XtManageChild(formTopLeft);
2474 XtManageChild(formTop);
2478 XtSetArg(args[n], XmNmarginWidth, 6);
n++;
2479 Widget formMiddle = XmCreateForm(This->listsDialog, (
char *)
"MiddleForm", args,
2484 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2485 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2486 XtSetArg(args[n], XmNtopWidget, This->myViewPtList);
n++;
2487 Widget label = XmCreateLabelGadget(formMiddle, (
char *)
"Selection", args,
2489 XtManageChild(label);
2493 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2494 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2495 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2496 XtSetArg(args[n], XmNtopWidget, label);
n++;
2497 XtSetArg(args[n], XmNtopOffset, 3);
n++;
2498 XtSetArg(args[n], XmNmaxLength, This->MAX_VP_NAME);
n++;
2499 This->viewPtSelection = XmCreateText(formMiddle, (
char *)
"Txt", args, n);
2500 XtManageChild(This->viewPtSelection);
2502 Dimension h1, h2, h;
2503 XtVaGetValues(label, XmNheight, &h1, NULL);
2504 XtVaGetValues(This->viewPtSelection, XmNheight, &h2, NULL);
2506 h = (Dimension) (1.1 * (h1 + h2));
2508 XtVaSetValues(formMiddle, XmNpaneMaximum, h, XmNpaneMinimum, h, NULL);
2509 XtManageChild(formMiddle);
2514 XtSetArg(args[n], XmNfractionBase, 4);
n++;
2515 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET);
n++;
2516 XtSetArg(args[n], XmNtopWidget, This->viewPtSelection);
n++;
2517 Widget formAction = XmCreateForm(This->listsDialog, (
char *)
"ActionForm", args,
2521 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);
n++;
2522 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);
n++;
2523 XtSetArg(args[n], XmNtopOffset, 3);
n++;
2524 XtSetArg(args[n], XmNbottomOffset, 5);
n++;
2525 Widget separator = XmCreateSeparatorGadget(formAction, (
char *)
"Sep", args, n);
2527 XtManageChild(separator);
2529 Widget button = XmCreatePushButton(formAction, (
char *)
"Delete", NULL, 0);
2530 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2531 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2532 XmATTACH_POSITION, XmNleftPosition, 0, XmNrightAttachment,
2533 XmATTACH_POSITION, XmNrightPosition, 1,
2534 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2537 XtAddCallback(button, XmNactivateCallback,
2538 (XtCallbackProc) deleteBookmarkCB, This);
2539 XtManageChild(button);
2541 button = XmCreatePushButton(formAction, (
char *)
"Rename", NULL, 0);
2542 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2543 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2544 XmATTACH_POSITION, XmNleftPosition, 1, XmNrightAttachment,
2545 XmATTACH_POSITION, XmNrightPosition, 2,
2546 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2549 XtAddCallback(button, XmNactivateCallback,
2550 (XtCallbackProc) renameBookmarkCB, This);
2551 XtManageChild(button);
2553 button = XmCreatePushButton(formAction, (
char *)
"Sort", NULL, 0);
2554 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2555 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2556 XmATTACH_POSITION, XmNleftPosition, 2, XmNrightAttachment,
2557 XmATTACH_POSITION, XmNrightPosition, 3,
2558 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2561 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc) sortBookmarksCB, This);
2562 XtManageChild(button);
2564 button = XmCreatePushButton(formAction, (
char *)
"Close", NULL, 0);
2565 XtVaSetValues(button, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget,
2566 separator, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment,
2567 XmATTACH_POSITION, XmNleftPosition, 3, XmNrightAttachment,
2568 XmATTACH_POSITION, XmNrightPosition, 4,
2569 XmNdefaultButtonShadowThickness, 2, XmNwidth, 40, XmNheight, 30,
2572 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc) closeListsDialogCB, This);
2573 XtManageChild(button);
2575 XtManageChild(formAction);
2576 XtVaGetValues(button, XmNheight, &h1, NULL);
2577 XtVaSetValues(formAction, XmNpaneMaximum, h1, XmNpaneMinimum, h1, NULL);
2579 XtManageChild(This->listsDialog);
2587void G4OpenInventorXtExaminerViewer::lookAtSceneElementCB(Widget,
2588 XtPointer client_data,
2589 XtPointer call_data)
2592 std::string elementField;
2594 SoCamera * cam = This->getCamera();
2596 if (This->SoXtExaminerViewer::isAnimating())
2597 This->stopAnimating();
2599 XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
2601 value = (
char *) XmStringUnparse(cbs->item, XmFONTLIST_DEFAULT_TAG,
2602 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
2603 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
2604 || This->currentState == PAUSED_ANIMATION ) {
2605 if (This->animateSensor->isScheduled())
2606 This->animateSensor->unschedule();
2607 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
2608 This->maxSpeed = 0.0f;
2609 This->scheduleRedraw();
2610 This->restoreCamera();
2611 This->currentState = This->prevState;
2612 }
else if (This->currentState == VIEWPOINT)
2613 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
2615 elementField = value;
2617 int idx = elementField.find_last_of(
"[");
2619 idx = elementField.size();
2625 SoSearchAction search;
2626 SoNode *root = This->getSceneManager()->getSceneGraph();
2627 int counter, idxUnderscore = elementField.find_last_of(
"_");
2629 This->
parseString<
int>(counter, elementField.substr(idxUnderscore + 1, idx), error);
2631 SoBaseKit::setSearchingChildren(
TRUE);
2633 search.setSearchingAll(
TRUE);
2636 This->
curEltName = elementField.substr(0, idx);
2640 path = (SoFullPath *)search.getPath();
2643 This->
curEltName = elementField.substr(0, idxUnderscore);
2644 search.setInterest(SoSearchAction::ALL);
2648 SoPathList &pl = search.getPaths();
2649 path = (SoFullPath *)pl[counter - 1];
2654 if ((idx > 0) && (path)) {
2656 if(!This->refParticleTrajectory.empty()){
2658 SoGetBoundingBoxAction bAction(This->getViewportRegion());
2659 bAction.apply(path);
2660 SbBox3f bBox = bAction.getBoundingBox();
2661 SbVec3f elementCoord = bBox.getCenter();
2663 This->refParticleIdx = 0;
2666 float absLengthNow, absLengthMin;
2667 int maxIdx = This->refParticleTrajectory.size() - 2;
2671 p = This->refParticleTrajectory[This->refParticleIdx];
2672 absLengthMin = (p - elementCoord).length();
2673 This->refParticleIdx++;
2676 while (This->refParticleIdx < maxIdx) {
2677 p = This->refParticleTrajectory[This->refParticleIdx];
2678 absLengthNow = (p - elementCoord).length();
2680 if (absLengthNow < absLengthMin) {
2681 absLengthMin = absLengthNow;
2682 targetIdx = This->refParticleIdx;
2684 This->refParticleIdx++;
2687 if (This->currentState != BEAMLINE) {
2689 This->currentState = BEAMLINE;
2690 This->prevParticleDir = SbVec3f(0,0,0);
2692 p1 = This->prevPt = This->refParticleTrajectory[0];
2693 pN = This->refParticleTrajectory[This->refParticleTrajectory.size() - 1];
2694 This->distance = (pN - p1).length() / 10;
2697 if (cam->isOfType(SoOrthographicCamera::getClassTypeId()))
2698 ((SoOrthographicCamera *) cam)->height.setValue(This->defaultHeight);
2700 else if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2701 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2702 This->defaultHeightAngle);
2704 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2705 This->distance = (This->prevPt - cam->position.getValue()).length();
2707 This->refParticleIdx = targetIdx;
2710 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
2711 This->axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2712 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2713 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2714 This->scheduleRedraw();
2722 This->offsetFromCenter.setValue(0, 0, 1);
2723 This->distance = 50;
2724 This->upVector.setValue(0, 1, 0);
2727 cam->viewAll(path, This->getViewportRegion());
2731 XmTextSetString(This->viewPtSelection, NULL);
2737void G4OpenInventorXtExaminerViewer::closeListsDialogCB(Widget,
2738 XtPointer client_data,
2743 This->sceneElements.clear();
2744 This->refParticleTrajectory.clear();
2746 This->currentState = GENERAL;
2747 XtDestroyWidget(This->myShellDialog);
2748 This->listsDialog = NULL;
2752void G4OpenInventorXtExaminerViewer::prevViewPtCB(Widget, XtPointer client_data,
2756 if (This->viewPtIdx == 0)
2757 This->viewPtIdx = This->viewPtList.size() - 1;
2761 This->writeViewPtIdx();
2766void G4OpenInventorXtExaminerViewer::nextViewPtCB(Widget, XtPointer client_data,
2770 if (This->viewPtIdx >= (
int) This->viewPtList.size() - 1)
2771 This->viewPtIdx = 0;
2775 This->writeViewPtIdx();
2782void G4OpenInventorXtExaminerViewer::writeViewPtIdx()
2785 std::stringstream out;
2788 fileOut.seekp(0, std::ios::beg);
2790 while ((
int) idxStr.length() < MAX_VP_IDX) {
2794 fileOut << idxStr <<
"\n";
2796 fileOut.seekp(0, std::ios::end);
2802void G4OpenInventorXtExaminerViewer::setViewPt()
2804 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
2805 || currentState == ROTATING) {
2807 if (animateSensor->isScheduled())
2808 animateSensor->unschedule();
2809 setSuperimpositionEnabled(superimposition,
FALSE);
2814 SoCamera * camera = getCamera();
2815 if (camera == NULL) {
2816 String dialogName = (
char *)
"Missing Camera Node";
2817 std::string msg =
"Camera is null. Unable to set the viewpoint.";
2822 if (!viewPtList.size()) {
2823 String dialogName = (
char *)
"Missing Viewpoints";
2824 std::string msg =
"There are no viewpoints to load.";
2829 if (SoXtExaminerViewer::isAnimating())
2832 if (currentState != VIEWPOINT) {
2833 currentState = VIEWPOINT;
2835 setSuperimpositionEnabled(superimposition,
TRUE);
2836 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2837 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2838 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2844 curViewPtName = viewPtList[viewPtIdx].viewPtName;
2845 camera->viewportMapping = viewPtList[viewPtIdx].viewportMapping;
2846 camera->position = viewPtList[viewPtIdx].position;
2847 camera->orientation = viewPtList[viewPtIdx].orientation;
2848 camera->aspectRatio = viewPtList[viewPtIdx].aspectRatio;
2849 camera->nearDistance = viewPtList[viewPtIdx].nearDistance;
2850 camera->farDistance = viewPtList[viewPtIdx].farDistance;
2851 camera->focalDistance = viewPtList[viewPtIdx].focalDistance;
2854 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2855 if (viewPtList[viewPtIdx].camType == ORTHOGRAPHIC) {
2857 camera = getCamera();
2858 ((SoOrthographicCamera *) camera)->height.setValue(
2859 viewPtList[viewPtIdx].height);
2861 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
2862 viewPtList[viewPtIdx].height);
2863 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
2864 if (viewPtList[viewPtIdx].camType == PERSPECTIVE) {
2866 camera = getCamera();
2867 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
2868 viewPtList[viewPtIdx].height);
2870 ((SoOrthographicCamera *) camera)->height.setValue(
2871 viewPtList[viewPtIdx].height);
2873 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::setViewPt",
2874 "Only Perspective and Orthographic cameras are supported.");
2883void G4OpenInventorXtExaminerViewer::saveViewPtCB(Widget w,
2884 XtPointer client_data,
2889 if (This->fileName.empty()) {
2890 newViewPtFileCB(w, This, NULL);
2891 This->returnToSaveVP =
true;
2897 Widget nameViewPtDialog;
2898 Widget parent = This->getParentWidget();
2899 XmString label = XmStringCreateLocalized((
char *)
"Name the viewpoint:");
2901 XtSetArg(args[n], XmNselectionLabelString, label);
n++;
2902 XtSetArg(args[n], XmNautoUnmanage, False);
n++;
2906 nameViewPtDialog = XmCreatePromptDialog(parent, (
char *)
"Save Viewpoint",
2909 XmStringFree(label);
2910 XtAddCallback(nameViewPtDialog, XmNokCallback, getViewPtNameCB, This);
2911 XtAddCallback(nameViewPtDialog, XmNcancelCallback,
2912 (XtCallbackProc) XtDestroyWidget, NULL);
2914 Widget text = XtNameToWidget(nameViewPtDialog,
"Text");
2915 XtVaSetValues(text, XmNmaxLength, This->MAX_VP_NAME, NULL);
2916 std::string autoName =
"";
2918 autoName = This->viewPtAutoName();
2921 XmTextSetString(text, (
char *) autoName.c_str());
2922 XmTextSetInsertionPosition(text, autoName.length());
2924 XtUnmanageChild(XtNameToWidget(nameViewPtDialog,
"Help"));
2925 XtManageChild(nameViewPtDialog);
2929std::string G4OpenInventorXtExaminerViewer::viewPtAutoName()
2932 std::stringstream sstream;
2933 std::vector<int> existingViewPts;
2937 for (
unsigned int i = 0; i < this->viewPtList.size(); ++i) {
2938 viewPt = this->viewPtList[i].viewPtName;
2939 if (viewPt.find(
"viewpoint_") != std::string::npos) {
2940 tmp = atoi(viewPt.substr(10).c_str());
2943 if (!viewPt.compare(
"viewpoint_0"))
2944 existingViewPts.push_back(0);
2946 existingViewPts.push_back(tmp);
2954 if (existingViewPts.size() > 0) {
2957 if (std::find(existingViewPts.begin(), existingViewPts.end(), vpNum)
2958 == existingViewPts.end()) {
2959 sstream <<
"viewpoint_" << vpNum;
2960 return sstream.str();
2965 return "viewpoint_0";
2971void G4OpenInventorXtExaminerViewer::abbrOutputCB(Widget,
2972 XtPointer client_data,
2981void G4OpenInventorXtExaminerViewer::pickRefPathCB(Widget,
2982 XtPointer client_data,
2989 if(This->isViewing())
2990 This->setViewing(
false);
2991 This->setComponentCursor(SoXtCursor(SoXtCursor::CROSSHAIR));
2998void G4OpenInventorXtExaminerViewer::getViewPtNameCB(Widget w,
2999 XtPointer client_data,
3000 XtPointer call_data)
3003 std::string strName;
3005 XmSelectionBoxCallbackStruct *cbs =
3006 (XmSelectionBoxCallbackStruct *) call_data;
3007 XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &name);
3020 int beg = strName.find_first_not_of(
' ');
3021 int end = strName.find_last_not_of(
' ');
3022 strName = strName.substr(beg, end - beg + 1);
3024 bool nameExists =
false;
3025 int size = This->viewPtList.size();
3026 for (
int i = 0; i < size; i++) {
3027 if (!strcmp(This->viewPtList[i].viewPtName, strName.c_str())) {
3034 name =
new char[This->MAX_VP_NAME + 1];
3035 strcpy(name, strName.c_str());
3036 if (This->viewPtIdx == -1)
3037 This->viewPtIdx = 0;
3038 This->saveViewPt(name);
3039 if (This->listsDialog) {
3040 XmListAddItemUnselected(This->myViewPtList, cbs->value, 0);
3045 String dialogName = (
char *)
"Existing Viewpoint";
3046 std::string msg =
"The viewpoint already exists.";
3055void G4OpenInventorXtExaminerViewer::saveViewPt(
char *name)
3059 float x, y, z, angle;
3060 SoCamera * camera = getCamera();
3062 if (viewPtList.size() == 0) {
3064 XtSetSensitive(nextViewPtButton, True);
3065 XtSetSensitive(prevViewPtButton, True);
3068 tmp.viewPtName = name;
3069 tmp.viewportMapping = camera->viewportMapping.getValue();
3070 tmp.position = camera->position.getValue();
3071 tmp.orientation = camera->orientation.getValue();
3072 tmp.aspectRatio = camera->aspectRatio.getValue();
3073 tmp.nearDistance = camera->nearDistance.getValue();
3074 tmp.farDistance = camera->farDistance.getValue();
3075 tmp.focalDistance = camera->focalDistance.getValue();
3078 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3079 tmp.height = ((SoPerspectiveCamera *) camera)->heightAngle.getValue();
3080 tmp.camType = PERSPECTIVE;
3081 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3082 tmp.height = ((SoOrthographicCamera *) camera)->height.getValue();
3083 tmp.camType = ORTHOGRAPHIC;
3085 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::saveViewPtCB",
3086 "Only Perspective and Orthographic cameras are supported.");
3090 viewPtList.push_back(tmp);
3093 std::string vpName = name;
3095 while ((
int) vpName.size() <= MAX_VP_NAME)
3098 fileOut << vpName << std::endl;
3099 tmp.position.getValue(x, y, z);
3100 fileOut << x <<
" " << y <<
" " << z << std::endl;
3103 tmp.orientation.getValue(axis, angle);
3104 axis.getValue(x, y, z);
3105 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3107 fileOut << tmp.camType <<
" " << tmp.height << std::endl;
3108 fileOut << tmp.focalDistance <<
" ";
3109 fileOut << tmp.nearDistance <<
" ";
3110 fileOut << tmp.farDistance << std::endl;
3111 fileOut << tmp.viewportMapping <<
" ";
3112 fileOut << tmp.aspectRatio <<
"\n" << std::endl;
3118void G4OpenInventorXtExaminerViewer::deleteViewPtCB(Widget,
3119 XtPointer client_data,
3124 This->deleteViewPt();
3131void G4OpenInventorXtExaminerViewer::deleteViewPt(
char *vpName)
3135 fileIn.open(fileName.c_str());
3136 std::ofstream out(
"temporaryFile.txt");
3139 vpName = viewPtList[viewPtIdx].viewPtName;
3142 XmString vpNameStr = XmStringCreateLocalized(vpName);
3144 XmListDeleteItem(myViewPtList, vpNameStr);
3145 XmStringFree(vpNameStr);
3148 getline(fileIn, line);
3149 out << line <<
"\n";
3151 while (getline(fileIn, line)) {
3152 end = line.find_last_not_of(
' ');
3153 line = line.substr(0, end + 1);
3154 if (!strcmp(line.c_str(), vpName)) {
3155 while (line.size()) {
3156 getline(fileIn, line);
3159 while (getline(fileIn, line))
3160 out << line <<
"\n";
3162 while (line.size()) {
3163 out << line <<
"\n";
3164 getline(fileIn, line);
3171 int size = viewPtList.size();
3172 while (idx < size) {
3173 if (!strcmp(viewPtList[idx].viewPtName, vpName)) {
3174 viewPtList.erase(viewPtList.begin() + idx);
3185 remove(fileName.c_str());
3186 rename(
"temporaryFile.txt", fileName.c_str());
3188 fileOut.open(fileName.c_str(), std::ios::in);
3189 fileOut.seekp(0, std::ios::end);
3191 if (!viewPtList.size()) {
3192 curViewPtName = (
char *)
"";
3194 XtSetSensitive(nextViewPtButton, False);
3195 XtSetSensitive(prevViewPtButton, False);
3197 if (viewPtIdx >= (
int) viewPtList.size())
3207void G4OpenInventorXtExaminerViewer::renameViewPt(
char *vpName)
3209 int idx = 0, end, pos;
3210 int size = viewPtList.size();
3211 std::string line, newName;
3212 fileIn.open(fileName.c_str());
3215 while ((
int) newName.size() < MAX_VP_NAME)
3218 getline(fileIn, line);
3219 pos = fileIn.tellg();
3220 while (getline(fileIn, line)) {
3221 end = line.find_last_not_of(
' ');
3222 line = line.substr(0, end + 1);
3223 if (!strcmp(line.c_str(), curViewPtName)) {
3226 fileOut.seekp(0, std::ios::end);
3230 getline(fileIn, line);
3231 pos = fileIn.tellg();
3237 while (idx < size) {
3238 if (!strcmp(viewPtList[idx].viewPtName, curViewPtName)) {
3239 strcpy(viewPtList[idx].viewPtName, vpName);
3249void G4OpenInventorXtExaminerViewer::sortViewPts(std::vector<std::string> sortedViewPts)
3252 float x, y, z, angle;
3253 int sortIdx = 0, unsortIdx = 0;
3255 if (fileOut.is_open())
3258 fileOut.open(fileName.c_str());
3262 int size = sortedViewPts.size();
3263 while (sortIdx < size) {
3264 while (strcmp(sortedViewPts[sortIdx].c_str(),
3265 viewPtList[unsortIdx].viewPtName))
3268 std::string vpName = viewPtList[unsortIdx].viewPtName;
3270 while ((
int) vpName.size() < MAX_VP_NAME)
3272 fileOut << vpName << std::endl;
3273 viewPtList[unsortIdx].position.getValue(x, y, z);
3274 fileOut << x <<
" " << y <<
" " << z << std::endl;
3277 viewPtList[unsortIdx].orientation.getValue(axis, angle);
3278 axis.getValue(x, y, z);
3279 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3281 fileOut << viewPtList[unsortIdx].camType <<
" "
3282 << viewPtList[unsortIdx].height << std::endl;
3283 fileOut << viewPtList[unsortIdx].focalDistance <<
" ";
3285 fileOut << viewPtList[unsortIdx].nearDistance <<
" ";
3287 fileOut << viewPtList[unsortIdx].farDistance << std::endl;
3289 fileOut << viewPtList[unsortIdx].viewportMapping <<
" ";
3290 fileOut << viewPtList[unsortIdx].aspectRatio <<
"\n" << std::endl;
3308 float x, y, z, angle;
3312 parseString<int>(viewPtIdx, token, error);
3313 getline(fileIn, token);
3315 while (getline(fileIn, token)) {
3317 int end = token.find_last_not_of(
' ');
3318 token = token.substr(0, end + 1);
3320 char *vpName =
new char[token.size() + 1];
3321 strcpy(vpName, token.c_str());
3322 tmp.viewPtName = vpName;
3325 parseString<float>(x, token, error);
3327 parseString<float>(y, token, error);
3329 parseString<float>(z, token, error);
3331 tmp.position = axis.setValue(x, y, z);
3333 parseString<float>(x, token, error);
3335 parseString<float>(y, token, error);
3337 parseString<float>(z, token, error);
3339 parseString<float>(angle, token, error);
3341 orient.setValue(axis.setValue(x, y, z), angle);
3342 tmp.orientation = orient.getValue();
3345 parseString<int>(camType, token, error);
3347 tmp.camType = (CameraType) camType;
3349 parseString<float>(tmp.height, token, error);
3351 parseString<float>(tmp.focalDistance, token, error);
3353 parseString<float>(tmp.nearDistance, token, error);
3355 parseString<float>(tmp.farDistance, token, error);
3357 parseString<int>(tmp.viewportMapping, token, error);
3359 parseString<float>(tmp.aspectRatio, token, error);
3361 getline(fileIn, token);
3362 getline(fileIn, token);
3369 viewPtList.push_back(tmp);
3382 std::istringstream str(s);
3383 if ((str >> t).fail())
3390void G4OpenInventorXtExaminerViewer::popUpFileSelDialog(Widget &dialog,
3391 std::string dialogName,
3392 std::string buttonLabel,
3393 XtCallbackProc cbOK)
3397 Widget parent, scrollWidget;
3398 parent = SoXt::getShellWidget(getParentWidget());
3400 if (dialog == NULL) {
3403 XmString str = XmStringCreateLocalized((
char *) buttonLabel.c_str());
3406 XtSetArg(args[n], XmNokLabelString, str); n++;
3407 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
3409 dialog = XmCreateFileSelectionDialog(parent,
3410 (
char *) dialogName.c_str(), args, n);
3412 XtAddCallback(dialog, XmNokCallback, cbOK,
this);
3413 XtAddCallback(dialog, XmNcancelCallback, cancelFileSelDialogCB,
this);
3416 scrollWidget = XmFileSelectionBoxGetChild(dialog, XmDIALOG_DIR_LIST);
3419 scrollWidget = XmFileSelectionBoxGetChild(dialog, XmDIALOG_LIST);
3423 XtUnmanageChild(XmSelectionBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
3426 XtManageChild(dialog);
3432void G4OpenInventorXtExaminerViewer::cancelFileSelDialogCB(Widget w,
3442void G4OpenInventorXtExaminerViewer::openViewPtFileCB(Widget,
3443 XtPointer client_data,
3448 This->popUpFileSelDialog(This->openFileDialog,
"Open File",
"Load",
3449 viewPtFileSelectedCB);
3453void G4OpenInventorXtExaminerViewer::viewPtFileSelectedCB(Widget w,
3454 XtPointer client_data,
3455 XtPointer call_data)
3459 XmFileSelectionBoxCallbackStruct *cbs =
3460 (XmFileSelectionBoxCallbackStruct *) call_data;
3464 if (!(file = (
char *) XmStringUnparse(cbs->value,
3465 XmFONTLIST_DEFAULT_TAG, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0,
3467 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::fileSelectedCB",
3468 "Internal error during file opening");
3472 This->fileIn.open(file);
3473 if (!This->fileIn.fail()) {
3475 This->cleanUpAfterPrevFile();
3477 String dialogName = (
char *)
"Error Loading File";
3478 std::string msg =
"Wrong or corrupted input file.";
3481 This->fileName = file;
3482 This->fileOut.open(This->fileName.c_str(), std::ios::in);
3483 This->fileOut.seekp(0, std::ios::end);
3485 if (!This->listsDialog)
3486 constructListsDialog(w, This, NULL);
3488 This->addViewPoints();
3490 std::string newDialogName = This->fileName.substr(
3491 This->fileName.rfind(
'/') + 1);
3492 XtVaSetValues(This->myShellDialog, XmNtitle,
3493 (
char *) newDialogName.c_str(), NULL);
3495 if (This->viewPtList.size()) {
3497 XmTextSetString(This->viewPtSelection, NULL);
3498 XtSetSensitive(This->nextViewPtButton, True);
3499 XtSetSensitive(This->prevViewPtButton, True);
3501 XtSetSensitive(This->nextViewPtButton, False);
3502 XtSetSensitive(This->prevViewPtButton, False);
3508 This->fileIn.close();
3510 String dialogName = (
char *)
"Nonexistent File";
3511 std::string msg =
"Unable to open file.";
3516 This->fileIn.clear();
3523void G4OpenInventorXtExaminerViewer::addViewPoints()
3525 int size = viewPtList.size();
3531 viewPts = (XmString *) XtMalloc(size *
sizeof(XmString));
3532 for (
int i = 0; i < size; i++)
3533 viewPts[i] = XmStringCreateLocalized(viewPtList[i].viewPtName);
3535 XmListAddItemsUnselected(myViewPtList, viewPts, size, 1);
3537 if (viewPts != NULL) {
3538 for (
int i = 0; i < size; i++)
3539 XmStringFree(viewPts[i]);
3540 XtFree((
char *) viewPts);
3548void G4OpenInventorXtExaminerViewer::cleanUpAfterPrevFile()
3552 setSuperimpositionEnabled(superimposition,
FALSE);
3554 currentState = GENERAL;
3555 if (fileOut.is_open())
3558 XmListDeleteAllItems(myViewPtList);
3570 XmString warningMsg;
3572 warningMsg = XmStringCreateLocalized((
char *)msg.c_str());
3575 XtSetArg(args[n], XmNmessageString, warningMsg); n++;
3576 Widget warningDialog = XmCreateWarningDialog(getParentWidget(), dialogName, args, n);
3578 XtAddCallback(warningDialog, XmNokCallback, cb,
this);
3580 XmStringFree(warningMsg);
3582 XtVaSetValues (warningDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
3583 XtUnmanageChild(XtNameToWidget(warningDialog,
"Help"));
3584 XtUnmanageChild(XtNameToWidget(warningDialog,
"Cancel"));
3586 XtManageChild(warningDialog);
3590void G4OpenInventorXtExaminerViewer::newViewPtFileCB(Widget,
3591 XtPointer client_data,
3596 This->popUpFileSelDialog(This->newFileDialog,
"New File",
"Save",
3601void G4OpenInventorXtExaminerViewer::createNewVPFileCB(Widget w,
3602 XtPointer client_data,
3603 XtPointer call_data)
3608 XmFileSelectionBoxCallbackStruct *cbs =
3609 (XmFileSelectionBoxCallbackStruct *) call_data;
3613 if (!(file = (
char *) XmStringUnparse(cbs->value,
3614 XmFONTLIST_DEFAULT_TAG, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0,
3616 SoDebugError::post(
"G4OpenInventorXtExaminerViewer::createNewVPFileCB",
3617 "Internal error during file opening");
3621 This->fileName = file;
3622 fName = This->fileName.substr(This->fileName.rfind(
'/') + 1);
3623 This->fileIn.open(file);
3624 if (This->fileIn.fail()) {
3625 This->cleanUpAfterPrevFile();
3626 This->fileOut.open(file);
3627 XtSetSensitive(This->nextViewPtButton, False);
3628 XtSetSensitive(This->prevViewPtButton, False);
3629 if (This->listsDialog)
3630 closeListsDialogCB(w, This, NULL);
3631 constructListsDialog(w, This, NULL);
3633 if (This->returnToSaveVP) {
3634 This->returnToSaveVP =
false;
3635 saveViewPtCB(NULL, This, NULL);
3638 String dialogName = (
char *)
"Existing File";
3639 std::string msg =
"'" + fName +
"' already exists. Do you want to overwrite it?";
3641 This->fileIn.close();
3643 This->fileIn.clear();
3649void G4OpenInventorXtExaminerViewer::overwriteFileCB(Widget,
3650 XtPointer client_data,
3654 This->cleanUpAfterPrevFile();
3655 XtSetSensitive(This->nextViewPtButton, False);
3656 XtSetSensitive(This->prevViewPtButton, False);
3658 XtUnmanageChild(This->newFileDialog);
3660 This->fileOut.open(This->fileName.c_str());
3662 if (This->returnToSaveVP) {
3663 This->returnToSaveVP =
false;
3664 saveViewPtCB(NULL, This, NULL);
3669void G4OpenInventorXtExaminerViewer::loadRefCoordsDialogCB(Widget,
3670 XtPointer client_data,
3675 This->popUpFileSelDialog(This->loadRefCoordsDialog,
"Load Ref Coords",
3676 "Load", loadRefCoordsCB);
3680void G4OpenInventorXtExaminerViewer::loadRefCoordsCB(Widget w,
3681 XtPointer client_data,
3682 XtPointer call_data)
3686 XmFileSelectionBoxCallbackStruct *cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
3691 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3692 XmCHARSET_TEXT, XmCHARSET_TEXT,
3693 NULL, 0, XmOUTPUT_ALL);
3695 std::ifstream ifs(file);
3697 This->refParticleTrajectory.clear();
3699 while(ifs >> x >> y >> z){
3700 This->refParticleTrajectory.push_back(SbVec3f(x,y,z));
3706 String dialogName = (
char *)
"Problem reading file";
3707 std::string msg =
"Problem reading file";
3718void G4OpenInventorXtExaminerViewer::saveRefCoordsDialogCB(Widget,
3719 XtPointer client_data,
3724 if (!This->refParticleTrajectory.size()) {
3725 String dialogName = (
char *)
"No Reference Trajectory";
3726 std::string msg =
"You need to start a run or load a reference trajectory from a file";
3733 Widget parent, scrollWidget;
3734 parent = SoXt::getShellWidget(This->getParentWidget());
3736 if (This->saveRefCoordsDialog == NULL) {
3739 XmString str = XmStringCreateLocalized((
char *)
"Save");
3742 XtSetArg(args[n], XmNokLabelString, str);
n++;
3743 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE);
n++;
3745 This->saveRefCoordsDialog = XmCreateFileSelectionDialog(parent,(
char *)
"Save Ref Coords", args, n);
3747 XtAddCallback(This->saveRefCoordsDialog, XmNokCallback, saveRefCoordsCB, This);
3748 XtAddCallback(This->saveRefCoordsDialog, XmNcancelCallback, cancelFileSelDialogCB, This);
3751 scrollWidget = XmFileSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_DIR_LIST);
3754 scrollWidget = XmFileSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_LIST);
3758 XtUnmanageChild(XmSelectionBoxGetChild(This->saveRefCoordsDialog, XmDIALOG_HELP_BUTTON));
3764 XtManageChild(This->saveRefCoordsDialog);
3769void G4OpenInventorXtExaminerViewer::saveRefCoordsCB(Widget w,
3770 XtPointer client_data,
3771 XtPointer call_data)
3775 XmFileSelectionBoxCallbackStruct *cbs =
3776 (XmFileSelectionBoxCallbackStruct *) call_data;
3781 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3782 XmCHARSET_TEXT, XmCHARSET_TEXT,
3783 NULL, 0, XmOUTPUT_ALL);
3785 std::ifstream ifile(file);
3790 Widget parent = This->getParentWidget();
3791 Widget confirmOverwriteDialog;
3794 confirmOverwriteDialog = XmCreateQuestionDialog (parent, (
char *)
"Confirm overwrite", args, 0);
3795 msg = XmStringCreateLocalized ((
char *)
"File exists. Overwrite?");
3796 XtVaSetValues (confirmOverwriteDialog, XmNmessageString, msg, NULL);
3801 XtVaSetValues (confirmOverwriteDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
3802 XtAddCallback (confirmOverwriteDialog, XmNokCallback, saveRefCoordsOverWriteCB, client_data);
3803 XtAddCallback (confirmOverwriteDialog, XmNcancelCallback, saveRefCoordsOverWriteCB, client_data);
3811 XtUnmanageChild(XtNameToWidget(confirmOverwriteDialog,
"Help"));
3812 XtManageChild(confirmOverwriteDialog);
3818 std::ofstream ofs(file);
3821 for(
unsigned int i=0; i < This->refParticleTrajectory.size(); ++i){
3822 This->refParticleTrajectory[i].getValue(x,y,z);
3823 ofs << x <<
" " << y <<
" " << z <<
"\n";
3829 String dialogName = (
char *)
"Error opening file";
3830 std::string msg =
"There was a problem trying to open the file '";
3843void G4OpenInventorXtExaminerViewer::saveRefCoordsOverWriteCB(Widget w,
3844 XtPointer client_data,
3845 XtPointer call_data)
3847 XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
3850 switch (cbs->reason) {
3858 for(
unsigned int i=0; i < This->refParticleTrajectory.size(); ++i){
3859 This->refParticleTrajectory[i].getValue(x,y,z);
3860 ofs << x <<
" " << y <<
" " << z <<
"\n";
3867 String dialogName = (
char *)
"Error opening file";
3868 std::string msg =
"There was a problem trying to open the file '";
3882 XmProcessTraversal(XtNameToWidget(This->
saveRefCoordsWidget,
"Text"), XmTRAVERSE_CURRENT);
3895void G4OpenInventorXtExaminerViewer::loadSceneGraphDialogCB(Widget,
3896 XtPointer client_data,
3901 This->popUpFileSelDialog(This->loadSceneGraphDialog,
"Load Scene Graph",
3902 "Load", loadSceneGraphCB);
3907void G4OpenInventorXtExaminerViewer::loadSceneGraphCB(Widget w,
3908 XtPointer client_data,
3909 XtPointer call_data)
3913 XmFileSelectionBoxCallbackStruct *cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
3917 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
3918 XmCHARSET_TEXT, XmCHARSET_TEXT,
3919 NULL, 0, XmOUTPUT_ALL);
3922 if (!sceneInput.openFile(file)) {
3923 String dialogName = (
char *)
"Problem opening file";
3924 std::string msg =
"Cannot open file ";
3928 sceneInput.closeFile();
3932 This->newSceneGraph = SoDB::readAll(&sceneInput);
3933 if (This->newSceneGraph == NULL) {
3934 String dialogName = (
char *)
"Problem reading file";
3935 std::string msg =
"Problem reading file";
3941 This->setSceneGraph(This->newSceneGraph);
3948void G4OpenInventorXtExaminerViewer::saveSceneGraphDialogCB(Widget,
3949 XtPointer client_data,
3956 Widget parent, scrollWidget;
3957 parent = SoXt::getShellWidget(This->getParentWidget());
3959 if (This->saveSceneGraphDialog == NULL) {
3962 XmString str = XmStringCreateLocalized((
char *)
"Save");
3965 XtSetArg(args[n], XmNokLabelString, str);
n++;
3966 XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE);
n++;
3968 This->saveSceneGraphDialog = XmCreateFileSelectionDialog(parent,(
char *)
"Save Scene Graph", args, n);
3970 XtAddCallback(This->saveSceneGraphDialog, XmNokCallback, saveSceneGraphCB, This);
3971 XtAddCallback(This->saveSceneGraphDialog, XmNcancelCallback, cancelFileSelDialogCB, This);
3974 scrollWidget = XmFileSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_DIR_LIST);
3977 scrollWidget = XmFileSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_LIST);
3981 XtUnmanageChild(XmSelectionBoxGetChild(This->saveSceneGraphDialog, XmDIALOG_HELP_BUTTON));
3987 XtManageChild(This->saveSceneGraphDialog);
3993void G4OpenInventorXtExaminerViewer::saveSceneGraphCB(Widget w,
3994 XtPointer client_data,
3995 XtPointer call_data)
3999 XmFileSelectionBoxCallbackStruct *cbs =
4000 (XmFileSelectionBoxCallbackStruct *) call_data;
4004 file = (
char *)XmStringUnparse(cbs->value, XmFONTLIST_DEFAULT_TAG,
4005 XmCHARSET_TEXT, XmCHARSET_TEXT,
4006 NULL, 0, XmOUTPUT_ALL);
4008 std::ifstream ifile(file);
4013 Widget parent = This->getParentWidget();
4014 Widget confirmOverwriteDialog;
4017 confirmOverwriteDialog = XmCreateQuestionDialog (parent, (
char *)
"Confirm overwrite", args, 0);
4018 msg = XmStringCreateLocalized ((
char *)
"File exists. Overwrite?");
4019 XtVaSetValues (confirmOverwriteDialog, XmNmessageString, msg, NULL);
4024 XtVaSetValues (confirmOverwriteDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
4025 XtAddCallback (confirmOverwriteDialog, XmNokCallback, saveSceneGraphOverWriteCB, client_data);
4026 XtAddCallback (confirmOverwriteDialog, XmNcancelCallback, saveSceneGraphOverWriteCB, client_data);
4034 XtUnmanageChild(XtNameToWidget(confirmOverwriteDialog,
"Help"));
4035 XtManageChild(confirmOverwriteDialog);
4041 SoWriteAction writeAction;
4042 SoSeparator *root = (SoSeparator *) (This->getSceneGraph());
4044 SoOutput * out = writeAction.getOutput();
4046 if(out->openFile(file)){
4047 out->setBinary(
FALSE);
4048 writeAction.apply(root);
4054 String dialogName = (
char *)
"Error opening file";
4055 std::string msg =
"There was a problem trying to open the file '";
4070void G4OpenInventorXtExaminerViewer::saveSceneGraphOverWriteCB(Widget w,
4071 XtPointer client_data,
4072 XtPointer call_data)
4074 XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
4077 switch (cbs->reason) {
4082 SoWriteAction writeAction;
4083 SoSeparator *root = (SoSeparator *) (This->getSceneGraph());
4085 SoOutput * out = writeAction.getOutput();
4087 out->setBinary(
FALSE);
4088 writeAction.apply(root);
4097 String dialogName = (
char *)
"Error opening file";
4098 std::string msg =
"There was a problem trying to open the file '";
4129void G4OpenInventorXtExaminerViewer::loadBookmarkCB(Widget,
4130 XtPointer client_data,
4131 XtPointer call_data)
4135 XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
4137 vpName = (
char *) XmStringUnparse(cbs->item, XmFONTLIST_DEFAULT_TAG,
4138 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
4140 for (
int i = 0; i < (int) This->viewPtList.size(); i++) {
4141 if (!strcmp(This->viewPtList[i].viewPtName, vpName)) {
4142 This->viewPtIdx = i;
4146 XmTextSetString(This->viewPtSelection, vpName);
4148 This->writeViewPtIdx();
4155void G4OpenInventorXtExaminerViewer::deleteBookmarkCB(Widget,
4156 XtPointer client_data,
4162 vpName = XmTextGetString(This->viewPtSelection);
4164 XmString vpNameStr = XmStringCreateLocalized(vpName);
4166 if (XmListItemExists(This->myViewPtList, vpNameStr)) {
4167 XmListDeleteItem(This->myViewPtList, vpNameStr);
4168 This->deleteViewPt(vpName);
4171 XmStringFree(vpNameStr);
4172 XmTextSetString(This->viewPtSelection, NULL);
4177void G4OpenInventorXtExaminerViewer::renameBookmarkCB(Widget,
4178 XtPointer client_data,
4181 std::string vpNameStr;
4183 int *pos_list, pos_cnt;
4186 vpName = XmTextGetString(This->viewPtSelection);
4188 if (!strlen(vpName) || !strcmp(This->curViewPtName, vpName)) {
4195 int beg = vpNameStr.find_first_not_of(
' ');
4196 int end = vpNameStr.find_last_not_of(
' ');
4197 vpNameStr = vpNameStr.substr(beg, end - beg + 1);
4198 vpName =
new char[vpNameStr.size() + 1];
4199 strcpy(vpName, vpNameStr.c_str());
4201 int size = This->viewPtList.size();
4202 for (
int i = 0; i < size; i++) {
4203 if (!strcmp(vpName, This->viewPtList[i].viewPtName)) {
4205 String dialogName = (
char *)
"Existing Viewpoint";
4206 std::string msg =
"'";
4208 msg +=
"' already exists. Choose a different name";
4215 XmString vpNameXmStr = XmStringCreateLocalized(vpName);
4217 if (XmListGetSelectedPos(This->myViewPtList, &pos_list, &pos_cnt)) {
4218 XmListReplaceItemsPos(This->myViewPtList, &vpNameXmStr, 1, pos_list[0]);
4219 This->renameViewPt(vpName);
4220 XtFree((
char *) pos_list);
4223 if (This->currentState == VIEWPOINT)
4224 This->scheduleRedraw();
4226 XmStringFree(vpNameXmStr);
4230void G4OpenInventorXtExaminerViewer::sortBookmarksCB(Widget,
4231 XtPointer client_data,
4236 XmString *strList, *newStrList;
4237 std::vector<std::string> charList;
4240 if (This->viewPtList.size() < 2)
4244 XtVaGetValues(This->myViewPtList, XmNitemCount, &size, XmNitems, &strList,
4247 for (
int i = 0; i < size; i++) {
4248 vpName = (
char *) XmStringUnparse(strList[i], XmFONTLIST_DEFAULT_TAG,
4249 XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
4250 charList.push_back(vpName);
4254 std::sort(charList.begin(), charList.end());
4256 newStrList = (XmString *) XtMalloc(size *
sizeof(XmString));
4257 for (
int i = 0; i < size; i++) {
4259 if (!strcmp(charList[i].c_str(), This->curViewPtName))
4260 This->viewPtIdx = i;
4261 char *vpName2 =
new char[charList[i].size() + 1];
4262 strcpy(vpName2, charList[i].c_str());
4263 newStrList[i] = XmStringCreateLocalized(vpName2);
4267 XmListDeleteAllItems(This->myViewPtList);
4268 XmListAddItemsUnselected(This->myViewPtList, newStrList, size, 1);
4270 This->sortViewPts(charList);
4272 if (newStrList != NULL) {
4273 for (
int i = 0; i < size; i++)
4274 XmStringFree(newStrList[i]);
4275 XtFree((
char *) newStrList);
4280void G4OpenInventorXtExaminerViewer::evenOutRefParticlePts()
4282 if(this->refParticleTrajectory.empty())
4285 SbVec3f p1, p2, p3, dirNow, dirNxt, dir, p2_tmp, p_start, p_corner, p_nxt;
4286 float avgDistBtwPts = 0;
4287 float totalDistBtwPts = 0;
4288 std::vector<SbVec3f> newRefParticleTrajectory;
4290 int size = refParticleTrajectory.size() - 1;
4292 for (
int i = 0; i < size; i++) {
4293 p1 = refParticleTrajectory[i];
4294 p2 = refParticleTrajectory[i + 1];
4298 totalDistBtwPts += (p2 - p1).length();
4301 avgDistBtwPts = totalDistBtwPts / numOfPts;
4302 float minDistAllowed = 0.75 * avgDistBtwPts;
4308 p1 = refParticleTrajectory[i];
4309 p2 = refParticleTrajectory[i + 1];
4312 p1.getValue(x, y, z);
4314 newRefParticleTrajectory.push_back(refPoint);
4317 while ((p2 - p1).length() < minDistAllowed && j < (size - 1)) {
4320 p1 = refParticleTrajectory[j];
4321 p2 = refParticleTrajectory[j + 1];
4329 refParticleTrajectory.clear();
4330 refParticleTrajectory = newRefParticleTrajectory;
4336void G4OpenInventorXtExaminerViewer::closeMainWindowCB(Widget,
4337 XtPointer client_data,
4343 if (This->openFileDialog)
4344 XtUnmanageChild(This->openFileDialog);
4346 if (This->newFileDialog)
4347 XtUnmanageChild(This->newFileDialog);
4349 if (This->listsDialog)
4350 closeListsDialogCB(NULL, This, NULL);
4354void G4OpenInventorXtExaminerViewer::saveCurCamera()
4356 SoCamera *cam = getCamera();
4357 camB4Animation.viewportMapping = cam->viewportMapping.getValue();
4358 camB4Animation.position = cam->position.getValue();
4359 camB4Animation.orientation = cam->orientation.getValue();
4360 camB4Animation.aspectRatio = cam->aspectRatio.getValue();
4361 camB4Animation.nearDistance = cam->nearDistance.getValue();
4362 camB4Animation.farDistance = cam->farDistance.getValue();
4363 camB4Animation.focalDistance = cam->focalDistance.getValue();
4365 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
4366 camB4Animation.height =
4367 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
4368 camB4Animation.camType = PERSPECTIVE;
4369 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4370 camB4Animation.height =
4371 ((SoOrthographicCamera *) cam)->height.getValue();
4372 camB4Animation.camType = ORTHOGRAPHIC;
4377void G4OpenInventorXtExaminerViewer::restoreCamera()
4379 SoCamera *cam = getCamera();
4381 cam->viewportMapping = camB4Animation.viewportMapping;
4382 cam->position = camB4Animation.position;
4383 cam->orientation = camB4Animation.orientation;
4384 cam->aspectRatio = camB4Animation.aspectRatio;
4385 cam->nearDistance = camB4Animation.nearDistance;
4386 cam->farDistance = camB4Animation.farDistance;
4387 cam->focalDistance = camB4Animation.focalDistance;
4389 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
4390 if (camB4Animation.camType == ORTHOGRAPHIC) {
4393 ((SoOrthographicCamera *) cam)->height.setValue(
4394 camB4Animation.height);
4396 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
4397 camB4Animation.height);
4398 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4399 if (camB4Animation.camType == PERSPECTIVE) {
4402 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
4403 camB4Animation.height);
4405 ((SoOrthographicCamera *) cam)->height.setValue(
4406 camB4Animation.height);
4411void G4OpenInventorXtExaminerViewer::animateSensorRotationCB(
void *data,
4414 SbTime curTime = SbTime::getTimeOfDay();
4416 SoTimerSensor *s = (SoTimerSensor *) sensor;
4418 float t = float((curTime - s->getBaseTime()).getValue())
4419 / This->animateBtwPtsPeriod;
4421 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
4423 SbBool end = (t == 1.0f);
4426 This->animateSensorRotation->unschedule();
4433 This->currentState = This->prevState;
4443void G4OpenInventorXtExaminerViewer::animateSensorCB(
void *data,
4446 SbTime curTime = SbTime::getTimeOfDay();
4448 SoCamera *cam = This->getCamera();
4449 SoTimerSensor *s = (SoTimerSensor *) sensor;
4451 float t = float((curTime - s->getBaseTime()).getValue())
4452 / This->animateBtwPtsPeriod;
4454 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
4456 SbBool end = (t == 1.0f);
4458 cam->orientation = SbRotation::slerp(This->camStartOrient, This->camEndOrient, t);
4459 cam->position = This->camStartPos + (This->camEndPos - This->camStartPos) * t;
4462 This->animateSensor->unschedule();
4464 if (This->currentState == ANIMATION) {
4465 if (This->refParticleIdx < (
int) (This->refParticleTrajectory.size() - 1))
4466 This->animateRefParticle();
4472 if (This->currentState == REVERSED_ANIMATION) {
4473 if (This->refParticleIdx >= 1)
4474 This->animateRefParticle();
4484void G4OpenInventorXtExaminerViewer::setStartingPtForAnimation()
4486 if (SoXtExaminerViewer::isAnimating())
4490 SbVec3f p1, p2, p2_tmp, camUpV, camD, camD_tmp, leftRightAxis;
4491 float x1, y1, z1, x2, y2, z2;
4493 if (currentState == ANIMATION) {
4494 p1 = refParticleTrajectory[refParticleIdx];
4495 p2 = refParticleTrajectory[++(refParticleIdx)];
4496 }
else if (currentState == REVERSED_ANIMATION) {
4497 p2 = refParticleTrajectory[refParticleIdx];
4498 p1 = refParticleTrajectory[--(refParticleIdx)];
4499 }
else if (currentState == PAUSED_ANIMATION) {
4500 if (refParticleIdx < (
int) refParticleTrajectory.size()) {
4501 p1 = refParticleTrajectory[refParticleIdx];
4502 p2 = refParticleTrajectory[refParticleIdx + 1];
4504 p1 = refParticleTrajectory[refParticleIdx - 1];
4505 p2 = refParticleTrajectory[refParticleIdx];
4508 p1.getValue(x1, y1, z1);
4509 p2.getValue(x2, y2, z2);
4514 p2_tmp.setValue(x2, y1, z2);
4515 camD_tmp = p2_tmp - p1;
4516 camD_tmp.normalize();
4518 camUpV.setValue(0, 1, 0);
4519 rot.setValue(camD_tmp, camD);
4520 rot.multVec(camUpV, camUpV);
4522 leftRightAxis = camD.cross(camUpV);
4524 myCam->position = p1;
4525 myCam->pointAt(p2, camUpV);
4528 p1 = p1 + (up_down * camUpV) + (left_right * leftRightAxis);
4529 myCam->position = p1;
4533void G4OpenInventorXtExaminerViewer::gotoRefPathStart()
4535 G4OpenInventorXtExaminerViewer::gotoRefPathStartCB(NULL, (
void *)
this,
4540void G4OpenInventorXtExaminerViewer::gotoRefPathStartCB(Widget,
4541 XtPointer client_data,
4546 if (!This->refParticleTrajectory.size()) {
4547 String dialogName = (
char *)
"No Reference Trajectory";
4548 std::string msg =
"You need to start a run or load a reference trajectory from a file";
4553 if (This->currentState == ROTATING)
4555 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
4556 || This->currentState == PAUSED_ANIMATION) {
4557 if (This->animateSensor->isScheduled())
4558 This->animateSensor->unschedule();
4559 This->setSuperimpositionEnabled(This->superimposition,
FALSE);
4560 This->maxSpeed = 0.0f;
4561 This->scheduleRedraw();
4563 This->saveCurCamera();
4564 This->prevState = This->currentState;
4565 This->prevRefIdx = This->refParticleIdx;
4568 if (This->SoXtExaminerViewer::isAnimating())
4569 This->stopAnimating();
4572 This->left_right = 0;
4575 This->refParticleIdx = 0;
4576 This->currentState = BEAMLINE;
4577 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
4578 This->axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
4579 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
4580 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
4581 This->scheduleRedraw();
4588 This->prevParticleDir = SbVec3f(0,0,0);
4591 SbVec3f p1 = This->refParticleTrajectory[0];
4592 SbVec3f pN = This->refParticleTrajectory[This->refParticleTrajectory.size() - 1];
4593 This->distance = (pN - p1).length() / 10;
4599void G4OpenInventorXtExaminerViewer::invertRefPathCB(Widget,
4600 XtPointer client_data,
4605 This->invertRefPath();
4609void G4OpenInventorXtExaminerViewer::invertRefPath()
4611 std::reverse(this->refParticleTrajectory.begin(),
4612 this->refParticleTrajectory.end());
4613 this->setReferencePathZPos();
4614 this->sortElements();
4618void G4OpenInventorXtExaminerViewer::animateRefParticleCB(Widget,
4619 XtPointer client_data,
4624 if (!This->refParticleTrajectory.size()) {
4625 This->returnToAnim =
true;
4626 String dialogName = (
char *)
"No Reference Trajectory";
4627 std::string msg =
"You need to start a run or load a reference trajectory from a file";
4632 if (!This->refParticleTrajectory.size())
4636 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
4638 This->axisSwitch->whichChild.setValue(SO_SWITCH_ALL);
4639 This->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
4640 This->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
4641 This->scheduleRedraw();
4644 SoCamera *cam = This->getCamera();
4647 if (This->currentState == ANIMATION || This->currentState == REVERSED_ANIMATION
4648 || This->currentState == ROTATING)
4651 if (This->currentState != PAUSED_ANIMATION) {
4653 This->saveCurCamera();
4654 This->prevState = This->currentState;
4655 This->prevRefIdx = This->refParticleIdx;
4657 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
4658 This->toggleCameraType();
4659 cam = This->getCamera();
4662 This->refParticleIdx = 0;
4665 This->left_right = This->up_down = 0;
4667 cam->focalDistance = 0.1f;
4668 ((SoPerspectiveCamera *) cam)->heightAngle = 0.50f;
4671 This->currentState = ANIMATION;
4672 This->setStartingPtForAnimation();
4674 cam->position = (This->myCam)->
position.getValue();
4675 cam->orientation = (This->myCam)->orientation.getValue();
4676 This->animateRefParticle();
4680void G4OpenInventorXtExaminerViewer::animateRefParticle()
4682 SoCamera *cam = getCamera();
4684 camStartPos = cam->position.getValue();
4685 camStartOrient = cam->orientation.getValue();
4687 if (currentState != BEAMLINE)
4688 setStartingPtForAnimation();
4690 camEndPos = myCam->position.getValue();
4691 camEndOrient = myCam->orientation.getValue();
4693 if (animateSensor->isScheduled())
4694 animateSensor->unschedule();
4696 animateSensor->setBaseTime(SbTime::getTimeOfDay());
4697 animateSensor->setInterval(SbTime(0.02));
4699 animateSensor->schedule();
4704 void (*callback)(
void *),
void *
object)
4706 this->escapeCallback = callback;
4707 this->examinerObject = object;
4711void G4OpenInventorXtExaminerViewer::sceneChangeCB(
void *
userData, SoSensor *)
4715 if(This->newEvents){
4716 This->findAndSetRefPath();
4717 This->newEvents =
false;
4735 this->viewer->newEvents =
true;
#define MAX_SPEED_INDICATOR
#define SPEED_INDICATOR_STEP
G4DLLIMPORT 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)
HookEventProcState(G4OpenInventorXtExaminerViewer *)
virtual G4bool Notify(G4ApplicationState requiredState)
static Pixmap createPixmapFromXpm(Widget button, const char **xpm, SbBool ghost=FALSE)
void xmAddMouseEventHandler(Widget w)