44#include <Inventor/Qt/SoQt.h>
45#include <Inventor/Qt/SoQtCursor.h>
46#include <Inventor/events/SoKeyboardEvent.h>
47#include <Inventor/events/SoMouseButtonEvent.h>
48#include <Inventor/events/SoLocation2Event.h>
49#include <Inventor/nodes/SoSeparator.h>
50#include <Inventor/nodes/SoOrthographicCamera.h>
51#include <Inventor/nodes/SoPerspectiveCamera.h>
55#include <Inventor/nodes/SoLineSet.h>
56#include <Inventor/nodes/SoMaterial.h>
57#include <Inventor/errors/SoDebugError.h>
58#include <Inventor/SoPickedPoint.h>
59#include <Inventor/actions/SoWriteAction.h>
60#include <Inventor/projectors/SbPlaneProjector.h>
62#include <Inventor/sensors/SoTimerSensor.h>
63#include <Inventor/sensors/SoNodeSensor.h>
70#include <Inventor/nodes/SoCallback.h>
71#include <Inventor/nodes/SoSwitch.h>
72#include <Inventor/nodes/SoScale.h>
73#include <Inventor/nodes/SoTranslation.h>
74#include <Inventor/actions/SoSearchAction.h>
75#include <Inventor/actions/SoGetBoundingBoxAction.h>
77#include <Inventor/nodes/SoCoordinate3.h>
79#include <Inventor/nodes/SoText2.h>
80#include <Inventor/nodes/SoFont.h>
81#include <Inventor/nodes/SoPointSet.h>
82#include <Inventor/nodes/SoDrawStyle.h>
83#include <Inventor/nodes/SoBaseColor.h>
86#include <Inventor/nodekits/SoBaseKit.h>
90#include <QRadioButton>
93#include <QListWidgetItem>
94#include <QInputDialog>
98#include <QCommonStyle>
102#include "moc_G4OpenInventorQtExaminerViewer.cpp"
110#define START_STEP 0.3
111#define SPEED_INDICATOR_STEP 0.045
112#define MAX_SPEED_INDICATOR 0.81
120 SoQtFullViewer::BuildFlag flag,
121 SoQtViewer::Type type)
122 : SoQtExaminerViewer(parent, name, embed, flag, type),
123 externalQtApp(0), processSoEventCount(0)
132 fName =
new QString(name);
173 myCam =
new SoPerspectiveCamera;
183 lshiftdown = rshiftdown =
false;
186 lctrldown = rctrldown =
false;
204 static const char * superimposed[] = {
205 "#Inventor V2.1 ascii",
"",
212 " OrthographicCamera ",
218 " DEF soxt->callback Callback { }",
221 " DEF soxt->translation Translation ",
223 " translation 0 0 0",
225 " DEF soxt->scale Scale ",
227 " scaleFactor 1 1 1",
229 " DEF soxt->geometry Coordinate3 ",
233 " -0.81 -0.04 0, -0.81 0 0,",
234 " -0.81 0.04 0, 0 -0.04 0,",
236 " 0.81 -0.04 0, 0.81 0 0,",
239 " 0.81 0.02 0, 0.81 -0.02 0,",
242 " 0.4 0.01 0, 0.4 -0.01 0,",
247 " DEF soxt->animSpeedOutlineSwitch Switch ",
252 " emissiveColor 0 0 0",
258 " 12, 11, 10, 9, -1",
263 " DEF soxt->axisSwitch Switch ",
282 " DEF soxt->animSpeedSwitch Switch ",
287 " emissiveColor 0 1 0",
293 " 16, 15, 14, 13, -1",
299 " DEF soxt->curInfoSwitch Switch ",
302 " DEF soxt->curInfoTrans Translation ",
304 " translation 0 0 0 ",
307 " DEF soxt->curInfoFont Font ",
309 " name defaultFont:Bold",
312 " DEF soxt->curInfoText Text2 ",
321 " DEF soxt->mouseOverTransLogName Translation ",
323 " translation 0 0 0 ",
325 " DEF soxt->mouseOverFontLogName Font ",
327 " name defaultFont:Bold",
330 " DEF soxt->mouseOverTextLogName Text2 { } ",
334 " DEF soxt->mouseOverTransSolid Translation ",
336 " translation 0 0 0 ",
338 " DEF soxt->mouseOverFontSolid Font ",
340 " name defaultFont:Bold",
343 " DEF soxt->mouseOverTextSolid Text2 { } ",
347 " DEF soxt->mouseOverTransMaterial Translation ",
349 " translation 0 0 0 ",
351 " DEF soxt->mouseOverFontMaterial Font ",
353 " name defaultFont:Bold",
356 " DEF soxt->mouseOverTextMaterial Text2 { } ",
360 " DEF soxt->mouseOverTransZPos Translation ",
362 " translation 0 0 0 ",
364 " DEF soxt->mouseOverFontZPos Font ",
366 " name defaultFont:Bold",
369 " DEF soxt->mouseOverTextZPos Text2 { } ",
375 for (i = bufsize = 0; superimposed[i]; i++)
376 bufsize += strlen(superimposed[i]) + 1;
377 char * buf =
new char[bufsize + 1];
378 for (i = bufsize = 0; superimposed[i]; i++) {
379 strcpy(buf + bufsize, superimposed[i]);
380 bufsize += strlen(superimposed[i]);
384 SoInput * input =
new SoInput;
385 input->setBuffer(buf, bufsize);
421 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
434 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::buildWidget",
435 "Error: Parent is null.");
439 font->setPointSize(12);
441 parent->setFont(*font);
447 menubar =
new QMenuBar(getRenderAreaWidget());
452 filemenu =
new QMenu(
"File");
453 menubar->addMenu(filemenu);
455 FileOpenBookmark =
new QAction(
"Open Bookmark File",
this);
456 FileOpenBookmark->setFont(*font);
457 connect(FileOpenBookmark, SIGNAL(triggered()),
this,
458 SLOT(FileOpenBookmarkCB()));
459 filemenu->addAction(FileOpenBookmark);
461 FileNewBookmark =
new QAction(
"New Bookmark File",
this);
462 FileNewBookmark->setFont(*font);
463 connect(FileNewBookmark, SIGNAL(triggered()),
this,
464 SLOT(FileNewBookmarkCB()));
465 filemenu->addAction(FileNewBookmark);
467 FileLoadRefPath =
new QAction(
"Load Reference Path",
this);
468 FileLoadRefPath->setFont(*font);
469 connect(FileLoadRefPath, SIGNAL(triggered()),
this,
470 SLOT(FileLoadRefPathCB()));
471 filemenu->addAction(FileLoadRefPath);
473 FileSaveRefPath =
new QAction(
"Save Reference Path",
this);
474 FileSaveRefPath->setFont(*font);
475 connect(FileSaveRefPath, SIGNAL(triggered()),
this,
476 SLOT(FileSaveRefPathCB()));
477 filemenu->addAction(FileSaveRefPath);
479 FileLoadSceneGraph =
new QAction(
"Load scene graph",
this);
480 FileLoadSceneGraph->setFont(*font);
481 connect(FileLoadSceneGraph, SIGNAL(triggered()),
this,
482 SLOT(FileLoadSceneGraphCB()));
483 filemenu->addAction(FileLoadSceneGraph);
485 FileSaveSceneGraph =
new QAction(
"Save scene graph",
this);
486 FileSaveSceneGraph->setFont(*font);
487 connect(FileSaveSceneGraph, SIGNAL(triggered()),
this,
488 SLOT(FileSaveSceneGraphCB()));
489 filemenu->addAction(FileSaveSceneGraph);
493 toolsmenu =
new QMenu(
"Tools");
494 menubar->addMenu(toolsmenu);
496 ToolsAnimateRefParticle =
new QAction(
"Fly on Ref Path",
this);
497 ToolsAnimateRefParticle->setFont(*font);
498 connect(ToolsAnimateRefParticle, SIGNAL(triggered()),
this,
499 SLOT(ToolsAnimateRefParticleCB()));
500 toolsmenu->addAction(ToolsAnimateRefParticle);
502 ToolsRefPathStart =
new QAction(
"Go to start of Ref Path",
this);
503 ToolsRefPathStart->setFont(*font);
504 connect(ToolsRefPathStart, SIGNAL(triggered()),
this,
505 SLOT(ToolsRefPathStartCB()));
506 toolsmenu->addAction(ToolsRefPathStart);
508 ToolsRefPathInvert =
new QAction(
"Invert Ref Path",
this);
509 ToolsRefPathInvert->setFont(*font);
510 connect(ToolsRefPathInvert, SIGNAL(triggered()),
this,
511 SLOT(ToolsRefPathInvertCB()));
512 toolsmenu->addAction(ToolsRefPathInvert);
514 etcmenu =
new QMenu(
"Etc");
515 menubar->addMenu(etcmenu);
519 helpmenu =
new QMenu(
"Help");
520 menubar->addMenu(helpmenu);
522 HelpControls =
new QAction(
"Controls",
this);
523 HelpControls->setFont(*font);
524 connect(HelpControls, SIGNAL(triggered()),
this, SLOT(HelpControlsCB()));
525 helpmenu->addAction(HelpControls);
534 saveViewPtButton =
new QPushButton;
535 saveViewPtButton->setIcon(QPixmap((
const char **)saveViewPt_xpm));
536 saveViewPtButton->setIconSize(QSize(24,24));
537 saveViewPtButton->setToolTip(
"Bookmark this view");
538 connect(saveViewPtButton, SIGNAL(clicked()),
this,
539 SLOT(SaveViewPtCB()));
540 addAppPushButton(saveViewPtButton);
542 nextViewPtButton =
new QPushButton;
543 nextViewPtButton->setIconSize(QSize(24,24));
545 nextViewPtButton->setIcon(style.standardIcon(QStyle::SP_ArrowRight));
546 nextViewPtButton->setToolTip(
"Next bookmark");
547 connect(nextViewPtButton, SIGNAL(clicked()),
this,
548 SLOT(NextViewPtCB()));
549 addAppPushButton(nextViewPtButton);
551 prevViewPtButton =
new QPushButton;
552 prevViewPtButton->setIconSize(QSize(24,24));
553 prevViewPtButton->setIcon(style.standardIcon(QStyle::SP_ArrowLeft));
554 prevViewPtButton->setToolTip(
"Previous bookmark");
555 connect(prevViewPtButton, SIGNAL(clicked()),
this,
556 SLOT(PrevViewPtCB()));
557 addAppPushButton(prevViewPtButton);
559 abbrOutputButton =
new QPushButton;
560 abbrOutputButton->setCheckable(
true);
561 abbrOutputButton->setIconSize(QSize(24,24));
562 abbrOutputButton->setIcon(QPixmap((
const char **)pickext_xpm));
563 abbrOutputButton->setToolTip(
"Extended picking & readout");
564 connect(abbrOutputButton, SIGNAL(toggled(
bool)),
this,
565 SLOT(AbbrOutputCB(
bool)));
566 addAppPushButton(abbrOutputButton);
568 pickRefPathButton =
new QPushButton;
569 pickRefPathButton->setIconSize(QSize(24,24));
570 pickRefPathButton->setIcon(QPixmap((
const char **)pickref_xpm));
571 pickRefPathButton->setToolTip(
"Pick ref trajectory");
572 connect(pickRefPathButton, SIGNAL(clicked()),
this,
573 SLOT(PickRefPathCB()));
574 addAppPushButton(pickRefPathButton);
576 switchWireFrameButton =
new QPushButton;
577 switchWireFrameButton->setCheckable(
true);
578 switchWireFrameButton->setIconSize(QSize(24,24));
579 switchWireFrameButton->setIcon(QPixmap((
const char **)wireframe_xpm));
580 switchWireFrameButton->setToolTip(
"Switch wireframe/solid");
581 connect(switchWireFrameButton, SIGNAL(toggled(
bool)),
this,
582 SLOT(SwitchWireFrameCB(
bool)));
583 addAppPushButton(switchWireFrameButton);
585 switchAxesButton =
new QPushButton;
586 switchAxesButton->setCheckable(
true);
587 switchAxesButton->setText(QString(
"A"));
588 switchAxesButton->setToolTip(
"Axes on/off");
589 connect(switchAxesButton, SIGNAL(toggled(
bool)),
this,
590 SLOT(SwitchAxesCB(
bool)));
591 addAppPushButton(switchAxesButton);
593 detachButton =
new QPushButton;
594 detachButton->setIconSize(QSize(24,24));
595 detachButton->setIcon(style.standardIcon(QStyle::SP_CommandLink));
596 detachButton->setToolTip(
"Detach viewer window");
597 connect(detachButton, SIGNAL(clicked()),
this,
604 helpmsgbox =
new QMessageBox(getParentWidget());
605 helpmsgbox->setWindowTitle(
"OIQt Controls");
606 helpmsgbox->setFont(*font);
608"\nVIEWING mode (Hand cursor):\n\n\
609 Left-button + pointer move: rotate\n\
610 Shift+Left-button + pointer move: pan\n\
611 Middle-button + pointer move: pan\n\
612 Ctrl+Shift+Left-button + pointer move: zoom\n\
614 Right-button: popup menu\n\n\
615PICKING mode (Arrow cursor):\n\n\
616 Click on a volume: geometry readout\n\
617 Click on a trajectory: particle & trajectory readout\n\
618 Ctrl + click on a volume: see daughters.\n\
619 Shift + click on a volume: see mother.\n\n\
620EXTENDED PICKING mode (Arrow+ viewer button):\n\n\
621 Hover the mouse over a volume or trajectory for\n\
622 overlayed readout.\n\n\
623ELEMENT NAVIGATION (requires Reference Path):\n\n\
624 Click on element in list: centers view on element\n\
625 Arrow keys: rotate in 90 degree steps around element \n\
626 Shift + Right Arrow: move to next element\n\
627 Shift + Left Arrow: move to previous element\n\n\
628FLY mode (requires Reference Path):\n\n\
629 Page Up: Increase speed\n\
630 Page Down: Decrease speed (& reverse if wanted)\n\
631 Up Arrow: raise camera above path\n\
632 Down Arror: lower camera below path\n\
633 Escape: Exit fly mode";
634 helpmsgbox->setText(messagetxt);
635 helpmsgbox->setModal(
false);
642 AuxWindow =
new QDialog(parent);
643 AuxWindowDialog->
setupUi(AuxWindow);
646 connect(AuxWindowDialog->
listWidget, SIGNAL(itemClicked(QListWidgetItem*)),
647 this, SLOT(LoadBookmarkCB(QListWidgetItem*)));
648 connect(AuxWindowDialog->
listWidget1, SIGNAL(itemClicked(QListWidgetItem*)),
649 this, SLOT(LookAtSceneElementCB(QListWidgetItem*)));
650 connect(AuxWindowDialog->
pushButton_2, SIGNAL(clicked()),
651 this, SLOT(DeleteBookmarkCB()));
652 connect(AuxWindowDialog->
pushButton_3, SIGNAL(clicked()),
653 this, SLOT(RenameBookmarkCB()));
654 connect(AuxWindowDialog->
pushButton, SIGNAL(clicked()),
655 this, SLOT(SortBookmarksCB()));
668 SoQtExaminerViewer::afterRealizeHook();
672 SoCamera *cam = getCamera();
674 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
676 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
679 ((SoOrthographicCamera *) cam)->height.getValue();
683 ((SoOrthographicCamera *) cam)->height.getValue();
686 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
688 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
698 msgbox.setFont(*font);
699 QString messagetxt =
"Error reading bookmark file ";
700 messagetxt.append(QString(
fileName.c_str()));
701 msgbox.setText(messagetxt);
706 fileOut.seekp(0, std::ios::end);
727 SoSeparator* root = (SoSeparator*) (getSceneManager()->getSceneGraph());
729 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::afterRealizeHook",
"Root is null.");
731 root->addChild(
myCam);
745 SoEventCallback *moCB =
new SoEventCallback;
746 moCB->addEventCallback(
747 SoLocation2Event::getClassTypeId(),
749 root->addChild(moCB);
753 SoEventCallback *pickCB =
new SoEventCallback;
754 pickCB->addEventCallback(
755 SoMouseButtonEvent::getClassTypeId(),
757 root->addChild(pickCB);
763 AuxWindow->activateWindow();
766 uiQt =
dynamic_cast<G4UIQt*
>(UI->GetG4UIWindow());
769 viewerParent = getParentWidget();
770 viewerParent2 = viewerParent->parentWidget();
774 addAppPushButton(detachButton);
789 searcher->setInterest(SoSearchAction::FIRST);
793 return searcher->getPath()->getTail();
812 if (!action->isOfType(SoGLRenderAction::getClassTypeId()))
814 SbViewportRegion vpRegion =
815 ((SoGLRenderAction*)action)->getViewportRegion();
816 SbVec2s viewportSize = vpRegion.getViewportSizePixels();
819 float aspect = float(viewportSize[0]) / float(viewportSize[1]);
830 float factorx = 1.0f / float(viewportSize[1]) * 220.0f;
831 float factory = factorx;
834 stranslation->translation.setValue(SbVec3f(0.0f, -0.4f, 0.0f));
836 stranslation->translation.setValue(SbVec3f(0.0f, -0.4f / aspect, 0.0f));
840 if (viewportSize[0] > 500)
841 factorx *= 500.0f / 400.0f;
843 factorx *= float(viewportSize[0]) / 400.0f;
845 sscale->scaleFactor.setValue(SbVec3f(factorx, factory, 1.0f));
853 float xInfo, yInfo, xLogName, yLogName, xSolid, ySolid,
854 xMaterial, yMaterial, xZPos, yZPos;
862 if (aspect > 1.) xInfo = xInfo*aspect;
863 if (aspect < 1.) yInfo = yInfo/aspect;
864 yInfo = yInfo - mbgap*aspect;
868 yLogName = -.88 + mbgap*aspect;
870 ySolid = -.91 + mbgap*aspect;
872 yMaterial = -.94 + mbgap*aspect;
874 yZPos = -.97 + mbgap*aspect;
877 curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
917 float x, y, z, angle;
921 parseString<int>(
viewPtIdx, token, error);
924 while (getline(
fileIn, token)) {
926 std::size_t end = token.find_last_not_of(
' ');
927 token = token.substr(0, end + 1);
929 char *vpName =
new char[token.size() + 1];
930 strcpy(vpName, token.c_str());
934 parseString<float>(x, token, error);
936 parseString<float>(y, token, error);
938 parseString<float>(z, token, error);
940 tmp.
position = axis.setValue(x, y, z);
942 parseString<float>(x, token, error);
944 parseString<float>(y, token, error);
946 parseString<float>(z, token, error);
948 parseString<float>(angle, token, error);
950 orient.setValue(axis.setValue(x, y, z), angle);
954 parseString<int>(camType, token, error);
958 parseString<float>(tmp.
height, token, error);
989 SoCamera *cam = getCamera();
996 cam->position = camPosNew;
998 cam->focalDistance = (
prevPt - camPosNew).length();
1017 SoCamera *cam = getCamera();
1019 SbVec3f particleDir;
1030 cam->focalDistance = (cam->position.getValue() -
center).length();
1039 dist = (
prevPt - cam->position.getValue()).length();
1046 dist = (
prevPt - cam->position.getValue()).length();
1055 particleDir = p2 - p1;
1056 particleDir.normalize();
1069 SbRotation rot(SbVec3f(0,0,1), particleDir);
1083 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1103 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1106 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
1108 camPosNew = p2 - (
camDir*cam->focalDistance.getValue());
1112 cam->position = camPosNew;
1114 cam->focalDistance = (p2 - camPosNew).length();
1117 camPosNew.getValue(x,y,z);
1128 SoEventCallback *eventCB)
1130 SoHandleEventAction* action = eventCB->getAction();
1131 const SoPickedPoint *pp = action->getPickedPoint();
1136 SoPath* path = pp->getPath();
1137 SoNode* node = ((SoFullPath*)path)->getTail();
1139 if(node->getTypeId() == SoLineSet::getClassTypeId()) {
1146 This->setComponentCursor(SoQtCursor(SoQtCursor::DEFAULT));
1149 SoLineSet * trajectory = (SoLineSet *)node;
1157 SoSeparator * grpNode =
1158 (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1163 int nodeIndex = grpNode->findChild(trajectory);
1166 SoCoordinate3 * coords = 0;
1170 for(
int i = 0; i < 100; ++i) {
1173 tmpNode = grpNode->getChild(nodeIndex);
1174 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()) {
1176 coords = (SoCoordinate3 *)tmpNode;
1181 if(coords == NULL) {
1182 G4warn <<
"Could not find the coordinates node"
1183 " for the picked trajectory." <<
G4endl;
1191 if ((This->lshiftdown) || (This->rshiftdown))
1202 if(attHolder && attHolder->
GetAttDefs().size()) {
1204 std::string strTrajPoint =
"G4TrajectoryPoint:";
1205 std::ostringstream oss;
1206 for (std::size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1211 if(oss.str().find(strTrajPoint) != std::string::npos) {
1225 G4String name((
char*)node->getName().getString());
1226 G4String cls((
char*)node->getTypeId().getName().getString());
1227 G4warn <<
"SoNode : " << node
1228 <<
" SoType : " << cls
1229 <<
" name : " << name
1246 if(attHolder && attHolder->
GetAttDefs().size()) {
1247 for (std::size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1252 G4String name((
char*)node->getName().getString());
1253 G4String cls((
char*)node->getTypeId().getName().getString());
1254 G4warn <<
"SoNode : " << node
1255 <<
" SoType : " << cls
1256 <<
" name : " << name
1262 eventCB->setHandled();
1269 SoHandleEventAction* action = eventCB->getAction();
1270 const SoPickedPoint* pp = action->getPickedPoint();
1278 const SbViewportRegion & viewportRegion = action->getViewportRegion();
1280 std::string sLogName;
1282 std::stringstream ssZPos;
1283 std::stringstream ssSolids;
1284 std::stringstream ssMaterials;
1285 SoPath * path = pp->getPath();
1286 SoNode* node = ((SoFullPath*)path)->getTail();
1288 if(node->getTypeId() == Geant4_SoPolyhedron::getClassTypeId()) {
1290 sLogName =
"Logical Volume: ";
1293 SoGetBoundingBoxAction bAction(viewportRegion);
1294 bAction.apply((SoFullPath*)path);
1295 SbBox3f bBox = bAction.getBoundingBox();
1296 SbVec3f centr = bBox.getCenter();
1297 centr.getValue(x,y,z);
1298 ssZPos <<
"Pos: " << x <<
" " << y <<
" " << z;
1301 if(attHolder && attHolder->
GetAttDefs().size()) {
1303 std::vector<const std::map<G4String,G4AttDef>*> vecDefs =
1305 std::vector<const std::vector<G4AttValue>*> vecVals =
1307 for (std::size_t i = 0; i < vecDefs.size(); ++i) {
1308 const std::vector<G4AttValue> * vals = vecVals[i];
1310 std::vector<G4AttValue>::const_iterator iValue;
1312 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1313 const G4String& valueName = iValue->GetName();
1314 const G4String& value = iValue->GetValue();
1316 if(valueName ==
"Solid") {
1317 if(ssSolids.str() ==
"")
1318 ssSolids <<
"Solid Name: " << value;
1320 ssSolids <<
", " << value;
1323 if(valueName ==
"Material") {
1324 if(ssMaterials.str() ==
"")
1325 ssMaterials <<
"Material Name: " << value;
1327 ssMaterials <<
", " << value;
1334 else if(node->getTypeId() == SoLineSet::getClassTypeId()) {
1337 if(attHolder && attHolder->
GetAttDefs().size()) {
1338 std::string strTrajPoint =
"G4TrajectoryPoint:";
1339 std::ostringstream oss;
1341 for (std::size_t i = 0; i < attHolder->
GetAttDefs().size(); ++i) {
1345 const std::vector<G4AttValue>* vals = attHolder->
GetAttValues()[i];
1346 std::vector<G4AttValue>::const_iterator iValue;
1347 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1348 const G4String& valueName = iValue->GetName();
1349 const G4String& value = iValue->GetValue();
1353 if (valueName ==
"PN") t1 = value;
1354 if (valueName ==
"Ch") {
1355 if (atof(value.c_str()) > 0)
1361 if (valueName ==
"PDG") {
1369 if (valueName ==
"EventID") t2 =
"Evt " + value;
1370 if (valueName ==
"ID") t2 +=
" Trk " + value;
1371 if (valueName ==
"PID") {
1372 t2 +=
" Prt " + value;
1376 if (valueName ==
"IKE") t3 =
"KE " + value;
1377 if (valueName ==
"IMom") {
1379 std::size_t ipos = value.rfind(
" ");
1382 t3 +=
" P (" + value1 +
")";
1384 if (valueName ==
"IMag") {
1385 t3 +=
" " + value +
"/c";
1390 if (valueName ==
"NTP") {
1391 std::ostringstream t4oss;
1392 t4oss <<
"TrjPts " << value;
1393 t4oss <<
" Pos " << pp->getPoint()[0] <<
" " << pp->getPoint()[1] <<
1394 " " << pp->getPoint()[2];
1417 This->scheduleRedraw();
1418 eventCB->setHandled();
1422 bool redraw =
false;
1427 if(std::string(This->
mouseOverTextSolid->string.getValues(0)->getString()) != ssSolids.str()) {
1431 if(std::string(This->
mouseOverTextMaterial->string.getValues(0)->getString()) != ssMaterials.str()) {
1435 if(std::string(This->
mouseOverTextZPos->string.getValues(0)->getString()) != ssZPos.str()) {
1442 This->scheduleRedraw();
1445 eventCB->setHandled();
1450 This->scheduleRedraw();
1454 This->scheduleRedraw();
1458 This->scheduleRedraw();
1460 if(std::string(This->
mouseOverTextZPos->string.getValues(0)->getString()) !=
"") {
1462 This->scheduleRedraw();
1481 if (refParticleIdx < lastIdx && !animateSensor->isScheduled())
1510 SbVec3f * points = this->
sgeometry->point.startEditing();
1512 if (points[10][0] == 0.0f)
1514 if (points[14][0] == 0.0f)
1535 SoQtExaminerViewer::actualRedraw();
1538 SoQtExaminerViewer::actualRedraw();
1545 SoCoordinate3 *coords,
bool append)
1556 SbVec3f refParticlePt;
1561 for(
int i = 0; i < lineset->numVertices.getNum(); ++i) {
1562 for(
int j = 0; j < lineset->numVertices[i]; ++j) {
1563 refParticlePt = coords->point[j];
1590 SoSearchAction action;
1591 action.setType(SoLineSet::getClassTypeId(),
false);
1592 action.setInterest(SoSearchAction::ALL);
1593 action.apply(getSceneGraph());
1595 SoPathList &pathList = action.getPaths();
1597 if(pathList.getLength() != 0) {
1599 SoCoordinate3 * coords = NULL;
1600 std::vector<SoCoordinate3 *> coordvec;
1601 std::vector<SoLineSet *> linevec;
1603 bool refPathFound =
false;
1604 for(
int i = 0; i < pathList.getLength(); ++i) {
1605 SoFullPath *path = (SoFullPath *)pathList[i];
1608 for (std::size_t j = 0; j < attHolder->
GetAttDefs().size(); ++j) {
1609 std::ostringstream oss;
1613 std::string findStr =
"Type of trajectory (Type): ";
1614 std::string compareValue =
"REFERENCE";
1615 std::size_t idx = oss.str().find(findStr);
1617 if(idx != std::string::npos) {
1618 if(oss.str().substr(idx + findStr.size(),
1619 compareValue.size()) == compareValue) {
1621 if(coords != NULL) {
1622 refPathFound =
true;
1623 coordvec.push_back(coords);
1624 linevec.push_back((SoLineSet *)path->getTail());
1630 findStr =
"Track ID (ID): ";
1631 idx = oss.str().find(findStr);
1632 if(idx != std::string::npos) {
1634 std::string tmpstr = oss.str().substr(idx + findStr.size(),1);
1635 std::istringstream buffer(tmpstr);
1643 char nextChar = oss.str().at(idx+findStr.size()+1);
1646 if(std::isdigit(nextChar))
1650 if(coords != NULL) {
1651 coordvec.push_back(coords);
1652 linevec.push_back((SoLineSet *)path->getTail());
1668 if(coordvec.empty())
1679 float longestLength = 0.0;
1681 for(
unsigned int i=0;i < linevec.size(); ++i) {
1684 std::vector<SbVec3f> trajectory;
1686 for(
int j=0; j < linevec[i]->numVertices.getNum(); ++j) {
1688 for(
int k=0; k < linevec[i]->numVertices[j]; ++k) {
1689 trajectory.push_back(coordvec[i]->point[k]);
1694 float tmpLength=0.0;
1695 for(
unsigned int j=0; j < trajectory.size() - 1; ++j) {
1696 tmpLength += (trajectory[j] - trajectory[j + 1]).length();
1699 if(tmpLength > longestLength) {
1701 longestLength = tmpLength;
1713 SoLineSet *trajectory = (SoLineSet *)path->getTail();
1714 SoSeparator * grpNode = (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1715 int nodeIndex = grpNode->findChild(trajectory);
1720 for (
int i = 0; i < 100; ++i) {
1723 tmpNode = grpNode->getChild(nodeIndex);
1724 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()) {
1726 return (SoCoordinate3 *)tmpNode;
1737 std::string field, eltName;
1739 std::map<std::string, int> duplicates;
1740 std::map<std::string, int> sceneElts;
1741 SoSearchAction search;
1743 SoGroup *root = (SoGroup *)getSceneManager()->getSceneGraph();
1745 SoBaseKit::setSearchingChildren(
TRUE);
1748 search.setSearchingAll(
TRUE);
1749 search.setInterest(SoSearchAction::ALL);
1750 search.setType(Geant4_SoPolyhedron::getClassTypeId(), 0);
1756 SoPathList &pl = search.getPaths();
1760 for (
int i = 0; i < pl.getLength(); i++) {
1761 SoFullPath *path = (SoFullPath *)pl[i];
1763 eltName = node->getName();
1765 if(duplicates.count(eltName))
1766 duplicates[eltName]++;
1768 duplicates[eltName] = 1;
1771 for(
int i = 0; i < pl.getLength(); i++) {
1773 std::stringstream ssCount;
1774 SoFullPath *path = (SoFullPath *)pl[i];
1776 eltName = node->getName();
1778 if(duplicates[eltName] == 1)
1781 if(sceneElts.count(eltName))
1782 sceneElts[eltName]++;
1784 sceneElts[eltName] = 1;
1786 ssCount << sceneElts[eltName];
1790 field += ssCount.str();
1792 SoGetBoundingBoxAction bAction(getViewportRegion());
1793 bAction.apply(path);
1794 SbBox3f bBox = bAction.getBoundingBox();
1796 SbVec3f centr = bBox.getCenter();
1797 centr.getValue(x,y,z);
1810 return x*x + y*y + z*z;
1816 SbVec3f &closestPoint,
1855 SbVec3f dbq = b - q;
1856 float sqrDist =
sqrlen(dbq);
1859 for (std::size_t i = 1; i < count; ++i) {
1860 const SbVec3f a = b;
1861 const SbVec3f daq = dbq;
1864 const SbVec3f dab = a - b;
1866 float dab_x, dab_y, dab_z;
1867 dab.getValue(dab_x,dab_y,dab_z);
1868 float daq_x, daq_y, daq_z;
1869 daq.getValue(daq_x, daq_y, daq_z);
1870 float dbq_x, dbq_y, dbq_z;
1871 dbq.getValue(dbq_x, dbq_y, dbq_z);
1873 const float inv_sqrlen = 1./
sqrlen(dab);
1874 const float t = (dab_x*daq_x + dab_y*daq_y + dab_z*daq_z)*inv_sqrlen;
1885 current_dist = daq_x*daq_x + daq_y*daq_y + daq_z*daq_z
1886 - t*(daq_x*dab_x + daq_y*dab_y + daq_z*dab_z)
1887 + t*t*(dab_x*dab_x + dab_y*dab_y + dab_z*dab_z);
1892 current_dist =
sqrlen(dbq);
1895 if (current_dist < sqrDist) {
1896 sqrDist = current_dist;
1897 closestPoint = a + t*(b-a);
1902 dist = std::sqrt(sqrDist);
1912 typedef std::map<elementForSorting, sceneElement> sortedMap;
1921 trajLength[trajIndex] = 0.0;
1925 trajLength[trajIndex] = trajLength[trajIndex-1] + (*itRef - prevPoint).length();
1933 SoGetBoundingBoxAction bAction(getViewportRegion());
1934 SbVec3f elementCoord;
1935 std::vector<sceneElement>::iterator itEl;
1940 bAction.apply(itEl->path);
1943 elementCoord = itEl->center;
1961 sorted.insert(std::make_pair(el,*itEl));
1967 sortedMap::iterator itSorted = sorted.begin();
1968 for(; itSorted != sorted.end(); itSorted++)
1975 delete[] trajLength;
1987 std::vector<sceneElement>::const_iterator it;
1988 std::stringstream ss;
1993 ss <<
" [" << it->closestPointZCoord <<
"]";
1995 new QListWidgetItem(ss.str().c_str(), AuxWindowDialog->
listWidget1);
2004G4OpenInventorQtExaminerViewer::LookAtSceneElementCB(QListWidgetItem* item)
2007 std::string elementField;
2012 SoCamera * cam = getCamera();
2014 if (SoQtExaminerViewer::isAnimating())
2017 value = strdup(qPrintable(item->text()));
2032 elementField = value;
2034 std::size_t idx = elementField.find_last_of(
"[");
2035 if(idx == std::string::npos)
2036 idx = elementField.size();
2042 SoSearchAction search;
2043 SoNode *root = getSceneManager()->getSceneGraph();
2045 std::size_t idxUnderscore = elementField.find_last_of(
"_");
2047 parseString<int>(counter,
2048 elementField.substr(idxUnderscore + 1, idx), error);
2050 SoBaseKit::setSearchingChildren(
TRUE);
2052 search.setSearchingAll(
TRUE);
2062 path = (SoFullPath *)search.getPath();
2065 curEltName = elementField.substr(0, idxUnderscore);
2066 search.setInterest(SoSearchAction::ALL);
2070 SoPathList &pl = search.getPaths();
2071 path = (SoFullPath *)pl[counter - 1];
2077 if ((idx > 0) && (path)) {
2081 SoGetBoundingBoxAction bAction(getViewportRegion());
2082 bAction.apply(path);
2083 SbBox3f bBox = bAction.getBoundingBox();
2084 SbVec3f elementCoord = bBox.getCenter();
2089 float absLengthNow, absLengthMin;
2095 absLengthMin = (p - elementCoord).length();
2101 absLengthNow = (p - elementCoord).length();
2103 if (absLengthNow < absLengthMin) {
2104 absLengthMin = absLengthNow;
2117 distance = (pN - p1).length() / 10;
2129 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2133 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2140 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2155 cam->viewAll(path, getViewportRegion());
2162void G4OpenInventorQtExaminerViewer::FileLoadRefPathCB()
2166 QFileDialog filedialog(getParentWidget(), tr(
"Load Reference Path"));
2167 filedialog.setFileMode(QFileDialog::AnyFile);
2168 filedialog.setFont(*font);
2169 if (!filedialog.exec())
return;
2170 QStringList filenameinlist = filedialog.selectedFiles();
2171 QString filenamein = filenameinlist[0];
2175 char* filename =
new char[filenamein.size()+1];
2176 filename = strdup(qPrintable(filenamein));
2179 std::ifstream ifs(filename);
2183 while(ifs >> x >> y >> z) {
2189 msgbox.setFont(*font);
2190 QString messagetxt =
"Reference Path file not found: ";
2191 messagetxt.append(filenamein);
2192 msgbox.setText(messagetxt);
2198 msgbox.setFont(*font);
2199 QString messagetxt =
"Invalid Reference Path";
2200 msgbox.setText(messagetxt);
2212void G4OpenInventorQtExaminerViewer::FileSaveRefPathCB()
2216 QFileDialog filedialog(getParentWidget(), tr(
"Save Reference Path"));
2217 filedialog.setFileMode(QFileDialog::AnyFile);
2219 filedialog.setAcceptMode(QFileDialog::AcceptSave);
2220 filedialog.setFont(*font);
2221 if (!filedialog.exec())
return;
2222 QStringList filenameinlist = filedialog.selectedFiles();
2223 QString filenamein = filenameinlist[0];
2227 char* filename =
new char[filenamein.size()+1];
2228 filename = strdup(qPrintable(filenamein));
2231 std::ofstream ofs(filename);
2232 if (ofs.is_open()) {
2236 ofs << x <<
" " << y <<
" " << z <<
"\n";
2241 msgbox.setFont(*font);
2242 QString messagetxt =
"Error opening file ";
2243 messagetxt.append(filenamein);
2244 msgbox.setText(messagetxt);
2255 SbVec3f p1, p2, p3, dirNow, dirNxt, dir, p2_tmp, p_start, p_corner, p_nxt;
2256 float avgDistBtwPts = 0;
2257 float totalDistBtwPts = 0;
2258 std::vector<SbVec3f> newRefParticleTrajectory;
2262 for (std::size_t i = 0; i < size; ++i) {
2268 totalDistBtwPts += (p2 - p1).length();
2271 if (numOfPts <= 2)
return;
2273 avgDistBtwPts = totalDistBtwPts / numOfPts;
2274 float minDistAllowed = 0.75 * avgDistBtwPts;
2278 std::size_t i = 0, j = 0;
2284 p1.getValue(x, y, z);
2286 newRefParticleTrajectory.push_back(refPoint);
2289 while ((p2 - p1).length() < minDistAllowed && j < (size - 1)) {
2308 SoCamera *cam = getCamera();
2317 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2319 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
2321 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2323 ((SoOrthographicCamera *) cam)->height.getValue();
2331 SoCamera *cam = getCamera();
2341 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2345 ((SoOrthographicCamera *) cam)->height.setValue(
2348 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2350 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2354 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2357 ((SoOrthographicCamera *) cam)->height.setValue(
2366 SbTime curTime = SbTime::getTimeOfDay();
2369 SoTimerSensor* s = (SoTimerSensor*) sensor;
2371 float t = float((curTime - s->getBaseTime()).getValue())
2374 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2376 SbBool end = (t == 1.0f);
2399 SbTime curTime = SbTime::getTimeOfDay();
2401 SoCamera *cam = This->getCamera();
2402 SoTimerSensor* s = (SoTimerSensor*) sensor;
2404 float t = float((curTime - s->getBaseTime()).getValue())
2407 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2409 SbBool end = (t == 1.0f);
2439 if (SoQtExaminerViewer::isAnimating())
2443 SbVec3f p1, p2, p2_tmp, camUpV, camD, camD_tmp, leftRightAxis;
2444 float x1, y1, z1, x2, y2, z2;
2461 p1.getValue(x1, y1, z1);
2462 p2.getValue(x2, y2, z2);
2467 p2_tmp.setValue(x2, y1, z2);
2468 camD_tmp = p2_tmp - p1;
2469 camD_tmp.normalize();
2471 camUpV.setValue(0, 1, 0);
2472 rot.setValue(camD_tmp, camD);
2473 rot.multVec(camUpV, camUpV);
2475 leftRightAxis = camD.cross(camUpV);
2477 myCam->position = p1;
2478 myCam->pointAt(p2, camUpV);
2482 myCam->position = p1;
2488 myCam->focalDistance = 0.1f;
2494 G4OpenInventorQtExaminerViewer::ToolsRefPathStartCB();
2498void G4OpenInventorQtExaminerViewer::ToolsRefPathStartCB()
2502 msgbox.setFont(*font);
2503 QString messagetxt =
"No current reference path";
2504 msgbox.setText(messagetxt);
2524 if (SoQtExaminerViewer::isAnimating())
2534 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2549 distance = (pN - p1).length() / 10;
2555void G4OpenInventorQtExaminerViewer::ToolsRefPathInvertCB()
2572 SoCamera *cam = getCamera();
2595 escapeCallback = callback;
2623 for (std::size_t i = 0; i < size; ++i) {
2624 new QListWidgetItem(
viewPtList[i].viewPtName,
2636 std::istringstream str(s);
2637 if ((str >> t).fail())
2643G4OpenInventorQtExaminerViewer::FileOpenBookmarkCB()
2647 QFileDialog filedialog(getParentWidget(), tr(
"Open bookmark file"));
2648 filedialog.setFileMode(QFileDialog::ExistingFile);
2649 filedialog.setFont(*font);
2650 if (!filedialog.exec())
return;
2651 QStringList filenameinlist = filedialog.selectedFiles();
2652 QString filenamein = filenameinlist[0];
2654 char* filename =
new char[filenamein.size()+1];
2655 filename = strdup(qPrintable(filenamein));
2662 msgbox.setFont(*font);
2663 QString messagetxt =
"Error opening file: ";
2664 messagetxt.append(filenamein);
2665 msgbox.setText(messagetxt);
2676 msgbox.setFont(*font);
2677 QString messagetxt =
"Error reading bookmark file: ";
2678 messagetxt.append(filenamein);
2679 msgbox.setText(messagetxt);
2688 fileOut.seekp(0, std::ios::end);
2711 AuxWindowDialog->
lineEdit->setText(QString(
""));
2716G4OpenInventorQtExaminerViewer::FileNewBookmarkCB()
2719 QFileDialog filedialog(getParentWidget(), tr(
"Open new bookmark file"));
2720 filedialog.setFileMode(QFileDialog::AnyFile);
2722 filedialog.setAcceptMode(QFileDialog::AcceptSave);
2724 filedialog.setLabelText(QFileDialog::Accept, QString(
"New"));
2725 filedialog.setFont(*font);
2726 if (!filedialog.exec())
return;
2727 QStringList filenameinlist = filedialog.selectedFiles();
2728 QString filenamein = filenameinlist[0];
2732 char* filename =
new char[filenamein.size()+1];
2733 filename = strdup(qPrintable(filenamein));
2741 msgbox.setFont(*font);
2742 QString messagetxt =
"Error opening new bookmark file: ";
2743 messagetxt.append(filenamein);
2744 msgbox.setText(messagetxt);
2752G4OpenInventorQtExaminerViewer::ToolsAnimateRefParticleCB()
2764 axisSwitch->whichChild.setValue(SO_SWITCH_ALL);
2770 SoCamera *cam = getCamera();
2783 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2793 cam->focalDistance = 0.1f;
2794 ((SoPerspectiveCamera *) cam)->heightAngle = 0.50f;
2801 cam->orientation = (
myCam)->orientation.getValue();
2807G4OpenInventorQtExaminerViewer::SaveViewPtCB()
2816 QInputDialog* inputdialog =
new QInputDialog(getParentWidget());
2817 inputdialog->setFont(*font);
2818 inputdialog->setWindowTitle(tr(
"Enter a name for the bookmark"));
2819 inputdialog->setLabelText(
"Bookmark name");
2821 inputdialog->adjustSize();
2823 if (inputdialog->exec() == QDialog::Accepted)
2824 namein=inputdialog->textValue().trimmed();
2827 if (namein.isEmpty())
return;
2837 char*
name =
new char[nVPName];
2841 QByteArray ba = namein.toLocal8Bit();
2842 name = strdup(ba.constData());
2849 for (
int i = 0; i < (int)
viewPtList.size(); i++) {
2850 if (!strcmp(name,
viewPtList[i].viewPtName)) {
2852 msgbox.setText(
"Bookmark name is already in use");
2861 saveViewPtItem =
new QListWidgetItem(namein,
2863 AuxWindowDialog->
listWidget->setCurrentItem(saveViewPtItem);
2864 AuxWindowDialog->
lineEdit->setText(namein);
2874 float x, y, z, angle;
2875 SoCamera* camera = getCamera();
2890 tmp.
position = camera->position.getValue();
2898 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2899 tmp.
height = ((SoPerspectiveCamera *) camera)->heightAngle.getValue();
2901 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
2902 tmp.
height = ((SoOrthographicCamera *) camera)->height.getValue();
2905 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::saveViewPtCB",
2906 "Only Perspective and Orthographic cameras are supported.");
2916 std::string vpName = name;
2921 fileOut << vpName << std::endl;
2923 fileOut << x <<
" " << y <<
" " << z << std::endl;
2927 axis.getValue(x, y, z);
2928 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
2951 std::stringstream out;
2955 fileOut.seekp(0, std::ios::beg);
2965 fileOut.seekp(0, std::ios::end);
2971void G4OpenInventorQtExaminerViewer::LoadBookmarkCB(QListWidgetItem* item)
2977 char* vpName =
new char[nVPName];
2979 vpName = strdup(qPrintable(item->text()));
2982 for (
int i = 0; i < (int)
viewPtList.size(); i++) {
2983 if (!strcmp(
viewPtList[i].viewPtName, vpName)) {
2992 AuxWindowDialog->
lineEdit->setText(item->text());
3008 SoCamera * camera = getCamera();
3009 if (camera == NULL) {
3010 G4warn <<
"setViewPt: Camera is null. Unable to set the viewpoint." <<
3019 G4warn <<
"setViewPt: There are no viewpoints to load." <<
G4endl;
3026 if (SoQtExaminerViewer::isAnimating()) stopAnimating();
3032 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
3049 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3052 camera = getCamera();
3053 ((SoOrthographicCamera *) camera)->height.setValue(
3056 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3058 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3061 camera = getCamera();
3062 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3065 ((SoOrthographicCamera *) camera)->height.setValue(
3068 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::setViewPt",
3069 "Only Perspective and Orthographic cameras are supported.");
3076void G4OpenInventorQtExaminerViewer::NextViewPtCB()
3090 AuxWindowDialog->
lineEdit->setText(QString(viewptname));
3093void G4OpenInventorQtExaminerViewer::PrevViewPtCB()
3107 AuxWindowDialog->
lineEdit->setText(QString(viewptname));
3111void G4OpenInventorQtExaminerViewer::AbbrOutputCB(
bool checked)
3120void G4OpenInventorQtExaminerViewer::PickRefPathCB()
3129 setComponentCursor(SoQtCursor(SoQtCursor::CROSSHAIR));
3134void G4OpenInventorQtExaminerViewer::SwitchWireFrameCB(
bool checked)
3141 setDrawStyle(SoQtViewer::STILL, SoQtViewer::VIEW_LINE);
3142 setDrawStyle(SoQtViewer::INTERACTIVE, SoQtViewer::VIEW_LINE);
3144 setDrawStyle(SoQtViewer::STILL, SoQtViewer::VIEW_AS_IS);
3145 setDrawStyle(SoQtViewer::INTERACTIVE,
3146 SoQtViewer::VIEW_SAME_AS_STILL);
3151void G4OpenInventorQtExaminerViewer::SwitchAxesCB(
bool checked)
3155 setFeedbackVisibility(checked);
3164void G4OpenInventorQtExaminerViewer::DetachCB()
3169 viewerParent->setParent(viewerParent2);
3170 removeAppPushButton(detachButton);
3175void G4OpenInventorQtExaminerViewer::DeleteBookmarkCB()
3181 QListWidgetItem* listitem = AuxWindowDialog->
listWidget->currentItem();
3182 if (!listitem)
return;
3183 if (!(listitem->isSelected()))
return;
3185 QString vpnamein = listitem->text();
3188 char* vpName =
new char[nVPName];
3189 vpName = strdup(qPrintable(vpnamein));
3204 std::ofstream out(
"temporaryFile.txt");
3210 out << line <<
"\n";
3212 while (getline(
fileIn, line)) {
3213 end = line.find_last_not_of(
' ');
3214 line = line.substr(0, end + 1);
3215 if (!strcmp(line.c_str(), vpName)) {
3216 while (line.size()) {
3220 while (getline(
fileIn, line))
3221 out << line <<
"\n";
3223 while (line.size()) {
3224 out << line <<
"\n";
3231 std::size_t idx = 0;
3233 while (idx < size) {
3234 if (!strcmp(
viewPtList[idx].viewPtName, vpName)) {
3247 int istat = remove(
fileName.c_str());
3250 msgbox.setFont(*font);
3251 QString messagetxt =
"Error removing bookmarks file";
3253 msgbox.setText(messagetxt);
3257 istat = rename(
"temporaryFile.txt",
fileName.c_str());
3260 msgbox.setFont(*font);
3261 QString messagetxt =
"Error renaming bookmarks file";
3263 msgbox.setText(messagetxt);
3268 fileOut.seekp(0, std::ios::end);
3282void G4OpenInventorQtExaminerViewer::RenameBookmarkCB()
3287 QListWidgetItem* listitem = AuxWindowDialog->
listWidget->currentItem();
3288 if (!listitem)
return;
3289 if (!(listitem->isSelected()))
return;
3291 QString vpnamein = listitem->text();
3298 QInputDialog* inputdialog =
new QInputDialog(getParentWidget());
3299 inputdialog->setFont(*font);
3300 inputdialog->setWindowTitle(tr(
"Enter"));
3301 inputdialog->setLabelText(
"New bookmark name");
3302 inputdialog->adjustSize();
3304 if (inputdialog->exec() == QDialog::Accepted)
3305 newnamein=inputdialog->textValue().trimmed();
3308 if (newnamein.isEmpty())
return;
3310 char* newname =
new char[nVPName];
3311 newname = strdup(qPrintable(newnamein));
3314 for (std::size_t i = 0; i < size; ++i) {
3315 if (!strcmp(newname,
viewPtList[i].viewPtName)) {
3317 msgbox.setFont(*font);
3318 msgbox.setText(
"Bookmark name is already in use");
3325 listitem->setText(QString(newname));
3326 AuxWindowDialog->
lineEdit->setText(newname);
3337 std::size_t idx = 0, end, pos;
3339 std::string line, newName;
3348 while (getline(
fileIn, line)) {
3349 end = line.find_last_not_of(
' ');
3350 line = line.substr(0, end + 1);
3354 fileOut.seekp(0, std::ios::end);
3365 while (idx < size) {
3375void G4OpenInventorQtExaminerViewer::SortBookmarksCB()
3385 std::vector<std::string> charList;
3391 for (
int i = 0; i < (int)
viewPtList.size(); i++) {
3393 charList.push_back(
viewPtList[i].viewPtName);
3397 std::sort(charList.begin(), charList.end());
3403 for (
int i = 0; i < (int)
viewPtList.size(); i++) {
3407 new QListWidgetItem(charList[i].c_str(), AuxWindowDialog->
listWidget);
3420 float x, y, z, angle;
3421 std::size_t sortIdx = 0, unsortIdx = 0;
3430 std::size_t size = sortedViewPts.size();
3431 while (sortIdx < size) {
3432 while (strcmp(sortedViewPts[sortIdx].c_str(),
3436 std::string vpName =
viewPtList[unsortIdx].viewPtName;
3440 fileOut << vpName << std::endl;
3441 viewPtList[unsortIdx].position.getValue(x, y, z);
3442 fileOut << x <<
" " << y <<
" " << z << std::endl;
3445 viewPtList[unsortIdx].orientation.getValue(axis, angle);
3446 axis.getValue(x, y, z);
3447 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3450 <<
viewPtList[unsortIdx].height << std::endl;
3473 float multiplicator = float(std::exp(diffvalue));
3474 SoCamera *cam = getCamera();
3476 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3477 const float oldfocaldist = cam->focalDistance.getValue();
3478 const float newfocaldist = oldfocaldist * multiplicator;
3481 cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
3483 const SbVec3f oldpos = cam->position.getValue();
3484 const SbVec3f newpos = oldpos + (newfocaldist - oldfocaldist) * -direction;
3485 cam->position = newpos;
3486 cam->focalDistance = newfocaldist;
3487 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
3488 SoOrthographicCamera * oc = (SoOrthographicCamera *)cam;
3489 oc->height = oc->height.getValue() * multiplicator;
3503 SoCamera *cam = getCamera();
3504 const SoType type(ev->getTypeId());
3509 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
3510 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
3515 switch (me->getButton()) {
3517 case SoMouseButtonEvent::BUTTON4:
3518 if (me->getState() == SoButtonEvent::DOWN) {
3525 case SoMouseButtonEvent::BUTTON5:
3526 if (me->getState() == SoButtonEvent::DOWN) {
3543 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
3544 SoKeyboardEvent* ke = (SoKeyboardEvent*)ev;
3546 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
3547 switch (ke->getKey()) {
3548 case SoKeyboardEvent::E:
3549 if (externalQtApp) {
3554 "E KEY PRESSED, EXITING OIQT VIEWER SECONDARY LOOP" <<
3556 SoQt::exitMainLoop();
3560 case SoKeyboardEvent::LEFT_SHIFT:
3561 this->lshiftdown =
true;
3563 case SoKeyboardEvent::RIGHT_SHIFT:
3564 this->rshiftdown =
true;
3566 case SoKeyboardEvent::LEFT_CONTROL:
3567 this->lctrldown =
true;
3569 case SoKeyboardEvent::RIGHT_CONTROL:
3570 this->rctrldown =
true;
3572 case SoKeyboardEvent::SPACE:
3594 case SoKeyboardEvent::ESCAPE:
3610 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
3621 case SoKeyboardEvent::DELETE:
3633 case SoKeyboardEvent::LEFT_ARROW:
3636 if ((this->lshiftdown) || (this->rshiftdown)) {
3640 else if ((this->lctrldown) || (this->rctrldown)) {
3641 if (SoQtExaminerViewer::isAnimating())
3656 if (SoQtExaminerViewer::isAnimating())
3680 cam->position =
myCam->position;
3684 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3687 this->bottomWheelMotion(
3688 this->getBottomWheelValue() + 0.1f);
3698 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3699 "Unhandled viewer state");
3704 case SoKeyboardEvent::RIGHT_ARROW:
3707 if ((this->lshiftdown) || (this->rshiftdown)) {
3711 else if ((this->lctrldown) || (this->rctrldown)) {
3712 if (SoQtExaminerViewer::isAnimating())
3725 if (SoQtExaminerViewer::isAnimating())
3746 cam->position =
myCam->position;
3750 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3753 this->bottomWheelMotion(
3754 this->getBottomWheelValue() - 0.1f);
3763 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3764 "Unhandled viewer state");
3769 case SoKeyboardEvent::DOWN_ARROW:
3773 if ((this->lshiftdown) || (this->rshiftdown)) {
3778 if (SoQtExaminerViewer::isAnimating())
3800 cam->position =
myCam->position;
3806 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3807 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
3816 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3817 "Unhandled viewer state");
3822 case SoKeyboardEvent::UP_ARROW:
3825 if ((this->lshiftdown) || (this->rshiftdown)) {
3830 if (SoQtExaminerViewer::isAnimating())
3853 cam->position =
myCam->position;
3859 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3860 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
3869 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3870 "Unhandled viewer state");
3875 case SoKeyboardEvent::PAGE_UP:
3926 case SoKeyboardEvent::PAGE_DOWN:
3983 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
3984 switch (ke->getKey()) {
3985 case SoKeyboardEvent::LEFT_SHIFT:
3986 this->lshiftdown =
false;
3988 case SoKeyboardEvent::RIGHT_SHIFT:
3989 this->rshiftdown =
false;
3991 case SoKeyboardEvent::LEFT_CONTROL:
3992 this->lctrldown =
false;
3994 case SoKeyboardEvent::RIGHT_CONTROL:
3995 this->rctrldown =
false;
4010 return SoQtExaminerViewer::processSoEvent(ev);
4017void G4OpenInventorQtExaminerViewer::FileLoadSceneGraphCB()
4021 QFileDialog filedialog(getParentWidget(), tr(
"Load Scene Graph"));
4022 filedialog.setFileMode(QFileDialog::AnyFile);
4023 filedialog.setFont(*font);
4024 if (!filedialog.exec())
return;
4025 QStringList filenameinlist = filedialog.selectedFiles();
4026 QString filenamein = filenameinlist[0];
4030 char* filename =
new char[filenamein.size()+1];
4031 filename = strdup(qPrintable(filenamein));
4036 if (sceneInput.openFile(filename)) {
4041 msgbox.setFont(*font);
4042 QString messagetxt =
"Error reading scene graph file ";
4043 messagetxt.append(filenamein);
4044 msgbox.setText(messagetxt);
4046 sceneInput.closeFile();
4051 msgbox.setFont(*font);
4052 QString messagetxt =
"Error opening scene graph file ";
4053 messagetxt.append(filenamein);
4054 msgbox.setText(messagetxt);
4059 SoSeparator* root = (SoSeparator*)getSceneGraph();
4065void G4OpenInventorQtExaminerViewer::FileSaveSceneGraphCB()
4069 QFileDialog filedialog(getParentWidget(), tr(
"Save scene graph"));
4070 filedialog.setFileMode(QFileDialog::AnyFile);
4072 filedialog.setAcceptMode(QFileDialog::AcceptSave);
4073 filedialog.setFont(*font);
4074 if (!filedialog.exec())
return;
4075 QStringList filenameinlist = filedialog.selectedFiles();
4076 QString filenamein = filenameinlist[0];
4080 char* filename =
new char[filenamein.size()+1];
4081 filename = strdup(qPrintable(filenamein));
4084 SoWriteAction writeAction;
4085 SoSeparator* root = (SoSeparator*)getSceneGraph();
4087 SoOutput* out = writeAction.getOutput();
4089 if (out->openFile(filename)) {
4090 out->setBinary(
FALSE);
4091 writeAction.apply(root);
4095 msgbox.setFont(*font);
4096 QString messagetxt =
"Error opening file ";
4097 messagetxt.append(filenamein);
4098 msgbox.setText(messagetxt);
4104void G4OpenInventorQtExaminerViewer::HelpControlsCB()
#define MAX_SPEED_INDICATOR
#define SPEED_INDICATOR_STEP
G4GLOB_DLL std::ostream G4cout
const std::vector< const std::vector< G4AttValue > * > & GetAttValues() const
const std::vector< const std::map< G4String, G4AttDef > * > & GetAttDefs() const
static void mouseoverCB(void *aThis, SoEventCallback *eventCB)
SoTranslation * mouseOverTransMaterial
SoCoordinate3 * getCoordsNode(SoFullPath *path)
static void superimpositionCB(void *closure, SoAction *action)
static void animateSensorRotationCB(void *, SoSensor *)
SoText2 * mouseOverTextMaterial
SoSearchAction * searcher
void moveCamera(float dist=0, bool lookdown=false)
virtual void afterRealizeHook()
SoSwitch * animSpeedSwitch
SoNode * getSuperimpositionNode(SoNode *, const char *name)
void animateRefParticle()
SoSeparator * newSceneGraph
SoTranslation * curInfoTrans
~G4OpenInventorQtExaminerViewer()
SoTranslation * mouseOverTransZPos
void addEscapeCallback(void(*cb)())
void buildWidget(QWidget *parent)
void parseString(T &t, const std::string &s, bool &error)
SoTranslation * mouseOverTransSolid
void setReferencePathZPos()
SbRotation camStartOrient
static void pickingCB(void *aThis, SoEventCallback *eventCB)
SoFont * mouseOverFontZPos
static void sceneChangeCB(void *, SoSensor *)
friend class HookEventProcState
SbBool processSoEvent(const SoEvent *const event)
void renameViewPt(char *vpName)
SoFont * mouseOverFontMaterial
std::vector< float > refZPositions
G4OpenInventorQtExaminerViewer(QWidget *parent=NULL, const char *name=NULL, SbBool embed=TRUE, SoQtFullViewer::BuildFlag flag=BUILD_ALL, SoQtViewer::Type type=BROWSER)
SoTranslation * stranslation
SoTranslation * mouseOverTransLogName
void sortViewPts(std::vector< std::string >)
void deleteViewPt(char *vpName=NULL)
SoNodeSensor * sceneChangeSensor
bool viewingBeforePickRef
void cleanUpAfterPrevFile()
SoTimerSensor * animateSensor
virtual void actualRedraw(void)
void createElementsList()
void setReferencePath(SoLineSet *, SoCoordinate3 *, bool append=false)
void saveViewPt(char *name)
void updateSpeedIndicator(void)
void construct(const SbBool build)
SoFont * mouseOverFontLogName
void superimpositionEvent(SoAction *action)
SoText2 * mouseOverTextZPos
SoTimerSensor * animateSensorRotation
std::vector< sceneElement > sceneElements
void distanceToTrajectory(const SbVec3f &, float &, SbVec3f &, int &)
void evenOutRefParticlePts()
viewPtData camB4Animation
double animateBtwPtsPeriod
SoSwitch * animSpeedOutlineSwitch
std::vector< viewPtData > viewPtList
SoFont * mouseOverFontSolid
std::vector< SbVec3f > refParticleTrajectory
SoText2 * mouseOverTextSolid
static void animateSensorCB(void *, SoSensor *)
float sqrlen(const SbVec3f &)
SoText2 * mouseOverTextLogName
SoCoordinate3 * sgeometry
void setStartingPtForAnimation()
HookEventProcState * hookBeamOn
G4bool AddTabWidget(QWidget *, QString)
QTabWidget * GetViewerTabWidget()
static G4UImanager * GetUIpointer()
virtual G4bool Notify(G4ApplicationState requestedState)
HookEventProcState(G4OpenInventorQtExaminerViewer *)
QPushButton * pushButton_2
QPushButton * pushButton_3
void setupUi(QDialog *Dialog)
QListWidget * listWidget1
const char * name(G4int ptype)
float distanceToBeamlineStart