29#ifdef G4VIS_BUILD_OIQT_DRIVER
46#include <Inventor/Qt/SoQt.h>
47#include <Inventor/Qt/SoQtCursor.h>
48#include <Inventor/events/SoKeyboardEvent.h>
49#include <Inventor/events/SoMouseButtonEvent.h>
50#include <Inventor/events/SoLocation2Event.h>
51#include <Inventor/nodes/SoSeparator.h>
52#include <Inventor/nodes/SoOrthographicCamera.h>
53#include <Inventor/nodes/SoPerspectiveCamera.h>
57#include <Inventor/nodes/SoLineSet.h>
58#include <Inventor/nodes/SoMaterial.h>
59#include <Inventor/errors/SoDebugError.h>
60#include <Inventor/SoPickedPoint.h>
61#include <Inventor/actions/SoWriteAction.h>
62#include <Inventor/projectors/SbPlaneProjector.h>
64#include <Inventor/sensors/SoTimerSensor.h>
65#include <Inventor/sensors/SoNodeSensor.h>
72#include <Inventor/nodes/SoCallback.h>
73#include <Inventor/nodes/SoSwitch.h>
74#include <Inventor/nodes/SoScale.h>
75#include <Inventor/nodes/SoTranslation.h>
76#include <Inventor/actions/SoSearchAction.h>
77#include <Inventor/actions/SoGetBoundingBoxAction.h>
79#include <Inventor/nodes/SoCoordinate3.h>
81#include <Inventor/nodes/SoText2.h>
82#include <Inventor/nodes/SoFont.h>
83#include <Inventor/nodes/SoPointSet.h>
84#include <Inventor/nodes/SoDrawStyle.h>
85#include <Inventor/nodes/SoBaseColor.h>
88#include <Inventor/nodekits/SoBaseKit.h>
93#include <QRadioButton>
96#include <QListWidgetItem>
97#include <QInputDialog>
101#include <QCommonStyle>
105#include "moc_G4OpenInventorQtExaminerViewer.cpp"
108G4OpenInventorQtExaminerViewer* G4OpenInventorQtExaminerViewer::viewer = 0;
111#define START_STEP 0.3
112#define SPEED_INDICATOR_STEP 0.045
113#define MAX_SPEED_INDICATOR 0.81
119G4OpenInventorQtExaminerViewer::
120G4OpenInventorQtExaminerViewer(QWidget* parent,
const char* name, SbBool embed,
121 SoQtFullViewer::BuildFlag flag,
122 SoQtViewer::Type type)
124 : SoQtExaminerViewer(parent,
name, embed, flag, type),
140G4OpenInventorQtExaminerViewer::~G4OpenInventorQtExaminerViewer()
158void G4OpenInventorQtExaminerViewer::construct(
const SbBool)
165 buildWidget(getParentWidget());
173 fileName =
"bookmarkFile";
176 animateSensor =
new SoTimerSensor(animateSensorCB,
this);
177 animateSensorRotation =
new SoTimerSensor(animateSensorRotationCB,
this);
178 animateBtwPtsPeriod = MIN_SPEED;
180 currentState = GENERAL;
181 myCam =
new SoPerspectiveCamera;
184 curViewPtName =
new char[MAX_VP_NAME + 1];
185 left_right = up_down = 0;
186 speedStep = START_STEP;
191 lshiftdown = rshiftdown =
false;
194 lctrldown = rctrldown =
false;
196 abbrOutputFlag =
false;
197 pickRefPathFlag =
false;
198 prevColorField = NULL;
204 newSceneGraph = NULL;
205 zcoordSetFlag =
false;
212 static const char * superimposed[] = {
213 "#Inventor V2.1 ascii",
"",
220 " OrthographicCamera ",
226 " DEF soxt->callback Callback { }",
229 " DEF soxt->translation Translation ",
231 " translation 0 0 0",
233 " DEF soxt->scale Scale ",
235 " scaleFactor 1 1 1",
237 " DEF soxt->geometry Coordinate3 ",
241 " -0.81 -0.04 0, -0.81 0 0,",
242 " -0.81 0.04 0, 0 -0.04 0,",
244 " 0.81 -0.04 0, 0.81 0 0,",
247 " 0.81 0.02 0, 0.81 -0.02 0,",
250 " 0.4 0.01 0, 0.4 -0.01 0,",
255 " DEF soxt->animSpeedOutlineSwitch Switch ",
260 " emissiveColor 0 0 0",
266 " 12, 11, 10, 9, -1",
271 " DEF soxt->axisSwitch Switch ",
290 " DEF soxt->animSpeedSwitch Switch ",
295 " emissiveColor 0 1 0",
301 " 16, 15, 14, 13, -1",
307 " DEF soxt->curInfoSwitch Switch ",
310 " DEF soxt->curInfoTrans Translation ",
312 " translation 0 0 0 ",
315 " DEF soxt->curInfoFont Font ",
317 " name defaultFont:Bold",
320 " DEF soxt->curInfoText Text2 ",
329 " DEF soxt->mouseOverTransLogName Translation ",
331 " translation 0 0 0 ",
333 " DEF soxt->mouseOverFontLogName Font ",
335 " name defaultFont:Bold",
338 " DEF soxt->mouseOverTextLogName Text2 { } ",
342 " DEF soxt->mouseOverTransSolid Translation ",
344 " translation 0 0 0 ",
346 " DEF soxt->mouseOverFontSolid Font ",
348 " name defaultFont:Bold",
351 " DEF soxt->mouseOverTextSolid Text2 { } ",
355 " DEF soxt->mouseOverTransMaterial Translation ",
357 " translation 0 0 0 ",
359 " DEF soxt->mouseOverFontMaterial Font ",
361 " name defaultFont:Bold",
364 " DEF soxt->mouseOverTextMaterial Text2 { } ",
368 " DEF soxt->mouseOverTransZPos Translation ",
370 " translation 0 0 0 ",
372 " DEF soxt->mouseOverFontZPos Font ",
374 " name defaultFont:Bold",
377 " DEF soxt->mouseOverTextZPos Text2 { } ",
383 for (i = bufsize = 0; superimposed[i]; i++)
384 bufsize += strlen(superimposed[i]) + 1;
385 char * buf =
new char[bufsize + 1];
386 for (i = bufsize = 0; superimposed[i]; i++) {
387 strcpy(buf + bufsize, superimposed[i]);
388 bufsize += strlen(superimposed[i]);
392 SoInput * input =
new SoInput;
393 input->setBuffer(buf, bufsize);
394 SbBool ok = SoDB::read(input, superimposition);
399 superimposition->ref();
401 sscale = (SoScale *) getSuperimpositionNode(superimposition,
"soxt->scale");
402 stranslation = (SoTranslation *) getSuperimpositionNode(superimposition,
"soxt->translation");
403 sgeometry = (SoCoordinate3 *) getSuperimpositionNode(superimposition,
"soxt->geometry");
404 axisSwitch = (SoSwitch *) getSuperimpositionNode(superimposition,
"soxt->axisSwitch");
405 animSpeedOutlineSwitch = (SoSwitch *) getSuperimpositionNode(superimposition,
"soxt->animSpeedOutlineSwitch");
406 animSpeedSwitch = (SoSwitch *) getSuperimpositionNode(superimposition,
"soxt->animSpeedSwitch");
407 curInfoSwitch = (SoSwitch *) getSuperimpositionNode(superimposition,
"soxt->curInfoSwitch");
408 curInfoTrans = (SoTranslation *) getSuperimpositionNode(superimposition,
"soxt->curInfoTrans");
409 curInfoFont = (SoFont *) getSuperimpositionNode(superimposition,
"soxt->curInfoFont");
410 curInfoText = (SoText2 *) getSuperimpositionNode(superimposition,
"soxt->curInfoText");
411 mouseOverTransLogName = (SoTranslation*)getSuperimpositionNode(superimposition,
"soxt->mouseOverTransLogName");
412 mouseOverFontLogName = (SoFont *) getSuperimpositionNode(superimposition,
"soxt->mouseOverFontLogName");
413 mouseOverTextLogName = (SoText2 *) getSuperimpositionNode(superimposition,
"soxt->mouseOverTextLogName");
414 mouseOverTransSolid = (SoTranslation *) getSuperimpositionNode(superimposition,
"soxt->mouseOverTransSolid");
415 mouseOverFontSolid = (SoFont *) getSuperimpositionNode(superimposition,
"soxt->mouseOverFontSolid");
416 mouseOverTextSolid = (SoText2 *) getSuperimpositionNode(superimposition,
"soxt->mouseOverTextSolid");
417 mouseOverTransMaterial = (SoTranslation*)getSuperimpositionNode(superimposition,
"soxt->mouseOverTransMaterial");
418 mouseOverFontMaterial = (SoFont *) getSuperimpositionNode(superimposition,
"soxt->mouseOverFontMaterial");
419 mouseOverTextMaterial = (SoText2 *) getSuperimpositionNode(superimposition,
"soxt->mouseOverTextMaterial");
420 mouseOverTransZPos = (SoTranslation *) getSuperimpositionNode(superimposition,
"soxt->mouseOverTransZPos");
421 mouseOverFontZPos = (SoFont *) getSuperimpositionNode(superimposition,
"soxt->mouseOverFontZPos");
422 mouseOverTextZPos = (SoText2 *) getSuperimpositionNode(superimposition,
"soxt->mouseOverTextZPos");
424 SoCallback * cb = (SoCallback *) getSuperimpositionNode(superimposition,
"soxt->callback");
425 cb->setCallback(superimpositionCB,
this);
427 addSuperimposition(superimposition);
428 setSuperimpositionEnabled(superimposition,
FALSE);
429 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
430 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
431 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
439void G4OpenInventorQtExaminerViewer::buildWidget(QWidget* parent)
442 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::buildWidget",
443 "Error: Parent is null.");
447 font->setPointSize(12);
449 parent->setFont(*font);
455 menubar =
new QMenuBar(getRenderAreaWidget());
461 filemenu =
new QMenu(
"File");
462 menubar->addMenu(filemenu);
464 FileOpenBookmark =
new QAction(
"Open Bookmark File",
this);
465 FileOpenBookmark->setFont(*font);
466 connect(FileOpenBookmark, SIGNAL(triggered()),
this,
467 SLOT(FileOpenBookmarkCB()));
468 filemenu->addAction(FileOpenBookmark);
470 FileNewBookmark =
new QAction(
"New Bookmark File",
this);
471 FileNewBookmark->setFont(*font);
472 connect(FileNewBookmark, SIGNAL(triggered()),
this,
473 SLOT(FileNewBookmarkCB()));
474 filemenu->addAction(FileNewBookmark);
476 FileLoadRefPath =
new QAction(
"Load Reference Path",
this);
477 FileLoadRefPath->setFont(*font);
478 connect(FileLoadRefPath, SIGNAL(triggered()),
this,
479 SLOT(FileLoadRefPathCB()));
480 filemenu->addAction(FileLoadRefPath);
482 FileSaveRefPath =
new QAction(
"Save Reference Path",
this);
483 FileSaveRefPath->setFont(*font);
484 connect(FileSaveRefPath, SIGNAL(triggered()),
this,
485 SLOT(FileSaveRefPathCB()));
486 filemenu->addAction(FileSaveRefPath);
488 FileLoadSceneGraph =
new QAction(
"Load scene graph",
this);
489 FileLoadSceneGraph->setFont(*font);
490 connect(FileLoadSceneGraph, SIGNAL(triggered()),
this,
491 SLOT(FileLoadSceneGraphCB()));
492 filemenu->addAction(FileLoadSceneGraph);
494 FileSaveSceneGraph =
new QAction(
"Save scene graph",
this);
495 FileSaveSceneGraph->setFont(*font);
496 connect(FileSaveSceneGraph, SIGNAL(triggered()),
this,
497 SLOT(FileSaveSceneGraphCB()));
498 filemenu->addAction(FileSaveSceneGraph);
502 toolsmenu =
new QMenu(
"Tools");
503 menubar->addMenu(toolsmenu);
505 ToolsAnimateRefParticle =
new QAction(
"Fly on Ref Path",
this);
506 ToolsAnimateRefParticle->setFont(*font);
507 connect(ToolsAnimateRefParticle, SIGNAL(triggered()),
this,
508 SLOT(ToolsAnimateRefParticleCB()));
509 toolsmenu->addAction(ToolsAnimateRefParticle);
511 ToolsRefPathStart =
new QAction(
"Go to start of Ref Path",
this);
512 ToolsRefPathStart->setFont(*font);
513 connect(ToolsRefPathStart, SIGNAL(triggered()),
this,
514 SLOT(ToolsRefPathStartCB()));
515 toolsmenu->addAction(ToolsRefPathStart);
517 ToolsRefPathInvert =
new QAction(
"Invert Ref Path",
this);
518 ToolsRefPathInvert->setFont(*font);
519 connect(ToolsRefPathInvert, SIGNAL(triggered()),
this,
520 SLOT(ToolsRefPathInvertCB()));
521 toolsmenu->addAction(ToolsRefPathInvert);
523 etcmenu =
new QMenu(
"Etc");
524 menubar->addMenu(etcmenu);
528 helpmenu =
new QMenu(
"Help");
529 menubar->addMenu(helpmenu);
531 HelpControls =
new QAction(
"Controls",
this);
532 HelpControls->setFont(*font);
533 connect(HelpControls, SIGNAL(triggered()),
this, SLOT(HelpControlsCB()));
534 helpmenu->addAction(HelpControls);
543 saveViewPtButton =
new QPushButton;
544 saveViewPtButton->setIcon(QPixmap((
const char **)saveViewPt_xpm));
545 saveViewPtButton->setIconSize(QSize(24,24));
546 saveViewPtButton->setToolTip(
"Bookmark this view");
547 connect(saveViewPtButton, SIGNAL(clicked()),
this,
548 SLOT(SaveViewPtCB()));
549 addAppPushButton(saveViewPtButton);
551 nextViewPtButton =
new QPushButton;
552 nextViewPtButton->setIconSize(QSize(24,24));
554 nextViewPtButton->setIcon(style.standardIcon(QStyle::SP_ArrowRight));
555 nextViewPtButton->setToolTip(
"Next bookmark");
556 connect(nextViewPtButton, SIGNAL(clicked()),
this,
557 SLOT(NextViewPtCB()));
558 addAppPushButton(nextViewPtButton);
560 prevViewPtButton =
new QPushButton;
561 prevViewPtButton->setIconSize(QSize(24,24));
562 prevViewPtButton->setIcon(style.standardIcon(QStyle::SP_ArrowLeft));
563 prevViewPtButton->setToolTip(
"Previous bookmark");
564 connect(prevViewPtButton, SIGNAL(clicked()),
this,
565 SLOT(PrevViewPtCB()));
566 addAppPushButton(prevViewPtButton);
568 abbrOutputButton =
new QPushButton;
570 abbrOutputButton->setCheckable(
true);
571 abbrOutputButton->setIconSize(QSize(24,24));
572 abbrOutputButton->setIcon(QPixmap((
const char **)pickext_xpm));
573 abbrOutputButton->setToolTip(
"Extended picking & readout");
574 connect(abbrOutputButton, SIGNAL(toggled(
bool)),
this,
575 SLOT(AbbrOutputCB(
bool)));
576 addAppPushButton(abbrOutputButton);
578 pickRefPathButton =
new QPushButton;
579 pickRefPathButton->setIconSize(QSize(24,24));
580 pickRefPathButton->setIcon(QPixmap((
const char **)pickref_xpm));
581 pickRefPathButton->setToolTip(
"Pick ref trajectory");
582 connect(pickRefPathButton, SIGNAL(clicked()),
this,
583 SLOT(PickRefPathCB()));
584 addAppPushButton(pickRefPathButton);
586 switchWireFrameButton =
new QPushButton;
588 switchWireFrameButton->setCheckable(
true);
589 switchWireFrameButton->setIconSize(QSize(24,24));
590 switchWireFrameButton->setIcon(QPixmap((
const char **)wireframe_xpm));
591 switchWireFrameButton->setToolTip(
"Switch wireframe/solid");
592 connect(switchWireFrameButton, SIGNAL(toggled(
bool)),
this,
593 SLOT(SwitchWireFrameCB(
bool)));
594 addAppPushButton(switchWireFrameButton);
598 helpmsgbox =
new QMessageBox(getParentWidget());
599 helpmsgbox->setWindowTitle(
"OIQt Controls");
600 helpmsgbox->setFont(*font);
602"\nVIEWING mode (Hand cursor):\n\n\
603 Left-button + pointer move: rotate\n\
604 Shift+Left-button + pointer move: pan\n\
605 Middle-button + pointer move: pan\n\
606 Ctrl+Shift+Left-button + pointer move: zoom\n\
608 Right-button: popup menu\n\n\
609PICKING mode (Arrow cursor):\n\n\
610 Click on a volume: geometry readout\n\
611 Click on a trajectory: particle & trajectory readout\n\
612 Ctrl + click on a volume: see daughters.\n\
613 Shift + click on a volume: see mother.\n\n\
614EXTENDED PICKING mode (Arrow+ viewer button):\n\n\
615 Hover the mouse over a volume or trajectory for\n\
616 overlayed readout.\n\n\
617ELEMENT NAVIGATION (requires Reference Path):\n\n\
618 Click on element in list: centers view on element\n\
619 Arrow keys: rotate in 90 degree steps around element \n\
620 Shift + Right Arrow: move to next element\n\
621 Shift + Left Arrow: move to previous element\n\n\
622FLY mode (requires Reference Path):\n\n\
623 Page Up: Increase speed\n\
624 Page Down: Decrease speed (& reverse if wanted)\n\
625 Up Arrow: raise camera above path\n\
626 Down Arror: lower camera below path\n\
627 Escape: Exit fly mode";
628 helpmsgbox->setText(messagetxt);
629 helpmsgbox->setModal(
false);
638 AuxWindow =
new QDialog(parent);
639 AuxWindowDialog->setupUi(AuxWindow);
642 connect(AuxWindowDialog->listWidget, SIGNAL(itemClicked(QListWidgetItem*)),
643 this, SLOT(LoadBookmarkCB(QListWidgetItem*)));
644 connect(AuxWindowDialog->listWidget1, SIGNAL(itemClicked(QListWidgetItem*)),
645 this, SLOT(LookAtSceneElementCB(QListWidgetItem*)));
646 connect(AuxWindowDialog->pushButton_2, SIGNAL(clicked()),
647 this, SLOT(DeleteBookmarkCB()));
648 connect(AuxWindowDialog->pushButton_3, SIGNAL(clicked()),
649 this, SLOT(RenameBookmarkCB()));
650 connect(AuxWindowDialog->pushButton, SIGNAL(clicked()),
651 this, SLOT(SortBookmarksCB()));
667void G4OpenInventorQtExaminerViewer::afterRealizeHook()
669 SoQtExaminerViewer::afterRealizeHook();
673 SoCamera *cam = getCamera();
675 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
677 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
680 ((SoOrthographicCamera *) cam)->height.getValue();
684 ((SoOrthographicCamera *) cam)->height.getValue();
687 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
689 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
695 fileIn.open(fileName.c_str());
696 if (!fileIn.fail()) {
697 if (!loadViewPts()) {
699 msgbox.setFont(*font);
700 QString messagetxt =
"Error reading bookmark file ";
701 messagetxt.append(QString(fileName.c_str()));
702 msgbox.setText(messagetxt);
706 fileOut.open(fileName.c_str(), std::ios::in);
707 fileOut.seekp(0, std::ios::end);
711 if (viewPtList.size()) {
721 fileOut.open(fileName.c_str());
728 SoSeparator* root = (SoSeparator*) (getSceneManager()->getSceneGraph());
730 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::afterRealizeHook",
"Root is null.");
732 root->addChild(myCam);
735 sceneChangeSensor =
new SoNodeSensor;
736 sceneChangeSensor->setFunction(sceneChangeCB);
737 sceneChangeSensor->attach(root);
738 sceneChangeSensor->setData(
this);
746 SoEventCallback *moCB =
new SoEventCallback;
747 moCB->addEventCallback(
748 SoLocation2Event::getClassTypeId(),
749 mouseoverCB,
static_cast<void *
>(
this));
750 root->addChild(moCB);
754 SoEventCallback *pickCB =
new SoEventCallback;
755 pickCB->addEventCallback(
756 SoMouseButtonEvent::getClassTypeId(),
757 pickingCB,
static_cast<void *
>(
this));
758 root->addChild(pickCB);
764 AuxWindow->activateWindow();
771G4OpenInventorQtExaminerViewer::getSuperimpositionNode(SoNode* root,
775 searcher =
new SoSearchAction;
777 searcher->setName(SbName(name));
778 searcher->setInterest(SoSearchAction::FIRST);
779 searcher->setSearchingAll(
TRUE);
780 searcher->apply(root);
781 assert(searcher->getPath());
782 return searcher->getPath()->getTail();
788void G4OpenInventorQtExaminerViewer::superimpositionCB(
void * closure,
792 ((G4OpenInventorQtExaminerViewer*)closure)->superimpositionEvent(action);
798void G4OpenInventorQtExaminerViewer::superimpositionEvent(SoAction * action)
801 if (!action->isOfType(SoGLRenderAction::getClassTypeId()))
803 SbViewportRegion vpRegion =
804 ((SoGLRenderAction*)action)->getViewportRegion();
805 SbVec2s viewportSize = vpRegion.getViewportSizePixels();
808 float aspect = float(viewportSize[0]) / float(viewportSize[1]);
819 float factorx = 1.0f / float(viewportSize[1]) * 220.0f;
820 float factory = factorx;
823 stranslation->translation.setValue(SbVec3f(0.0f, -0.4f, 0.0f));
825 stranslation->translation.setValue(SbVec3f(0.0f, -0.4f / aspect, 0.0f));
829 if (viewportSize[0] > 500)
830 factorx *= 500.0f / 400.0f;
832 factorx *= float(viewportSize[0]) / 400.0f;
834 sscale->scaleFactor.setValue(SbVec3f(factorx, factory, 1.0f));
842 float xInfo, yInfo, xLogName, yLogName, xSolid, ySolid,
843 xMaterial, yMaterial, xZPos, yZPos;
851 if (aspect > 1.) xInfo = xInfo*aspect;
852 if (aspect < 1.) yInfo = yInfo/aspect;
853 yInfo = yInfo - mbgap*aspect;
857 yLogName = -.88 + mbgap*aspect;
859 ySolid = -.91 + mbgap*aspect;
861 yMaterial = -.94 + mbgap*aspect;
863 yZPos = -.97 + mbgap*aspect;
866 curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
869 mouseOverTransLogName->translation.setValue(SbVec3f(xLogName, yLogName, 0.0));
870 mouseOverTransSolid->translation.setValue(SbVec3f(xSolid, ySolid, 0.0));
871 mouseOverTransMaterial->translation.setValue(SbVec3f(xMaterial, yMaterial, 0.0));
872 mouseOverTransZPos->translation.setValue(SbVec3f(xZPos, yZPos, 0.0));
874 if (currentState == VIEWPOINT) {
875 curInfoFont->size.setValue(15);
876 curInfoFont->name.setValue(
"defaultFont:Italic");
877 curInfoText->string.setValue(SbString(curViewPtName));
879 else if(currentState == GENERAL) {
880 curInfoFont->size.setValue(16);
881 curInfoFont->name.setValue(
"defaultFont:Bold");
882 curInfoText->string.setValue(SbString(
""));
885 if (refParticleIdx < (
int) refParticleTrajectory.size() - 1) {
886 curInfoFont->size.setValue(16);
887 curInfoFont->name.setValue(
"defaultFont:Bold");
890 sprintf(zPos,
"%-7.2f [m]", refZPositions[refParticleIdx] / 1000);
892 curInfoText->string.setValue(SbString(zPos));
900bool G4OpenInventorQtExaminerViewer::loadViewPts()
907 float x, y, z, angle;
911 parseString<int>(viewPtIdx, token, error);
912 getline(fileIn, token);
914 while (getline(fileIn, token)) {
916 int end = token.find_last_not_of(
' ');
917 token = token.substr(0, end + 1);
919 char *vpName =
new char[token.size() + 1];
920 strcpy(vpName, token.c_str());
921 tmp.viewPtName = vpName;
924 parseString<float>(x, token, error);
926 parseString<float>(y, token, error);
928 parseString<float>(z, token, error);
930 tmp.position = axis.setValue(x, y, z);
932 parseString<float>(x, token, error);
934 parseString<float>(y, token, error);
936 parseString<float>(z, token, error);
938 parseString<float>(angle, token, error);
940 orient.setValue(axis.setValue(x, y, z), angle);
941 tmp.orientation = orient.getValue();
944 parseString<int>(camType, token, error);
946 tmp.camType = (CameraType) camType;
948 parseString<float>(tmp.height, token, error);
950 parseString<float>(tmp.focalDistance, token, error);
952 parseString<float>(tmp.nearDistance, token, error);
954 parseString<float>(tmp.farDistance, token, error);
956 parseString<int>(tmp.viewportMapping, token, error);
958 parseString<float>(tmp.aspectRatio, token, error);
960 getline(fileIn, token);
961 getline(fileIn, token);
968 viewPtList.push_back(tmp);
977void G4OpenInventorQtExaminerViewer::rotateCamera()
979 SoCamera *cam = getCamera();
981 SbRotation rot(rotAxis,
M_PI / (2 * ROT_CNT));
982 rot.multVec(camDir, camDir);
983 rot.multVec(camUpVec, camUpVec);
985 SbVec3f camPosNew = prevPt - (camDir*distance);
986 cam->position = camPosNew;
987 cam->pointAt(prevPt, camUpVec);
988 cam->focalDistance = (prevPt - camPosNew).length();
992 if (animateSensorRotation->isScheduled()) {
993 animateSensorRotation->unschedule();
996 animateSensorRotation->setBaseTime(SbTime::getTimeOfDay());
997 animateSensorRotation->setInterval(SbTime(0.02));
998 animateSensorRotation->schedule();
1004void G4OpenInventorQtExaminerViewer::moveCamera(
float dist,
bool lookdown)
1007 SoCamera *cam = getCamera();
1009 SbVec3f particleDir;
1012 if(refParticleTrajectory.size() == 0) {
1017 distance = (cam->position.getValue() - center).length();
1019 cam->position.setValue(center + offsetFromCenter*distance);
1020 cam->focalDistance = (cam->position.getValue() - center).length();
1021 cam->pointAt(center, upVector);
1027 if (refParticleIdx >= (
int) refParticleTrajectory.size() - 1) {
1028 prevPt = refParticleTrajectory[refParticleIdx - step];
1029 dist = (prevPt - cam->position.getValue()).length();
1034 if (refParticleIdx < 0) {
1035 prevPt = refParticleTrajectory[refParticleIdx + step];
1036 dist = (prevPt - cam->position.getValue()).length();
1037 refParticleIdx = refParticleTrajectory.size() - 2;
1041 p1 = refParticleTrajectory[refParticleIdx];
1042 p2 = refParticleTrajectory[refParticleIdx + step];
1045 particleDir = p2 - p1;
1046 particleDir.normalize();
1048 if(prevParticleDir == SbVec3f(0,0,0)) {
1052 camDir = SbVec3f(0,0,1);
1054 camDir = SbVec3f(1,0,0);
1055 camUpVec = SbVec3f(0,1,0);
1059 SbRotation rot(SbVec3f(0,0,1), particleDir);
1060 rot.multVec(camDir, camDir);
1061 rot.multVec(camUpVec, camUpVec);
1064 else if(particleDir != prevParticleDir) {
1067 SbRotation rot(prevParticleDir, particleDir);
1068 rot.multVec(camDir, camDir);
1069 rot.multVec(camUpVec, camUpVec);
1073 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1075 distance = (prevPt - cam->position.getValue()).length();
1090 prevPt.getValue(x,y,z);
1093 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1094 camPosNew = p2 - (camDir*distance);
1096 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
1098 camPosNew = p2 - (camDir*cam->focalDistance.getValue());
1102 cam->position = camPosNew;
1103 cam->pointAt(p2, camUpVec);
1104 cam->focalDistance = (p2 - camPosNew).length();
1107 camPosNew.getValue(x,y,z);
1109 prevParticleDir = particleDir;
1117void G4OpenInventorQtExaminerViewer::pickingCB(
void *aThis,
1118 SoEventCallback *eventCB)
1120 SoHandleEventAction* action = eventCB->getAction();
1121 const SoPickedPoint *
pp = action->getPickedPoint();
1122 G4OpenInventorQtExaminerViewer* This = (G4OpenInventorQtExaminerViewer*)aThis;
1126 SoPath* path =
pp->getPath();
1127 SoNode* node = ((SoFullPath*)path)->getTail();
1129 if(node->getTypeId() == SoLineSet::getClassTypeId()) {
1131 if(This->pickRefPathFlag) {
1132 This->pickRefPathFlag =
false;
1133 if(This->viewingBeforePickRef != This->isViewing())
1134 This->setViewing(This->viewingBeforePickRef);
1136 This->setComponentCursor(SoQtCursor(SoQtCursor::DEFAULT));
1139 SoLineSet * trajectory = (SoLineSet *)node;
1147 SoSeparator * grpNode =
1148 (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1153 int nodeIndex = grpNode->findChild(trajectory);
1156 SoCoordinate3 * coords = 0;
1160 for(
int i = 0; i < 100; ++i) {
1163 tmpNode = grpNode->getChild(nodeIndex);
1164 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()) {
1166 coords = (SoCoordinate3 *)tmpNode;
1171 if(coords == NULL) {
1172 G4cout <<
"Could not find the coordinates node"
1173 " for the picked trajectory." <<
G4endl;
1181 if ((This->lshiftdown) || (This->rshiftdown))
1182 This->setReferencePath(trajectory, coords,
true);
1184 This->setReferencePath(trajectory, coords,
false);
1189 else if(This->abbrOutputFlag) {
1192 if(attHolder && attHolder->
GetAttDefs().size()) {
1194 std::string strTrajPoint =
"G4TrajectoryPoint:";
1195 std::ostringstream oss;
1196 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1201 if(oss.str().find(strTrajPoint) != std::string::npos) {
1216 G4String cls((
char*)node->getTypeId().getName().getString());
1217 G4cout <<
"SoNode : " << node
1218 <<
" SoType : " << cls
1219 <<
" name : " <<
name
1236 if(attHolder && attHolder->
GetAttDefs().size()) {
1237 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1243 G4String cls((
char*)node->getTypeId().getName().getString());
1244 G4cout <<
"SoNode : " << node
1245 <<
" SoType : " << cls
1246 <<
" name : " <<
name
1252 eventCB->setHandled();
1257void G4OpenInventorQtExaminerViewer::mouseoverCB(
void *aThis, SoEventCallback *eventCB)
1259 SoHandleEventAction* action = eventCB->getAction();
1260 const SoPickedPoint*
pp = action->getPickedPoint();
1261 G4OpenInventorQtExaminerViewer* This = (G4OpenInventorQtExaminerViewer*)aThis;
1263 if(!This->abbrOutputFlag)
1268 const SbViewportRegion & viewportRegion = action->getViewportRegion();
1270 std::string sLogName;
1272 std::stringstream ssZPos;
1273 std::stringstream ssSolids;
1274 std::stringstream ssMaterials;
1275 SoPath * path =
pp->getPath();
1276 SoNode* node = ((SoFullPath*)path)->getTail();
1278 if(node->getTypeId() == Geant4_SoPolyhedron::getClassTypeId()) {
1280 sLogName =
"Logical Volume: ";
1283 SoGetBoundingBoxAction bAction(viewportRegion);
1284 bAction.apply((SoFullPath*)path);
1285 SbBox3f bBox = bAction.getBoundingBox();
1286 SbVec3f center = bBox.getCenter();
1287 center.getValue(x,y,z);
1288 ssZPos <<
"Pos: " << x <<
" " << y <<
" " << z;
1291 if(attHolder && attHolder->
GetAttDefs().size()) {
1293 std::vector<const std::map<G4String,G4AttDef>*> vecDefs =
1295 std::vector<const std::vector<G4AttValue>*> vecVals =
1297 for (
size_t i = 0; i < vecDefs.size(); ++i) {
1298 const std::vector<G4AttValue> * vals = vecVals[i];
1300 std::vector<G4AttValue>::const_iterator iValue;
1302 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1303 const G4String& valueName = iValue->GetName();
1304 const G4String& value = iValue->GetValue();
1306 if(valueName ==
"Solid") {
1307 if(ssSolids.str() ==
"")
1308 ssSolids <<
"Solid Name: " << value;
1310 ssSolids <<
", " << value;
1313 if(valueName ==
"Material") {
1314 if(ssMaterials.str() ==
"")
1315 ssMaterials <<
"Material Name: " << value;
1317 ssMaterials <<
", " << value;
1324 else if(node->getTypeId() == SoLineSet::getClassTypeId()) {
1327 if(attHolder && attHolder->
GetAttDefs().size()) {
1328 std::string strTrajPoint =
"G4TrajectoryPoint:";
1329 std::ostringstream oss;
1331 for (
size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1334 const std::vector<G4AttValue>* vals = attHolder->
GetAttValues()[i];
1335 std::vector<G4AttValue>::const_iterator iValue;
1336 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1337 const G4String& valueName = iValue->GetName();
1338 const G4String& value = iValue->GetValue();
1342 if (valueName ==
"PN") t1 = value;
1343 if (valueName ==
"Ch") {
1344 if (atof(value.c_str()) > 0)
1350 if (valueName ==
"PDG") {
1354 This->mouseOverTextLogName->string.setValue(t1);
1358 if (valueName ==
"EventID") t2 =
"Evt " + value;
1359 if (valueName ==
"ID") t2 +=
" Trk " + value;
1360 if (valueName ==
"PID") {
1361 t2 +=
" Prt " + value;
1362 This->mouseOverTextSolid->string.setValue(t2);
1365 if (valueName ==
"IKE") t3 =
"KE " + value;
1366 if (valueName ==
"IMom") {
1368 unsigned ipos = value.rfind(
" ");
1371 t3 +=
" P (" + value1 +
")";
1373 if (valueName ==
"IMag") {
1374 t3 +=
" " + value +
"/c";
1376 This->mouseOverTextMaterial->string.setValue(t3);
1379 if (valueName ==
"NTP") {
1380 std::ostringstream t4oss;
1381 t4oss <<
"TrjPts " << value;
1382 t4oss <<
" Pos " <<
pp->getPoint()[0] <<
" " <<
pp->getPoint()[1] <<
1383 " " <<
pp->getPoint()[2];
1384 This->mouseOverTextZPos->string.setValue(SbString(t4oss.str().c_str()));
1405 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
1406 This->scheduleRedraw();
1407 eventCB->setHandled();
1411 bool redraw =
false;
1412 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) != sLogName) {
1413 This->mouseOverTextLogName->string.setValue(SbString(sLogName.c_str()));
1416 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) != ssSolids.str()) {
1417 This->mouseOverTextSolid->string.setValue(SbString(ssSolids.str().c_str()));
1420 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) != ssMaterials.str()) {
1421 This->mouseOverTextMaterial->string.setValue(SbString(ssMaterials.str().c_str()));
1424 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) != ssZPos.str()) {
1425 This->mouseOverTextZPos->string.setValue(SbString(ssZPos.str().c_str()));
1430 This->setSuperimpositionEnabled(This->superimposition,
TRUE);
1431 This->scheduleRedraw();
1434 eventCB->setHandled();
1437 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) !=
"") {
1438 This->mouseOverTextLogName->string.setValue(SbString(
""));
1439 This->scheduleRedraw();
1441 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) !=
"") {
1442 This->mouseOverTextSolid->string.setValue(SbString(
""));
1443 This->scheduleRedraw();
1445 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) !=
"") {
1446 This->mouseOverTextMaterial->string.setValue(SbString(
""));
1447 This->scheduleRedraw();
1449 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) !=
"") {
1450 This->mouseOverTextZPos->string.setValue(SbString(
""));
1451 This->scheduleRedraw();
1458void G4OpenInventorQtExaminerViewer::incSpeed() {
1459 if (std::ceil(animateBtwPtsPeriod * 100) >= 4) {
1460 if (speedStep > 0.08)
1464 animateBtwPtsPeriod -= speedStep;
1466 animateBtwPtsPeriod = 0.0;
1468 if (currentState != PAUSED_ANIMATION) {
1469 int lastIdx = refParticleTrajectory.size() - 1;
1470 if (refParticleIdx < lastIdx && !animateSensor->isScheduled())
1471 animateRefParticle();
1476void G4OpenInventorQtExaminerViewer::decSpeed() {
1477 animateBtwPtsPeriod += speedStep;
1478 if (animateBtwPtsPeriod < MIN_SPEED) {
1479 if (std::floor(animateBtwPtsPeriod * 100) == 12) {
1481 }
else if (animateBtwPtsPeriod > 0.12)
1484 animateBtwPtsPeriod = MIN_SPEED;
1485 speedStep = START_STEP;
1487 if (animateSensor->isScheduled())
1488 animateSensor->unschedule();
1495void G4OpenInventorQtExaminerViewer::updateSpeedIndicator(
void)
1497 assert(this->sgeometry != NULL);
1499 SbVec3f * points = this->sgeometry->point.startEditing();
1501 if (points[10][0] == 0.0f)
1502 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
1503 if (points[14][0] == 0.0f)
1504 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
1505 points[10][0] = this->maxSpeed;
1506 points[11][0] = this->maxSpeed;
1507 points[14][0] = this->maxSpeed;
1508 points[15][0] = this->maxSpeed;
1509 this->sgeometry->point.finishEditing();
1511 if (this->maxSpeed == 0.0f) {
1512 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
1513 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1518void G4OpenInventorQtExaminerViewer::actualRedraw(
void) {
1519 switch (currentState) {
1521 case REVERSED_ANIMATION:
1522 case PAUSED_ANIMATION:
1523 updateSpeedIndicator();
1524 SoQtExaminerViewer::actualRedraw();
1527 SoQtExaminerViewer::actualRedraw();
1533void G4OpenInventorQtExaminerViewer::setReferencePath(SoLineSet *lineset,
1534 SoCoordinate3 *coords,
bool append)
1545 SbVec3f refParticlePt;
1548 refParticleTrajectory.clear();
1550 for(
int i = 0; i < lineset->numVertices.getNum(); ++i) {
1551 for(
int j = 0; j < lineset->numVertices[i]; ++j) {
1552 refParticlePt = coords->point[j];
1553 refParticleTrajectory.push_back(refParticlePt);
1557 evenOutRefParticlePts();
1558 setReferencePathZPos();
1564void G4OpenInventorQtExaminerViewer::setReferencePathZPos()
1566 refZPositions.clear();
1567 refZPositions.push_back(0);
1569 for(
unsigned int i=0; i < refParticleTrajectory.size() - 1; ++i) {
1570 dist = (refParticleTrajectory[i] -
1571 refParticleTrajectory[i + 1]).length();
1572 refZPositions.push_back(refZPositions[i] + dist);
1577void G4OpenInventorQtExaminerViewer::findAndSetRefPath()
1579 SoSearchAction action;
1580 action.setType(SoLineSet::getClassTypeId(),
false);
1581 action.setInterest(SoSearchAction::ALL);
1582 action.apply(getSceneGraph());
1584 SoPathList &pathList = action.getPaths();
1586 if(pathList.getLength() != 0) {
1588 SoCoordinate3 * coords = NULL;
1589 std::vector<SoCoordinate3 *> coordvec;
1590 std::vector<SoLineSet *> linevec;
1592 bool refPathFound =
false;
1593 for(
int i = 0; i < pathList.getLength(); ++i) {
1594 SoFullPath *path = (SoFullPath *)pathList[i];
1597 for (
size_t j = 0; j < attHolder->
GetAttDefs().size(); ++j) {
1598 std::ostringstream oss;
1602 std::string findStr =
"Type of trajectory (Type): ";
1603 std::string compareValue =
"REFERENCE";
1604 size_t idx = oss.str().find(findStr);
1606 if(idx != std::string::npos) {
1607 if(oss.str().substr(idx + findStr.size(),
1608 compareValue.size()) == compareValue) {
1609 coords = getCoordsNode(path);
1610 if(coords != NULL) {
1611 refPathFound =
true;
1612 coordvec.push_back(coords);
1613 linevec.push_back((SoLineSet *)path->getTail());
1619 findStr =
"Track ID (ID): ";
1620 idx = oss.str().find(findStr);
1621 if(idx != std::string::npos) {
1623 std::string tmpstr = oss.str().substr(idx + findStr.size(),1);
1624 std::istringstream
buffer(tmpstr);
1632 char nextChar = oss.str().at(idx+findStr.size()+1);
1635 if(std::isdigit(nextChar))
1639 coords = getCoordsNode(path);
1640 if(coords != NULL) {
1641 coordvec.push_back(coords);
1642 linevec.push_back((SoLineSet *)path->getTail());
1658 if(coordvec.empty())
1663 setReferencePath(linevec.back(), coordvec.back());
1669 float longestLength = 0.0;
1671 for(
unsigned int i=0;i < linevec.size(); ++i) {
1674 std::vector<SbVec3f> trajectory;
1676 for(
int j=0; j < linevec[i]->numVertices.getNum(); ++j) {
1678 for(
int k=0; k < linevec[i]->numVertices[j]; ++k) {
1679 trajectory.push_back(coordvec[i]->point[k]);
1684 float tmpLength=0.0;
1685 for(
unsigned int j=0; j < trajectory.size() - 1; ++j) {
1686 tmpLength += (trajectory[j] - trajectory[j + 1]).length();
1689 if(tmpLength > longestLength) {
1691 longestLength = tmpLength;
1696 setReferencePath(linevec[longestIdx], coordvec[longestIdx]);
1701SoCoordinate3 * G4OpenInventorQtExaminerViewer::getCoordsNode(SoFullPath *path)
1703 SoLineSet *trajectory = (SoLineSet *)path->getTail();
1704 SoSeparator * grpNode = (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1705 int nodeIndex = grpNode->findChild(trajectory);
1710 for (
int i = 0; i < 100; ++i) {
1713 tmpNode = grpNode->getChild(nodeIndex);
1714 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()) {
1716 return (SoCoordinate3 *)tmpNode;
1725void G4OpenInventorQtExaminerViewer::getSceneElements()
1727 std::string field, eltName;
1729 std::map<std::string, int> duplicates;
1730 std::map<std::string, int> sceneElts;
1731 SoSearchAction search;
1733 SoGroup *root = (SoGroup *)getSceneManager()->getSceneGraph();
1735 SoBaseKit::setSearchingChildren(
TRUE);
1738 search.setSearchingAll(
TRUE);
1739 search.setInterest(SoSearchAction::ALL);
1740 search.setType(Geant4_SoPolyhedron::getClassTypeId(), 0);
1746 SoPathList &pl = search.getPaths();
1750 for (
int i = 0; i < pl.getLength(); i++) {
1751 SoFullPath *path = (SoFullPath *)pl[i];
1753 eltName = node->getName();
1755 if(duplicates.count(eltName))
1756 duplicates[eltName]++;
1758 duplicates[eltName] = 1;
1761 for(
int i = 0; i < pl.getLength(); i++) {
1763 std::stringstream ssCount;
1764 SoFullPath *path = (SoFullPath *)pl[i];
1766 eltName = node->getName();
1768 if(duplicates[eltName] == 1)
1771 if(sceneElts.count(eltName))
1772 sceneElts[eltName]++;
1774 sceneElts[eltName] = 1;
1776 ssCount << sceneElts[eltName];
1780 field += ssCount.str();
1782 SoGetBoundingBoxAction bAction(getViewportRegion());
1783 bAction.apply(path);
1784 SbBox3f bBox = bAction.getBoundingBox();
1786 SbVec3f centr = bBox.getCenter();
1787 centr.getValue(x,y,z);
1790 sceneElement el = { field, path, centr, 0.0 };
1791 sceneElements.push_back(el);
1796float G4OpenInventorQtExaminerViewer::sqrlen(
const SbVec3f &a)
1800 return x*x + y*y + z*z;
1804void G4OpenInventorQtExaminerViewer::distanceToTrajectory(
const SbVec3f &q,
1806 SbVec3f &closestPoint,
1841 const size_t count = refParticleTrajectory.size();
1844 SbVec3f b = refParticleTrajectory[0];
1845 SbVec3f dbq = b - q;
1846 float sqrDist = sqrlen(dbq);
1849 for (
size_t i = 1; i < count; ++i) {
1850 const SbVec3f a = b;
1851 const SbVec3f daq = dbq;
1852 b = refParticleTrajectory[i];
1854 const SbVec3f dab = a - b;
1856 float dab_x, dab_y, dab_z;
1857 dab.getValue(dab_x,dab_y,dab_z);
1858 float daq_x, daq_y, daq_z;
1859 daq.getValue(daq_x, daq_y, daq_z);
1860 float dbq_x, dbq_y, dbq_z;
1861 dbq.getValue(dbq_x, dbq_y, dbq_z);
1863 const float inv_sqrlen = 1./sqrlen(dab);
1864 const float t = (dab_x*daq_x + dab_y*daq_y + dab_z*daq_z)*inv_sqrlen;
1875 current_dist = daq_x*daq_x + daq_y*daq_y + daq_z*daq_z
1876 - t*(daq_x*dab_x + daq_y*dab_y + daq_z*dab_z)
1877 + t*t*(dab_x*dab_x + dab_y*dab_y + dab_z*dab_z);
1882 current_dist = sqrlen(dbq);
1885 if (current_dist < sqrDist) {
1886 sqrDist = current_dist;
1887 closestPoint = a + t*(b-a);
1892 dist = std::sqrt(sqrDist);
1896void G4OpenInventorQtExaminerViewer::sortElements()
1898 if(refParticleTrajectory.empty())
1901 float * trajLength =
new float[refParticleTrajectory.size()];
1902 typedef std::map<elementForSorting, sceneElement> sortedMap;
1908 std::vector<SbVec3f>::iterator itRef = refParticleTrajectory.begin();
1911 trajLength[trajIndex] = 0.0;
1914 for(; itRef != refParticleTrajectory.end(); ++itRef, ++trajIndex) {
1915 trajLength[trajIndex] = trajLength[trajIndex-1] + (*itRef - prevPoint).length();
1923 SoGetBoundingBoxAction bAction(getViewportRegion());
1924 SbVec3f elementCoord;
1925 std::vector<sceneElement>::iterator itEl;
1927 elementForSorting el;
1928 for(itEl = sceneElements.begin(), elementIndex = 0;
1929 itEl != sceneElements.end(); ++itEl, ++elementIndex) {
1930 bAction.apply(itEl->path);
1933 elementCoord = itEl->center;
1942 distanceToTrajectory(elementCoord, el.smallestDistance, el.closestPoint, index);
1943 itEl->closestPointZCoord = el.closestPointZCoord = trajLength[index];
1944 el.distanceToBeamlineStart = (itEl->center - refParticleTrajectory[0]).length();
1951 sorted.insert(std::make_pair(el,*itEl));
1955 sceneElements.clear();
1957 sortedMap::iterator itSorted = sorted.begin();
1958 for(; itSorted != sorted.end(); itSorted++)
1959 sceneElements.push_back(itSorted->second);
1961 zcoordSetFlag =
true;
1963 createElementsList();
1965 delete[] trajLength;
1969void G4OpenInventorQtExaminerViewer::createElementsList()
1974 AuxWindowDialog->listWidget1->clear();
1977 std::vector<sceneElement>::const_iterator it;
1978 std::stringstream ss;
1980 for(it=sceneElements.begin(); it!=sceneElements.end(); ++it) {
1983 ss <<
" [" << it->closestPointZCoord <<
"]";
1985 new QListWidgetItem(ss.str().c_str(), AuxWindowDialog->listWidget1);
1994G4OpenInventorQtExaminerViewer::LookAtSceneElementCB(QListWidgetItem* item)
1997 std::string elementField;
2002 SoCamera * cam = getCamera();
2004 if (SoQtExaminerViewer::isAnimating())
2007 value = strdup(qPrintable(item->text()));
2010 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
2011 || currentState == PAUSED_ANIMATION ) {
2012 if (animateSensor->isScheduled())
2013 animateSensor->unschedule();
2014 setSuperimpositionEnabled(superimposition,
FALSE);
2018 currentState = prevState;
2019 }
else if (currentState == VIEWPOINT)
2020 setSuperimpositionEnabled(superimposition,
FALSE);
2022 elementField = value;
2024 int idx = elementField.find_last_of(
"[");
2026 idx = elementField.size();
2032 SoSearchAction search;
2033 SoNode *root = getSceneManager()->getSceneGraph();
2034 int counter, idxUnderscore = elementField.find_last_of(
"_");
2036 parseString<int>(counter,
2037 elementField.substr(idxUnderscore + 1, idx), error);
2039 SoBaseKit::setSearchingChildren(
TRUE);
2041 search.setSearchingAll(
TRUE);
2047 curEltName = elementField.substr(0, idx);
2048 search.setName(curEltName.c_str());
2051 path = (SoFullPath *)search.getPath();
2054 curEltName = elementField.substr(0, idxUnderscore);
2055 search.setInterest(SoSearchAction::ALL);
2056 search.setName(curEltName.c_str());
2059 SoPathList &pl = search.getPaths();
2060 path = (SoFullPath *)pl[counter - 1];
2066 if ((idx > 0) && (path)) {
2068 if(!refParticleTrajectory.empty()) {
2070 SoGetBoundingBoxAction bAction(getViewportRegion());
2071 bAction.apply(path);
2072 SbBox3f bBox = bAction.getBoundingBox();
2073 SbVec3f elementCoord = bBox.getCenter();
2078 float absLengthNow, absLengthMin;
2079 int maxIdx = refParticleTrajectory.size() - 2;
2083 p = refParticleTrajectory[refParticleIdx];
2084 absLengthMin = (p - elementCoord).length();
2088 while (refParticleIdx < maxIdx) {
2089 p = refParticleTrajectory[refParticleIdx];
2090 absLengthNow = (p - elementCoord).length();
2092 if (absLengthNow < absLengthMin) {
2093 absLengthMin = absLengthNow;
2094 targetIdx = refParticleIdx;
2099 if (currentState != BEAMLINE) {
2101 currentState = BEAMLINE;
2102 prevParticleDir = SbVec3f(0,0,0);
2104 p1 = prevPt = refParticleTrajectory[0];
2105 pN = refParticleTrajectory[refParticleTrajectory.size() - 1];
2106 distance = (pN - p1).length() / 10;
2118 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2119 ((SoPerspectiveCamera*)cam)->heightAngle.setValue(defaultHeightAngle);
2122 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2123 distance = (prevPt - cam->position.getValue()).length();
2125 refParticleIdx = targetIdx;
2128 setSuperimpositionEnabled(superimposition,
TRUE);
2129 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2130 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2131 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2135 moveCamera(distance);
2140 offsetFromCenter.setValue(0, 0, 1);
2142 upVector.setValue(0, 1, 0);
2143 moveCamera(distance);
2144 cam->viewAll(path, getViewportRegion());
2151void G4OpenInventorQtExaminerViewer::FileLoadRefPathCB()
2155 QFileDialog filedialog(getParentWidget(), tr(
"Load Reference Path"));
2156 filedialog.setFileMode(QFileDialog::AnyFile);
2157 filedialog.setFont(*font);
2158 if (!filedialog.exec())
return;
2159 QStringList filenameinlist = filedialog.selectedFiles();
2160 QString filenamein = filenameinlist[0];
2164 char* filename =
new char[filenamein.size()+1];
2165 filename = strdup(qPrintable(filenamein));
2168 std::ifstream ifs(filename);
2170 refParticleTrajectory.clear();
2172 while(ifs >> x >> y >> z) {
2173 refParticleTrajectory.push_back(SbVec3f(x,y,z));
2178 msgbox.setFont(*font);
2179 QString messagetxt =
"Reference Path file not found: ";
2180 messagetxt.append(filenamein);
2181 msgbox.setText(messagetxt);
2185 if (refParticleTrajectory.size() < 2) {
2187 msgbox.setFont(*font);
2188 QString messagetxt =
"Invalid Reference Path";
2189 msgbox.setText(messagetxt);
2194 evenOutRefParticlePts();
2195 setReferencePathZPos();
2201void G4OpenInventorQtExaminerViewer::FileSaveRefPathCB()
2205 QFileDialog filedialog(getParentWidget(), tr(
"Save Reference Path"));
2206 filedialog.setFileMode(QFileDialog::AnyFile);
2208 filedialog.setAcceptMode(QFileDialog::AcceptSave);
2209 filedialog.setFont(*font);
2210 if (!filedialog.exec())
return;
2211 QStringList filenameinlist = filedialog.selectedFiles();
2212 QString filenamein = filenameinlist[0];
2216 char* filename =
new char[filenamein.size()+1];
2217 filename = strdup(qPrintable(filenamein));
2220 std::ofstream ofs(filename);
2221 if (ofs.is_open()) {
2223 for (
unsigned int i=0; i < refParticleTrajectory.size(); ++i) {
2224 refParticleTrajectory[i].getValue(x,y,z);
2225 ofs << x <<
" " << y <<
" " << z <<
"\n";
2230 msgbox.setFont(*font);
2231 QString messagetxt =
"Error opening file ";
2232 messagetxt.append(filenamein);
2233 msgbox.setText(messagetxt);
2239void G4OpenInventorQtExaminerViewer::evenOutRefParticlePts()
2241 if(refParticleTrajectory.empty())
2244 SbVec3f p1, p2, p3, dirNow, dirNxt, dir, p2_tmp, p_start, p_corner, p_nxt;
2245 float avgDistBtwPts = 0;
2246 float totalDistBtwPts = 0;
2247 std::vector<SbVec3f> newRefParticleTrajectory;
2249 int size = refParticleTrajectory.size() - 1;
2251 for (
int i = 0; i < size; i++) {
2252 p1 = refParticleTrajectory[i];
2253 p2 = refParticleTrajectory[i + 1];
2257 totalDistBtwPts += (p2 - p1).length();
2260 if (numOfPts <= 2)
return;
2262 avgDistBtwPts = totalDistBtwPts / numOfPts;
2263 float minDistAllowed = 0.75 * avgDistBtwPts;
2269 p1 = refParticleTrajectory[i];
2270 p2 = refParticleTrajectory[i + 1];
2273 p1.getValue(x, y, z);
2275 newRefParticleTrajectory.push_back(refPoint);
2278 while ((p2 - p1).length() < minDistAllowed && j < (size - 1)) {
2281 p1 = refParticleTrajectory[j];
2282 p2 = refParticleTrajectory[j + 1];
2290 refParticleTrajectory.clear();
2291 refParticleTrajectory = newRefParticleTrajectory;
2295void G4OpenInventorQtExaminerViewer::saveCurCamera()
2297 SoCamera *cam = getCamera();
2298 camB4Animation.viewportMapping = cam->viewportMapping.getValue();
2299 camB4Animation.position = cam->position.getValue();
2300 camB4Animation.orientation = cam->orientation.getValue();
2301 camB4Animation.aspectRatio = cam->aspectRatio.getValue();
2302 camB4Animation.nearDistance = cam->nearDistance.getValue();
2303 camB4Animation.farDistance = cam->farDistance.getValue();
2304 camB4Animation.focalDistance = cam->focalDistance.getValue();
2306 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2307 camB4Animation.height =
2308 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
2309 camB4Animation.camType = PERSPECTIVE;
2310 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2311 camB4Animation.height =
2312 ((SoOrthographicCamera *) cam)->height.getValue();
2313 camB4Animation.camType = ORTHOGRAPHIC;
2318void G4OpenInventorQtExaminerViewer::restoreCamera()
2320 SoCamera *cam = getCamera();
2322 cam->viewportMapping = camB4Animation.viewportMapping;
2323 cam->position = camB4Animation.position;
2324 cam->orientation = camB4Animation.orientation;
2325 cam->aspectRatio = camB4Animation.aspectRatio;
2326 cam->nearDistance = camB4Animation.nearDistance;
2327 cam->farDistance = camB4Animation.farDistance;
2328 cam->focalDistance = camB4Animation.focalDistance;
2330 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2331 if (camB4Animation.camType == ORTHOGRAPHIC) {
2334 ((SoOrthographicCamera *) cam)->height.setValue(
2335 camB4Animation.height);
2337 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2338 camB4Animation.height);
2339 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2340 if (camB4Animation.camType == PERSPECTIVE) {
2343 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2344 camB4Animation.height);
2346 ((SoOrthographicCamera *) cam)->height.setValue(
2347 camB4Animation.height);
2352void G4OpenInventorQtExaminerViewer::animateSensorRotationCB(
void *data,
2355 SbTime curTime = SbTime::getTimeOfDay();
2356 G4OpenInventorQtExaminerViewer* This = (G4OpenInventorQtExaminerViewer*) data;
2358 SoTimerSensor* s = (SoTimerSensor*) sensor;
2360 float t = float((curTime - s->getBaseTime()).getValue())
2361 / This->animateBtwPtsPeriod;
2363 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2365 SbBool end = (t == 1.0f);
2368 This->animateSensorRotation->unschedule();
2371 This->rotateCamera();
2375 This->currentState = This->prevState;
2385void G4OpenInventorQtExaminerViewer::animateSensorCB(
void *data,
2388 SbTime curTime = SbTime::getTimeOfDay();
2389 G4OpenInventorQtExaminerViewer* This = (G4OpenInventorQtExaminerViewer*) data;
2390 SoCamera *cam = This->getCamera();
2391 SoTimerSensor* s = (SoTimerSensor*) sensor;
2393 float t = float((curTime - s->getBaseTime()).getValue())
2394 / This->animateBtwPtsPeriod;
2396 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2398 SbBool end = (t == 1.0f);
2400 cam->orientation = SbRotation::slerp(This->camStartOrient, This->camEndOrient, t);
2401 cam->position = This->camStartPos + (This->camEndPos - This->camStartPos) * t;
2404 This->animateSensor->unschedule();
2406 if (This->currentState == ANIMATION) {
2407 if (This->refParticleIdx < (
int) (This->refParticleTrajectory.size() - 1))
2408 This->animateRefParticle();
2410 This->animateBtwPtsPeriod = MIN_SPEED;
2411 This->speedStep = START_STEP;
2414 if (This->currentState == REVERSED_ANIMATION) {
2415 if (This->refParticleIdx >= 1)
2416 This->animateRefParticle();
2418 This->animateBtwPtsPeriod = MIN_SPEED;
2419 This->speedStep = START_STEP;
2426void G4OpenInventorQtExaminerViewer::setStartingPtForAnimation()
2428 if (SoQtExaminerViewer::isAnimating())
2432 SbVec3f p1, p2, p2_tmp, camUpV, camD, camD_tmp, leftRightAxis;
2433 float x1, y1, z1, x2, y2, z2;
2435 if (currentState == ANIMATION) {
2436 p1 = refParticleTrajectory[refParticleIdx];
2437 p2 = refParticleTrajectory[++(refParticleIdx)];
2438 }
else if (currentState == REVERSED_ANIMATION) {
2439 p2 = refParticleTrajectory[refParticleIdx];
2440 p1 = refParticleTrajectory[--(refParticleIdx)];
2441 }
else if (currentState == PAUSED_ANIMATION) {
2442 if (refParticleIdx < (
int) refParticleTrajectory.size()) {
2443 p1 = refParticleTrajectory[refParticleIdx];
2444 p2 = refParticleTrajectory[refParticleIdx + 1];
2446 p1 = refParticleTrajectory[refParticleIdx - 1];
2447 p2 = refParticleTrajectory[refParticleIdx];
2450 p1.getValue(x1, y1, z1);
2451 p2.getValue(x2, y2, z2);
2456 p2_tmp.setValue(x2, y1, z2);
2457 camD_tmp = p2_tmp - p1;
2458 camD_tmp.normalize();
2460 camUpV.setValue(0, 1, 0);
2461 rot.setValue(camD_tmp, camD);
2462 rot.multVec(camUpV, camUpV);
2464 leftRightAxis = camD.cross(camUpV);
2466 myCam->position = p1;
2467 myCam->pointAt(p2, camUpV);
2470 p1 = p1 + (up_down * camUpV) + (left_right * leftRightAxis);
2471 myCam->position = p1;
2473 int idx = refParticleIdx + pathLookahead;
2474 idx = std::min(idx, (
int)refParticleTrajectory.size() - 1);
2475 myCam->pointAt(refParticleTrajectory[idx], camUpV);
2477 myCam->focalDistance = 0.1f;
2481void G4OpenInventorQtExaminerViewer::gotoRefPathStart()
2483 G4OpenInventorQtExaminerViewer::ToolsRefPathStartCB();
2487void G4OpenInventorQtExaminerViewer::ToolsRefPathStartCB()
2489 if (!refParticleTrajectory.size()) {
2491 msgbox.setFont(*font);
2492 QString messagetxt =
"No current reference path";
2493 msgbox.setText(messagetxt);
2498 if (currentState == ROTATING)
2500 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
2501 || currentState == PAUSED_ANIMATION) {
2502 if (animateSensor->isScheduled())
2503 animateSensor->unschedule();
2504 setSuperimpositionEnabled(superimposition,
FALSE);
2509 prevState = currentState;
2510 prevRefIdx = refParticleIdx;
2513 if (SoQtExaminerViewer::isAnimating())
2521 currentState = BEAMLINE;
2522 setSuperimpositionEnabled(superimposition,
TRUE);
2523 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2524 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
2525 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
2533 prevParticleDir = SbVec3f(0,0,0);
2536 SbVec3f p1 = refParticleTrajectory[0];
2537 SbVec3f pN = refParticleTrajectory[refParticleTrajectory.size() - 1];
2538 distance = (pN - p1).length() / 10;
2540 moveCamera(distance,
true);
2544void G4OpenInventorQtExaminerViewer::ToolsRefPathInvertCB()
2550void G4OpenInventorQtExaminerViewer::invertRefPath()
2552 std::reverse(refParticleTrajectory.begin(),
2553 refParticleTrajectory.end());
2554 setReferencePathZPos();
2559void G4OpenInventorQtExaminerViewer::animateRefParticle()
2561 SoCamera *cam = getCamera();
2563 camStartPos = cam->position.getValue();
2564 camStartOrient = cam->orientation.getValue();
2566 if (currentState != BEAMLINE)
2567 setStartingPtForAnimation();
2569 camEndPos = myCam->position.getValue();
2570 camEndOrient = myCam->orientation.getValue();
2572 if (animateSensor->isScheduled())
2573 animateSensor->unschedule();
2575 animateSensor->setBaseTime(SbTime::getTimeOfDay());
2576 animateSensor->setInterval(SbTime(0.02));
2578 animateSensor->schedule();
2582void G4OpenInventorQtExaminerViewer::addEscapeCallback(
void (*callback)())
2584 escapeCallback = callback;
2595void G4OpenInventorQtExaminerViewer::sceneChangeCB(
void*
userData, SoSensor*)
2601 G4OpenInventorQtExaminerViewer* This =
2602 (G4OpenInventorQtExaminerViewer*)
userData;
2603 if(This->newEvents) {
2604 This->findAndSetRefPath();
2605 This->newEvents =
false;
2614void G4OpenInventorQtExaminerViewer::addViewPoints()
2616 int size = viewPtList.size();
2619 for (
int i = 0; i < size; i++) {
2620 new QListWidgetItem(viewPtList[i].viewPtName,
2621 AuxWindowDialog->listWidget);
2629void G4OpenInventorQtExaminerViewer::parseString(T &t,
const std::string &s,
2632 std::istringstream str(s);
2633 if ((str >> t).fail())
2639G4OpenInventorQtExaminerViewer::FileOpenBookmarkCB()
2643 QFileDialog filedialog(getParentWidget(), tr(
"Open bookmark file"));
2644 filedialog.setFileMode(QFileDialog::ExistingFile);
2645 filedialog.setFont(*font);
2646 if (!filedialog.exec())
return;
2647 QStringList filenameinlist = filedialog.selectedFiles();
2648 QString filenamein = filenameinlist[0];
2657 char* filename =
new char[filenamein.size()+1];
2658 filename = strdup(qPrintable(filenamein));
2662 fileIn.open(filename);
2663 if (fileIn.fail()) {
2665 msgbox.setFont(*font);
2666 QString messagetxt =
"Error opening file: ";
2667 messagetxt.append(filenamein);
2668 msgbox.setText(messagetxt);
2675 cleanUpAfterPrevFile();
2677 if (!loadViewPts()) {
2679 msgbox.setFont(*font);
2680 QString messagetxt =
"Error reading bookmark file: ";
2681 messagetxt.append(filenamein);
2682 msgbox.setText(messagetxt);
2689 fileName = filename;
2690 fileOut.open(fileName.c_str(), std::ios::in);
2691 fileOut.seekp(0, std::ios::end);
2704void G4OpenInventorQtExaminerViewer::cleanUpAfterPrevFile()
2710 currentState = GENERAL;
2711 if (fileOut.is_open()) fileOut.close();
2713 AuxWindowDialog->listWidget->clear();
2714 AuxWindowDialog->lineEdit->setText(QString(
""));
2719G4OpenInventorQtExaminerViewer::FileNewBookmarkCB()
2722 QFileDialog filedialog(getParentWidget(), tr(
"Open new bookmark file"));
2723 filedialog.setFileMode(QFileDialog::AnyFile);
2725 filedialog.setAcceptMode(QFileDialog::AcceptSave);
2727 filedialog.setLabelText(QFileDialog::Accept, QString(
"New"));
2728 filedialog.setFont(*font);
2729 if (!filedialog.exec())
return;
2730 QStringList filenameinlist = filedialog.selectedFiles();
2731 QString filenamein = filenameinlist[0];
2735 char* filename =
new char[filenamein.size()+1];
2736 filename = strdup(qPrintable(filenamein));
2739 cleanUpAfterPrevFile();
2740 fileName = filename;
2741 fileOut.open(fileName.c_str());
2742 if (fileOut.fail()) {
2744 msgbox.setFont(*font);
2745 QString messagetxt =
"Error opening new bookmark file: ";
2746 messagetxt.append(filenamein);
2747 msgbox.setText(messagetxt);
2755G4OpenInventorQtExaminerViewer::ToolsAnimateRefParticleCB()
2758 if (!refParticleTrajectory.size()) {
2759 returnToAnim =
true;
2765 setSuperimpositionEnabled(superimposition,
TRUE);
2766 maxSpeed = SPEED_INDICATOR_STEP;
2767 axisSwitch->whichChild.setValue(SO_SWITCH_ALL);
2768 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
2769 animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
2773 SoCamera *cam = getCamera();
2776 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
2777 || currentState == ROTATING)
2780 if (currentState != PAUSED_ANIMATION) {
2783 prevState = currentState;
2784 prevRefIdx = refParticleIdx;
2786 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2792 animateBtwPtsPeriod = MIN_SPEED;
2793 speedStep = START_STEP;
2794 left_right = up_down = 0;
2796 cam->focalDistance = 0.1f;
2797 ((SoPerspectiveCamera *) cam)->heightAngle = 0.50f;
2800 currentState = ANIMATION;
2801 setStartingPtForAnimation();
2803 cam->position = (myCam)->
position.getValue();
2804 cam->orientation = (myCam)->orientation.getValue();
2805 animateRefParticle();
2810G4OpenInventorQtExaminerViewer::SaveViewPtCB()
2819 QInputDialog* inputdialog =
new QInputDialog(getParentWidget());
2820 inputdialog->setFont(*font);
2821 inputdialog->setWindowTitle(tr(
"Enter a name for the bookmark"));
2822 inputdialog->setLabelText(
"Bookmark name");
2824 inputdialog->adjustSize();
2826 if (inputdialog->exec() == QDialog::Accepted)
2827 namein=inputdialog->textValue().trimmed();
2830 if (namein.isEmpty())
return;
2839 const int nVPName = MAX_VP_NAME + 1;
2840 char*
name =
new char[nVPName];
2842 namein.truncate(MAX_VP_NAME);
2844 QByteArray ba = namein.toLocal8Bit();
2845 name = strdup(ba.constData());
2852 for (
int i = 0; i < (int)viewPtList.size(); i++) {
2853 if (!strcmp(name, viewPtList[i].viewPtName)) {
2855 msgbox.setText(
"Bookmark name is already in use");
2861 if (viewPtIdx == -1) viewPtIdx = 0;
2864 saveViewPtItem =
new QListWidgetItem(namein,
2865 AuxWindowDialog->listWidget);
2866 AuxWindowDialog->listWidget->setCurrentItem(saveViewPtItem);
2867 AuxWindowDialog->lineEdit->setText(namein);
2873void G4OpenInventorQtExaminerViewer::saveViewPt(
char *name)
2877 float x, y, z, angle;
2878 SoCamera* camera = getCamera();
2887 if (viewPtList.size() == 0) {
2891 tmp.viewPtName =
name;
2892 tmp.viewportMapping = camera->viewportMapping.getValue();
2893 tmp.position = camera->position.getValue();
2894 tmp.orientation = camera->orientation.getValue();
2895 tmp.aspectRatio = camera->aspectRatio.getValue();
2896 tmp.nearDistance = camera->nearDistance.getValue();
2897 tmp.farDistance = camera->farDistance.getValue();
2898 tmp.focalDistance = camera->focalDistance.getValue();
2901 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2902 tmp.height = ((SoPerspectiveCamera *) camera)->heightAngle.getValue();
2903 tmp.camType = PERSPECTIVE;
2904 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
2905 tmp.height = ((SoOrthographicCamera *) camera)->height.getValue();
2906 tmp.camType = ORTHOGRAPHIC;
2908 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::saveViewPtCB",
2909 "Only Perspective and Orthographic cameras are supported.");
2913 viewPtList.push_back(tmp);
2919 std::string vpName =
name;
2921 while ((
int) vpName.size() <= MAX_VP_NAME)
2924 fileOut << vpName << std::endl;
2925 tmp.position.getValue(x, y, z);
2926 fileOut << x <<
" " << y <<
" " << z << std::endl;
2929 tmp.orientation.getValue(axis, angle);
2930 axis.getValue(x, y, z);
2931 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
2933 fileOut << tmp.camType <<
" " << tmp.height << std::endl;
2934 fileOut << tmp.focalDistance <<
" ";
2935 fileOut << tmp.nearDistance <<
" ";
2936 fileOut << tmp.farDistance << std::endl;
2937 fileOut << tmp.viewportMapping <<
" ";
2938 fileOut << tmp.aspectRatio <<
"\n" << std::endl;
2951void G4OpenInventorQtExaminerViewer::writeViewPtIdx()
2954 std::stringstream out;
2958 fileOut.seekp(0, std::ios::beg);
2960 while ((
int) idxStr.length() < MAX_VP_IDX) {
2966 fileOut << idxStr <<
"\n";
2968 fileOut.seekp(0, std::ios::end);
2974void G4OpenInventorQtExaminerViewer::LoadBookmarkCB(QListWidgetItem* item)
2979 const int nVPName = MAX_VP_NAME + 1;
2980 char* vpName =
new char[nVPName];
2982 vpName = strdup(qPrintable(item->text()));
2985 for (
int i = 0; i < (int)viewPtList.size(); i++) {
2986 if (!strcmp(viewPtList[i].viewPtName, vpName)) {
2995 AuxWindowDialog->lineEdit->setText(item->text());
3001void G4OpenInventorQtExaminerViewer::setViewPt()
3003 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
3004 || currentState == ROTATING) {
3005 if (animateSensor->isScheduled()) animateSensor->unschedule();
3006 setSuperimpositionEnabled(superimposition,
FALSE);
3011 SoCamera * camera = getCamera();
3012 if (camera == NULL) {
3013 G4cout <<
"setViewPt: Camera is null. Unable to set the viewpoint." <<
3021 if (!viewPtList.size()) {
3022 G4cout <<
"setViewPt: There are no viewpoints to load." <<
G4endl;
3029 if (SoQtExaminerViewer::isAnimating()) stopAnimating();
3031 if (currentState != VIEWPOINT) {
3032 currentState = VIEWPOINT;
3034 setSuperimpositionEnabled(superimposition,
TRUE);
3035 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
3036 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
3037 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
3042 curViewPtName = viewPtList[viewPtIdx].viewPtName;
3043 camera->viewportMapping = viewPtList[viewPtIdx].viewportMapping;
3044 camera->position = viewPtList[viewPtIdx].position;
3045 camera->orientation = viewPtList[viewPtIdx].orientation;
3046 camera->aspectRatio = viewPtList[viewPtIdx].aspectRatio;
3047 camera->nearDistance = viewPtList[viewPtIdx].nearDistance;
3048 camera->farDistance = viewPtList[viewPtIdx].farDistance;
3049 camera->focalDistance = viewPtList[viewPtIdx].focalDistance;
3052 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3053 if (viewPtList[viewPtIdx].camType == ORTHOGRAPHIC) {
3055 camera = getCamera();
3056 ((SoOrthographicCamera *) camera)->height.setValue(
3057 viewPtList[viewPtIdx].height);
3059 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3060 viewPtList[viewPtIdx].height);
3061 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3062 if (viewPtList[viewPtIdx].camType == PERSPECTIVE) {
3064 camera = getCamera();
3065 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3066 viewPtList[viewPtIdx].height);
3068 ((SoOrthographicCamera *) camera)->height.setValue(
3069 viewPtList[viewPtIdx].height);
3071 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::setViewPt",
3072 "Only Perspective and Orthographic cameras are supported.");
3079void G4OpenInventorQtExaminerViewer::NextViewPtCB()
3084 if (!viewPtList.size())
return;
3085 if (viewPtIdx >= (
int)viewPtList.size() - 1)
3092 char* viewptname = viewPtList[viewPtIdx].viewPtName;
3093 AuxWindowDialog->lineEdit->setText(QString(viewptname));
3096void G4OpenInventorQtExaminerViewer::PrevViewPtCB()
3101 if (!viewPtList.size())
return;
3103 viewPtIdx = viewPtList.size() - 1;
3109 char* viewptname = viewPtList[viewPtIdx].viewPtName;
3110 AuxWindowDialog->lineEdit->setText(QString(viewptname));
3114void G4OpenInventorQtExaminerViewer::AbbrOutputCB(
bool checked)
3119 abbrOutputFlag = checked;
3123void G4OpenInventorQtExaminerViewer::PickRefPathCB()
3129 viewingBeforePickRef = isViewing();
3132 setComponentCursor(SoQtCursor(SoQtCursor::CROSSHAIR));
3133 pickRefPathFlag =
true;
3137void G4OpenInventorQtExaminerViewer::SwitchWireFrameCB(
bool checked)
3144 setDrawStyle(SoQtViewer::STILL, SoQtViewer::VIEW_LINE);
3145 setDrawStyle(SoQtViewer::INTERACTIVE, SoQtViewer::VIEW_LINE);
3147 setDrawStyle(SoQtViewer::STILL, SoQtViewer::VIEW_AS_IS);
3148 setDrawStyle(SoQtViewer::INTERACTIVE,
3149 SoQtViewer::VIEW_SAME_AS_STILL);
3154void G4OpenInventorQtExaminerViewer::DeleteBookmarkCB()
3160 QListWidgetItem* listitem = AuxWindowDialog->listWidget->currentItem();
3161 if (!listitem)
return;
3162 if (!(listitem->isSelected()))
return;
3164 QString vpnamein = listitem->text();
3166 const int nVPName = MAX_VP_NAME + 1;
3167 char* vpName =
new char[nVPName];
3168 vpName = strdup(qPrintable(vpnamein));
3171 deleteViewPt(vpName);
3178void G4OpenInventorQtExaminerViewer::deleteViewPt(
char *vpName)
3182 fileIn.open(fileName.c_str());
3183 std::ofstream out(
"temporaryFile.txt");
3186 vpName = viewPtList[viewPtIdx].viewPtName;
3188 getline(fileIn, line);
3189 out << line <<
"\n";
3191 while (getline(fileIn, line)) {
3192 end = line.find_last_not_of(
' ');
3193 line = line.substr(0, end + 1);
3194 if (!strcmp(line.c_str(), vpName)) {
3195 while (line.size()) {
3196 getline(fileIn, line);
3199 while (getline(fileIn, line))
3200 out << line <<
"\n";
3202 while (line.size()) {
3203 out << line <<
"\n";
3204 getline(fileIn, line);
3211 int size = viewPtList.size();
3212 while (idx < size) {
3213 if (!strcmp(viewPtList[idx].viewPtName, vpName)) {
3214 viewPtList.erase(viewPtList.begin() + idx);
3226 int istat = remove(fileName.c_str());
3229 msgbox.setFont(*font);
3230 QString messagetxt =
"Error removing bookmarks file";
3232 msgbox.setText(messagetxt);
3236 istat = rename(
"temporaryFile.txt", fileName.c_str());
3239 msgbox.setFont(*font);
3240 QString messagetxt =
"Error renaming bookmarks file";
3242 msgbox.setText(messagetxt);
3246 fileOut.open(fileName.c_str(), std::ios::in);
3247 fileOut.seekp(0, std::ios::end);
3249 if (!viewPtList.size()) {
3250 curViewPtName = (
char *)
"";
3253 if (viewPtIdx >= (
int) viewPtList.size())
3261void G4OpenInventorQtExaminerViewer::RenameBookmarkCB()
3266 QListWidgetItem* listitem = AuxWindowDialog->listWidget->currentItem();
3267 if (!listitem)
return;
3268 if (!(listitem->isSelected()))
return;
3270 QString vpnamein = listitem->text();
3272 const int nVPName = MAX_VP_NAME + 1;
3277 QInputDialog* inputdialog =
new QInputDialog(getParentWidget());
3278 inputdialog->setFont(*font);
3279 inputdialog->setWindowTitle(tr(
"Enter"));
3280 inputdialog->setLabelText(
"New bookmark name");
3281 inputdialog->adjustSize();
3283 if (inputdialog->exec() == QDialog::Accepted)
3284 newnamein=inputdialog->textValue().trimmed();
3287 if (newnamein.isEmpty())
return;
3289 char* newname =
new char[nVPName];
3290 newname = strdup(qPrintable(newnamein));
3292 int size = viewPtList.size();
3293 for (
int i = 0; i < size; i++) {
3294 if (!strcmp(newname, viewPtList[i].viewPtName)) {
3296 msgbox.setFont(*font);
3297 msgbox.setText(
"Bookmark name is already in use");
3303 renameViewPt(newname);
3304 listitem->setText(QString(newname));
3305 AuxWindowDialog->lineEdit->setText(newname);
3314void G4OpenInventorQtExaminerViewer::renameViewPt(
char *vpName)
3316 int idx = 0, end,
pos;
3317 int size = viewPtList.size();
3318 std::string line, newName;
3319 fileIn.open(fileName.c_str());
3322 while ((
int) newName.size() < MAX_VP_NAME)
3325 getline(fileIn, line);
3326 pos = fileIn.tellg();
3327 while (getline(fileIn, line)) {
3328 end = line.find_last_not_of(
' ');
3329 line = line.substr(0, end + 1);
3330 if (!strcmp(line.c_str(), curViewPtName)) {
3333 fileOut.seekp(0, std::ios::end);
3337 getline(fileIn, line);
3338 pos = fileIn.tellg();
3344 while (idx < size) {
3345 if (!strcmp(viewPtList[idx].viewPtName, curViewPtName)) {
3346 strcpy(viewPtList[idx].viewPtName, vpName);
3354void G4OpenInventorQtExaminerViewer::SortBookmarksCB()
3364 std::vector<std::string> charList;
3366 if (viewPtList.size() < 2)
return;
3370 for (
int i = 0; i < (int)viewPtList.size(); i++) {
3372 charList.push_back(viewPtList[i].viewPtName);
3376 std::sort(charList.begin(), charList.end());
3380 AuxWindowDialog->listWidget->clear();
3382 for (
int i = 0; i < (int)viewPtList.size(); i++) {
3384 if (!strcmp(charList[i].c_str(), curViewPtName))
3386 new QListWidgetItem(charList[i].c_str(), AuxWindowDialog->listWidget);
3390 sortViewPts(charList);
3396void G4OpenInventorQtExaminerViewer::sortViewPts(std::vector<std::string> sortedViewPts)
3399 float x, y, z, angle;
3400 int sortIdx = 0, unsortIdx = 0;
3402 if (fileOut.is_open())
3405 fileOut.open(fileName.c_str());
3409 int size = sortedViewPts.size();
3410 while (sortIdx < size) {
3411 while (strcmp(sortedViewPts[sortIdx].c_str(),
3412 viewPtList[unsortIdx].viewPtName))
3415 std::string vpName = viewPtList[unsortIdx].viewPtName;
3417 while ((
int) vpName.size() < MAX_VP_NAME)
3419 fileOut << vpName << std::endl;
3420 viewPtList[unsortIdx].position.getValue(x, y, z);
3421 fileOut << x <<
" " << y <<
" " << z << std::endl;
3424 viewPtList[unsortIdx].orientation.getValue(axis, angle);
3425 axis.getValue(x, y, z);
3426 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3428 fileOut << viewPtList[unsortIdx].camType <<
" "
3429 << viewPtList[unsortIdx].height << std::endl;
3430 fileOut << viewPtList[unsortIdx].focalDistance <<
" ";
3432 fileOut << viewPtList[unsortIdx].nearDistance <<
" ";
3434 fileOut << viewPtList[unsortIdx].farDistance << std::endl;
3436 fileOut << viewPtList[unsortIdx].viewportMapping <<
" ";
3437 fileOut << viewPtList[unsortIdx].aspectRatio <<
"\n" << std::endl;
3449G4OpenInventorQtExaminerViewer::processSoEvent(
const SoEvent*
const ev)
3452 SoCamera *cam = getCamera();
3453 const SoType type(ev->getTypeId());
3455 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
3456 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
3458 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
3459 || currentState == PAUSED_ANIMATION) {
3460 switch (me->getButton()) {
3461 case SoMouseButtonEvent::BUTTON4:
3462 if (me->getState() == SoButtonEvent::DOWN) {
3463 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3465 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
3466 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
3469 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
3471 ((SoOrthographicCamera *) cam)->height.getValue();
3472 ((SoOrthographicCamera *) cam)->height = height + 5;
3477 case SoMouseButtonEvent::BUTTON5:
3478 if (me->getState() == SoButtonEvent::DOWN) {
3479 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3481 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
3483 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
3486 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
3488 ((SoOrthographicCamera *) cam)->height.getValue();
3490 ((SoOrthographicCamera *) cam)->height = height - 5;
3499 if (currentState == GENERAL) {
3505 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
3506 SoKeyboardEvent* ke = (SoKeyboardEvent*)ev;
3508 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
3509 switch (ke->getKey()) {
3510 case SoKeyboardEvent::E:
3511 if (externalQtApp) {
3516 "E KEY PRESSED, EXITING OIQT VIEWER SECONDARY LOOP" <<
3518 SoQt::exitMainLoop();
3522 case SoKeyboardEvent::LEFT_SHIFT:
3523 this->lshiftdown =
true;
3525 case SoKeyboardEvent::RIGHT_SHIFT:
3526 this->rshiftdown =
true;
3528 case SoKeyboardEvent::LEFT_CONTROL:
3529 this->lctrldown =
true;
3531 case SoKeyboardEvent::RIGHT_CONTROL:
3532 this->rctrldown =
true;
3534 case SoKeyboardEvent::SPACE:
3535 if (currentState == ANIMATION
3536 || currentState == REVERSED_ANIMATION) {
3537 beforePausing = currentState;
3538 currentState = PAUSED_ANIMATION;
3539 if (animateSensor->isScheduled())
3540 animateSensor->unschedule();
3542 }
else if (currentState == PAUSED_ANIMATION) {
3544 if ((beforePausing == ANIMATION
3546 < (
int) refParticleTrajectory.size() - 1)
3547 || (beforePausing == REVERSED_ANIMATION
3548 && refParticleIdx > 0)) {
3549 currentState = beforePausing;
3550 animateRefParticle();
3556 case SoKeyboardEvent::ESCAPE:
3557 if (currentState == ANIMATION
3558 || currentState == REVERSED_ANIMATION
3559 || currentState == PAUSED_ANIMATION) {
3561 if (animateSensor->isScheduled())
3562 animateSensor->unschedule();
3563 currentState = prevState;
3564 refParticleIdx = prevRefIdx;
3565 setSuperimpositionEnabled(superimposition,
FALSE);
3570 if (currentState == VIEWPOINT) {
3571 setSuperimpositionEnabled(superimposition,
TRUE);
3572 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
3573 animSpeedOutlineSwitch->whichChild.setValue(
3575 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
3583 case SoKeyboardEvent::DELETE:
3584 if (viewPtList.size()
3585 && (currentState != ANIMATION
3586 && currentState != REVERSED_ANIMATION
3587 && currentState != PAUSED_ANIMATION)) {
3595 case SoKeyboardEvent::LEFT_ARROW:
3596 switch (currentState) {
3598 if ((this->lshiftdown) || (this->rshiftdown)) {
3599 refParticleIdx -= step;
3602 else if ((this->lctrldown) || (this->rctrldown)) {
3603 if (SoQtExaminerViewer::isAnimating())
3605 prevState = currentState;
3606 currentState = ROTATING;
3607 animateBtwPtsPeriod = 0.08f;
3609 SbVec3f tmp = camDir;
3618 if (SoQtExaminerViewer::isAnimating())
3620 prevState = currentState;
3621 currentState = ROTATING;
3622 animateBtwPtsPeriod = 0.08f;
3624 SbVec3f tmp = camUpVec;
3636 case REVERSED_ANIMATION:
3639 case PAUSED_ANIMATION:
3641 setStartingPtForAnimation();
3642 cam->position = myCam->position;
3646 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3649 this->bottomWheelMotion(
3650 this->getBottomWheelValue() + 0.1f);
3660 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3661 "Unhandled viewer state");
3666 case SoKeyboardEvent::RIGHT_ARROW:
3667 switch(currentState) {
3669 if ((this->lshiftdown) || (this->rshiftdown)) {
3670 refParticleIdx += step;
3673 else if ((this->lctrldown) || (this->rctrldown)) {
3674 if (SoQtExaminerViewer::isAnimating())
3676 prevState = currentState;
3677 currentState = ROTATING;
3678 animateBtwPtsPeriod = 0.08f;
3687 if (SoQtExaminerViewer::isAnimating())
3689 prevState = currentState;
3690 currentState = ROTATING;
3691 animateBtwPtsPeriod = 0.08f;
3702 case REVERSED_ANIMATION:
3705 case PAUSED_ANIMATION:
3707 setStartingPtForAnimation();
3708 cam->position = myCam->position;
3712 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3715 this->bottomWheelMotion(
3716 this->getBottomWheelValue() - 0.1f);
3725 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3726 "Unhandled viewer state");
3731 case SoKeyboardEvent::DOWN_ARROW:
3732 switch(currentState) {
3735 if ((this->lshiftdown) || (this->rshiftdown)) {
3736 refParticleIdx -= step;
3740 if (SoQtExaminerViewer::isAnimating())
3742 prevState = currentState;
3743 currentState = ROTATING;
3744 animateBtwPtsPeriod = 0.08f;
3746 rotAxis = camDir.cross(camUpVec);
3756 case REVERSED_ANIMATION:
3759 case PAUSED_ANIMATION:
3761 setStartingPtForAnimation();
3762 cam->position = myCam->position;
3768 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3769 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
3778 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3779 "Unhandled viewer state");
3784 case SoKeyboardEvent::UP_ARROW:
3785 switch(currentState) {
3787 if ((this->lshiftdown) || (this->rshiftdown)) {
3788 refParticleIdx -= step;
3792 if (SoQtExaminerViewer::isAnimating())
3794 prevState = currentState;
3795 currentState = ROTATING;
3796 animateBtwPtsPeriod = 0.08f;
3798 rotAxis = camUpVec.cross(camDir);
3809 case REVERSED_ANIMATION:
3812 case PAUSED_ANIMATION:
3814 setStartingPtForAnimation();
3815 cam->position = myCam->position;
3821 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3822 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
3831 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3832 "Unhandled viewer state");
3837 case SoKeyboardEvent::PAGE_UP:
3838 switch(currentState) {
3840 if (step < (
int) refParticleTrajectory.size() / 5)
3845 maxSpeed += SPEED_INDICATOR_STEP;
3847 maxSpeed = MAX_SPEED_INDICATOR;
3851 case REVERSED_ANIMATION:
3852 if(!animateSensor->isScheduled()) {
3853 currentState = ANIMATION;
3855 < (
int) refParticleTrajectory.size() - 1) {
3857 maxSpeed = SPEED_INDICATOR_STEP;
3859 animateRefParticle();
3863 maxSpeed += SPEED_INDICATOR_STEP;
3868 case PAUSED_ANIMATION:
3869 maxSpeed += SPEED_INDICATOR_STEP;
3871 maxSpeed = MAX_SPEED_INDICATOR;
3873 if (beforePausing == ANIMATION) {
3877 if (animateBtwPtsPeriod >= MIN_SPEED)
3878 beforePausing = ANIMATION;
3888 case SoKeyboardEvent::PAGE_DOWN:
3889 switch(currentState) {
3895 if(!animateSensor->isScheduled()) {
3896 currentState = REVERSED_ANIMATION;
3897 if (refParticleIdx > 1) {
3899 maxSpeed = -SPEED_INDICATOR_STEP;
3901 animateRefParticle();
3905 maxSpeed -= SPEED_INDICATOR_STEP;
3910 case REVERSED_ANIMATION:
3912 maxSpeed -= SPEED_INDICATOR_STEP;
3913 if (maxSpeed < -0.8)
3914 maxSpeed = -MAX_SPEED_INDICATOR;
3917 case PAUSED_ANIMATION:
3918 maxSpeed -= SPEED_INDICATOR_STEP;
3919 if (maxSpeed < -0.8)
3920 maxSpeed = -MAX_SPEED_INDICATOR;
3921 if (beforePausing == REVERSED_ANIMATION) {
3925 if (animateBtwPtsPeriod >= MIN_SPEED)
3926 beforePausing = REVERSED_ANIMATION;
3945 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
3946 switch (ke->getKey()) {
3947 case SoKeyboardEvent::LEFT_SHIFT:
3948 this->lshiftdown =
false;
3950 case SoKeyboardEvent::RIGHT_SHIFT:
3951 this->rshiftdown =
false;
3953 case SoKeyboardEvent::LEFT_CONTROL:
3954 this->lctrldown =
false;
3956 case SoKeyboardEvent::RIGHT_CONTROL:
3957 this->rctrldown =
false;
3968 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
3969 || currentState == ROTATING)
3972 return SoQtExaminerViewer::processSoEvent(ev);
3979void G4OpenInventorQtExaminerViewer::FileLoadSceneGraphCB()
3983 QFileDialog filedialog(getParentWidget(), tr(
"Load Scene Graph"));
3984 filedialog.setFileMode(QFileDialog::AnyFile);
3985 filedialog.setFont(*font);
3986 if (!filedialog.exec())
return;
3987 QStringList filenameinlist = filedialog.selectedFiles();
3988 QString filenamein = filenameinlist[0];
3992 char* filename =
new char[filenamein.size()+1];
3993 filename = strdup(qPrintable(filenamein));
3998 if (sceneInput.openFile(filename)) {
4000 newSceneGraph = SoDB::readAll(&sceneInput);
4001 if (newSceneGraph == NULL) {
4003 msgbox.setFont(*font);
4004 QString messagetxt =
"Error reading scene graph file ";
4005 messagetxt.append(filenamein);
4006 msgbox.setText(messagetxt);
4008 sceneInput.closeFile();
4013 msgbox.setFont(*font);
4014 QString messagetxt =
"Error opening scene graph file ";
4015 messagetxt.append(filenamein);
4016 msgbox.setText(messagetxt);
4021 SoSeparator* root = (SoSeparator*)getSceneGraph();
4023 newSceneGraph->ref();
4024 setSceneGraph(newSceneGraph);
4027void G4OpenInventorQtExaminerViewer::FileSaveSceneGraphCB()
4031 QFileDialog filedialog(getParentWidget(), tr(
"Save scene graph"));
4032 filedialog.setFileMode(QFileDialog::AnyFile);
4034 filedialog.setAcceptMode(QFileDialog::AcceptSave);
4035 filedialog.setFont(*font);
4036 if (!filedialog.exec())
return;
4037 QStringList filenameinlist = filedialog.selectedFiles();
4038 QString filenamein = filenameinlist[0];
4042 char* filename =
new char[filenamein.size()+1];
4043 filename = strdup(qPrintable(filenamein));
4046 SoWriteAction writeAction;
4047 SoSeparator* root = (SoSeparator*)getSceneGraph();
4049 SoOutput* out = writeAction.getOutput();
4051 if (out->openFile(filename)) {
4052 out->setBinary(
FALSE);
4053 writeAction.apply(root);
4057 msgbox.setFont(*font);
4058 QString messagetxt =
"Error opening file ";
4059 messagetxt.append(filenamein);
4060 msgbox.setText(messagetxt);
4066void G4OpenInventorQtExaminerViewer::HelpControlsCB()
G4GLOB_DLL std::ostream G4cout
const std::vector< const std::vector< G4AttValue > * > & GetAttValues() const
const std::vector< const std::map< G4String, G4AttDef > * > & GetAttDefs() const
virtual G4bool Notify(G4ApplicationState requiredState)
HookEventProcState(G4OpenInventorXtExaminerViewer *)
const char * name(G4int ptype)