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{0.0}, y{0.0}, z{0.0}, angle{0.0};
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());
940 tmp.
position = axis.setValue(x, y, z);
950 orient.setValue(axis.setValue(x, y, z), angle);
989 SoCamera *cam = getCamera();
996 cam->position = camPosNew;
998 cam->focalDistance = (
prevPt - camPosNew).length();
1017 SoCamera *cam = getCamera();
1019 SbVec3f particleDir;
1020 SbVec3f camPosNew{0.0f, 0.0f, 0.0f};
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();
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 if(attHolder !=
nullptr)
1610 for (std::size_t j = 0; j < attHolder->
GetAttDefs().size(); ++j) {
1611 std::ostringstream oss;
1615 std::string findStr =
"Type of trajectory (Type): ";
1616 std::string compareValue =
"REFERENCE";
1617 std::size_t idx = oss.str().find(findStr);
1619 if(idx != std::string::npos) {
1620 if(oss.str().substr(idx + findStr.size(),
1621 compareValue.size()) == compareValue) {
1623 if(coords != NULL) {
1624 refPathFound =
true;
1625 coordvec.push_back(coords);
1626 linevec.push_back((SoLineSet *)path->getTail());
1632 findStr =
"Track ID (ID): ";
1633 idx = oss.str().find(findStr);
1634 if(idx != std::string::npos) {
1636 std::string tmpstr = oss.str().substr(idx + findStr.size(),1);
1637 std::istringstream buffer(tmpstr);
1645 char nextChar = oss.str().at(idx+findStr.size()+1);
1648 if(std::isdigit(nextChar))
1652 if(coords != NULL) {
1653 coordvec.push_back(coords);
1654 linevec.push_back((SoLineSet *)path->getTail());
1671 if(coordvec.empty())
1682 float longestLength = 0.0;
1684 for(
unsigned int i=0;i < linevec.size(); ++i) {
1687 std::vector<SbVec3f> trajectory;
1689 for(
int j=0; j < linevec[i]->numVertices.getNum(); ++j) {
1691 for(
int k=0; k < linevec[i]->numVertices[j]; ++k) {
1692 trajectory.push_back(coordvec[i]->point[k]);
1697 float tmpLength=0.0;
1698 for(
unsigned int j=0; j < trajectory.size() - 1; ++j) {
1699 tmpLength += (trajectory[j] - trajectory[j + 1]).length();
1702 if(tmpLength > longestLength) {
1704 longestLength = tmpLength;
1716 SoLineSet *trajectory = (SoLineSet *)path->getTail();
1717 SoSeparator * grpNode = (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1718 int nodeIndex = grpNode->findChild(trajectory);
1723 for (
int i = 0; i < 100; ++i) {
1726 tmpNode = grpNode->getChild(nodeIndex);
1727 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()) {
1729 return (SoCoordinate3 *)tmpNode;
1740 std::string field, eltName;
1742 std::map<std::string, int> duplicates;
1743 std::map<std::string, int> sceneElts;
1744 SoSearchAction search;
1746 SoGroup *root = (SoGroup *)getSceneManager()->getSceneGraph();
1748 SoBaseKit::setSearchingChildren(
TRUE);
1751 search.setSearchingAll(
TRUE);
1752 search.setInterest(SoSearchAction::ALL);
1753 search.setType(Geant4_SoPolyhedron::getClassTypeId(), 0);
1759 SoPathList &pl = search.getPaths();
1763 for (
int i = 0; i < pl.getLength(); i++) {
1764 SoFullPath *path = (SoFullPath *)pl[i];
1766 eltName = node->getName();
1768 if(duplicates.count(eltName))
1769 duplicates[eltName]++;
1771 duplicates[eltName] = 1;
1774 for(
int i = 0; i < pl.getLength(); i++) {
1776 std::stringstream ssCount;
1777 SoFullPath *path = (SoFullPath *)pl[i];
1779 eltName = node->getName();
1781 if(duplicates[eltName] == 1)
1784 if(sceneElts.count(eltName))
1785 sceneElts[eltName]++;
1787 sceneElts[eltName] = 1;
1789 ssCount << sceneElts[eltName];
1793 field += ssCount.str();
1795 SoGetBoundingBoxAction bAction(getViewportRegion());
1796 bAction.apply(path);
1797 SbBox3f bBox = bAction.getBoundingBox();
1799 SbVec3f centr = bBox.getCenter();
1800 centr.getValue(x,y,z);
1813 return x*x + y*y + z*z;
1819 SbVec3f &closestPoint,
1858 SbVec3f dbq = b - q;
1859 float sqrDist =
sqrlen(dbq);
1862 for (std::size_t i = 1; i < count; ++i) {
1863 const SbVec3f a = b;
1864 const SbVec3f daq = dbq;
1867 const SbVec3f dab = a - b;
1869 float dab_x, dab_y, dab_z;
1870 dab.getValue(dab_x,dab_y,dab_z);
1871 float daq_x, daq_y, daq_z;
1872 daq.getValue(daq_x, daq_y, daq_z);
1873 float dbq_x, dbq_y, dbq_z;
1874 dbq.getValue(dbq_x, dbq_y, dbq_z);
1876 const float inv_sqrlen = 1./
sqrlen(dab);
1877 const float t = (dab_x*daq_x + dab_y*daq_y + dab_z*daq_z)*inv_sqrlen;
1888 current_dist = daq_x*daq_x + daq_y*daq_y + daq_z*daq_z
1889 - t*(daq_x*dab_x + daq_y*dab_y + daq_z*dab_z)
1890 + t*t*(dab_x*dab_x + dab_y*dab_y + dab_z*dab_z);
1895 current_dist =
sqrlen(dbq);
1898 if (current_dist < sqrDist) {
1899 sqrDist = current_dist;
1900 closestPoint = a + t*(b-a);
1905 dist = std::sqrt(sqrDist);
1915 typedef std::map<elementForSorting, sceneElement> sortedMap;
1924 trajLength[trajIndex] = 0.0;
1928 trajLength[trajIndex] = trajLength[trajIndex-1] + (*itRef - prevPoint).length();
1936 SoGetBoundingBoxAction bAction(getViewportRegion());
1937 SbVec3f elementCoord;
1938 std::vector<sceneElement>::iterator itEl;
1943 bAction.apply(itEl->path);
1946 elementCoord = itEl->center;
1964 sorted.insert(std::make_pair(el,*itEl));
1970 sortedMap::iterator itSorted = sorted.begin();
1971 for(; itSorted != sorted.end(); itSorted++)
1978 delete[] trajLength;
1990 std::vector<sceneElement>::const_iterator it;
1991 std::stringstream ss;
1996 ss <<
" [" << it->closestPointZCoord <<
"]";
1998 new QListWidgetItem(ss.str().c_str(), AuxWindowDialog->
listWidget1);
2007G4OpenInventorQtExaminerViewer::LookAtSceneElementCB(QListWidgetItem* item)
2012 SoCamera * cam = getCamera();
2014 if (SoQtExaminerViewer::isAnimating())
2029 std::string elementField = qPrintable(item->text());
2031 std::size_t idx = elementField.find_last_of(
"[");
2032 if(idx == std::string::npos)
2033 idx = elementField.size();
2039 SoSearchAction search;
2040 SoNode *root = getSceneManager()->getSceneGraph();
2042 std::size_t idxUnderscore = elementField.find_last_of(
"_");
2045 elementField.substr(idxUnderscore + 1, idx), error);
2047 SoBaseKit::setSearchingChildren(
TRUE);
2049 search.setSearchingAll(
TRUE);
2059 path = (SoFullPath *)search.getPath();
2062 curEltName = elementField.substr(0, idxUnderscore);
2063 search.setInterest(SoSearchAction::ALL);
2067 SoPathList &pl = search.getPaths();
2068 path = (SoFullPath *)pl[counter - 1];
2074 if ((idx > 0) && (path)) {
2078 SoGetBoundingBoxAction bAction(getViewportRegion());
2079 bAction.apply(path);
2080 SbBox3f bBox = bAction.getBoundingBox();
2081 SbVec3f elementCoord = bBox.getCenter();
2086 float absLengthNow, absLengthMin;
2092 absLengthMin = (p - elementCoord).length();
2098 absLengthNow = (p - elementCoord).length();
2100 if (absLengthNow < absLengthMin) {
2101 absLengthMin = absLengthNow;
2114 distance = (pN - p1).length() / 10;
2126 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2130 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
2137 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2152 cam->viewAll(path, getViewportRegion());
2159void G4OpenInventorQtExaminerViewer::FileLoadRefPathCB()
2163 QFileDialog filedialog(getParentWidget(), tr(
"Load Reference Path"));
2164 filedialog.setFileMode(QFileDialog::AnyFile);
2165 filedialog.setFont(*font);
2166 if (!filedialog.exec())
return;
2167 QStringList filenameinlist = filedialog.selectedFiles();
2168 QString filenamein = filenameinlist[0];
2170 std::ifstream ifs(qPrintable(filenamein));
2174 while(ifs >> x >> y >> z) {
2180 msgbox.setFont(*font);
2181 QString messagetxt =
"Reference Path file not found: ";
2182 messagetxt.append(filenamein);
2183 msgbox.setText(messagetxt);
2189 msgbox.setFont(*font);
2190 QString messagetxt =
"Invalid Reference Path";
2191 msgbox.setText(messagetxt);
2203void G4OpenInventorQtExaminerViewer::FileSaveRefPathCB()
2207 QFileDialog filedialog(getParentWidget(), tr(
"Save Reference Path"));
2208 filedialog.setFileMode(QFileDialog::AnyFile);
2210 filedialog.setAcceptMode(QFileDialog::AcceptSave);
2211 filedialog.setFont(*font);
2212 if (!filedialog.exec())
return;
2213 QStringList filenameinlist = filedialog.selectedFiles();
2214 QString filenamein = filenameinlist[0];
2216 std::ofstream ofs(qPrintable(filenamein));
2217 if (ofs.is_open()) {
2221 ofs << x <<
" " << y <<
" " << z <<
"\n";
2226 msgbox.setFont(*font);
2227 QString messagetxt =
"Error opening file ";
2228 messagetxt.append(filenamein);
2229 msgbox.setText(messagetxt);
2240 SbVec3f p1, p2, p3, dirNow, dirNxt, dir, p2_tmp, p_start, p_corner, p_nxt;
2241 float avgDistBtwPts = 0;
2242 float totalDistBtwPts = 0;
2243 std::vector<SbVec3f> newRefParticleTrajectory;
2247 for (std::size_t i = 0; i < size; ++i) {
2253 totalDistBtwPts += (p2 - p1).length();
2256 if (numOfPts <= 2)
return;
2258 avgDistBtwPts = totalDistBtwPts / numOfPts;
2259 float minDistAllowed = 0.75 * avgDistBtwPts;
2263 std::size_t i = 0, j = 0;
2269 p1.getValue(x, y, z);
2271 newRefParticleTrajectory.push_back(refPoint);
2274 while ((p2 - p1).length() < minDistAllowed && j < (size - 1)) {
2293 SoCamera *cam = getCamera();
2302 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2304 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
2306 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2308 ((SoOrthographicCamera *) cam)->height.getValue();
2316 SoCamera *cam = getCamera();
2326 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2330 ((SoOrthographicCamera *) cam)->height.setValue(
2333 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2335 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2339 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2342 ((SoOrthographicCamera *) cam)->height.setValue(
2351 SbTime curTime = SbTime::getTimeOfDay();
2354 SoTimerSensor* s = (SoTimerSensor*) sensor;
2356 float t = float((curTime - s->getBaseTime()).getValue())
2359 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2361 SbBool end = (t == 1.0f);
2384 SbTime curTime = SbTime::getTimeOfDay();
2386 SoCamera *cam = This->getCamera();
2387 SoTimerSensor* s = (SoTimerSensor*) sensor;
2389 float t = float((curTime - s->getBaseTime()).getValue())
2392 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2394 SbBool end = (t == 1.0f);
2424 if (SoQtExaminerViewer::isAnimating())
2428 SbVec3f p1{0.0, 0.0, 0.0}, p2{0.0, 0.0, 0.0}, p2_tmp, camUpV, camD, camD_tmp, leftRightAxis;
2429 float x1, y1, z1, x2, y2, z2;
2446 p1.getValue(x1, y1, z1);
2447 p2.getValue(x2, y2, z2);
2452 p2_tmp.setValue(x2, y1, z2);
2453 camD_tmp = p2_tmp - p1;
2454 camD_tmp.normalize();
2456 camUpV.setValue(0, 1, 0);
2457 rot.setValue(camD_tmp, camD);
2458 rot.multVec(camUpV, camUpV);
2460 leftRightAxis = camD.cross(camUpV);
2462 myCam->position = p1;
2463 myCam->pointAt(p2, camUpV);
2467 myCam->position = p1;
2473 myCam->focalDistance = 0.1f;
2479 G4OpenInventorQtExaminerViewer::ToolsRefPathStartCB();
2483void G4OpenInventorQtExaminerViewer::ToolsRefPathStartCB()
2487 msgbox.setFont(*font);
2488 QString messagetxt =
"No current reference path";
2489 msgbox.setText(messagetxt);
2509 if (SoQtExaminerViewer::isAnimating())
2519 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2534 distance = (pN - p1).length() / 10;
2540void G4OpenInventorQtExaminerViewer::ToolsRefPathInvertCB()
2557 SoCamera *cam = getCamera();
2580 escapeCallback = callback;
2608 for (std::size_t i = 0; i < size; ++i) {
2609 new QListWidgetItem(
viewPtList[i].viewPtName,
2621 std::istringstream str(s);
2622 if ((str >> t).fail())
2628G4OpenInventorQtExaminerViewer::FileOpenBookmarkCB()
2632 QFileDialog filedialog(getParentWidget(), tr(
"Open bookmark file"));
2633 filedialog.setFileMode(QFileDialog::ExistingFile);
2634 filedialog.setFont(*font);
2635 if (!filedialog.exec())
return;
2636 QStringList filenameinlist = filedialog.selectedFiles();
2637 QString filenamein = filenameinlist[0];
2640 fileIn.open(qPrintable(filenamein));
2643 msgbox.setFont(*font);
2644 QString messagetxt =
"Error opening file: ";
2645 messagetxt.append(filenamein);
2646 msgbox.setText(messagetxt);
2657 msgbox.setFont(*font);
2658 QString messagetxt =
"Error reading bookmark file: ";
2659 messagetxt.append(filenamein);
2660 msgbox.setText(messagetxt);
2669 fileOut.seekp(0, std::ios::end);
2692 AuxWindowDialog->
lineEdit->setText(QString(
""));
2697G4OpenInventorQtExaminerViewer::FileNewBookmarkCB()
2700 QFileDialog filedialog(getParentWidget(), tr(
"Open new bookmark file"));
2701 filedialog.setFileMode(QFileDialog::AnyFile);
2703 filedialog.setAcceptMode(QFileDialog::AcceptSave);
2705 filedialog.setLabelText(QFileDialog::Accept, QString(
"New"));
2706 filedialog.setFont(*font);
2707 if (!filedialog.exec())
return;
2708 QStringList filenameinlist = filedialog.selectedFiles();
2709 QString filenamein = filenameinlist[0];
2716 msgbox.setFont(*font);
2717 QString messagetxt =
"Error opening new bookmark file: ";
2718 messagetxt.append(filenamein);
2719 msgbox.setText(messagetxt);
2727G4OpenInventorQtExaminerViewer::ToolsAnimateRefParticleCB()
2739 axisSwitch->whichChild.setValue(SO_SWITCH_ALL);
2745 SoCamera *cam = getCamera();
2758 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2768 cam->focalDistance = 0.1f;
2769 ((SoPerspectiveCamera *) cam)->heightAngle = 0.50f;
2776 cam->orientation = (
myCam)->orientation.getValue();
2782G4OpenInventorQtExaminerViewer::SaveViewPtCB()
2791 QInputDialog* inputdialog =
new QInputDialog(getParentWidget());
2792 inputdialog->setFont(*font);
2793 inputdialog->setWindowTitle(tr(
"Enter a name for the bookmark"));
2794 inputdialog->setLabelText(
"Bookmark name");
2796 inputdialog->adjustSize();
2798 if (inputdialog->exec() == QDialog::Accepted)
2799 namein=inputdialog->textValue().trimmed();
2802 if (namein.isEmpty())
return;
2813 char*
name = strdup(qPrintable(namein));
2819 for (
int i = 0; i < (int)
viewPtList.size(); i++) {
2820 if (!strcmp(name,
viewPtList[i].viewPtName)) {
2822 msgbox.setText(
"Bookmark name is already in use");
2832 saveViewPtItem =
new QListWidgetItem(namein,
2834 AuxWindowDialog->
listWidget->setCurrentItem(saveViewPtItem);
2835 AuxWindowDialog->
lineEdit->setText(namein);
2846 float x, y, z, angle;
2847 SoCamera* camera = getCamera();
2862 tmp.
position = camera->position.getValue();
2870 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2871 tmp.
height = ((SoPerspectiveCamera *) camera)->heightAngle.getValue();
2873 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
2874 tmp.
height = ((SoOrthographicCamera *) camera)->height.getValue();
2877 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::saveViewPtCB",
2878 "Only Perspective and Orthographic cameras are supported.");
2888 std::string vpName = name;
2893 fileOut << vpName << std::endl;
2895 fileOut << x <<
" " << y <<
" " << z << std::endl;
2899 axis.getValue(x, y, z);
2900 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
2923 std::stringstream out;
2927 fileOut.seekp(0, std::ios::beg);
2937 fileOut.seekp(0, std::ios::end);
2943void G4OpenInventorQtExaminerViewer::LoadBookmarkCB(QListWidgetItem* item)
2948 for (
int i = 0; i < (int)
viewPtList.size(); i++) {
2949 if (!strcmp(
viewPtList[i].viewPtName, qPrintable(item->text()))) {
2958 AuxWindowDialog->
lineEdit->setText(item->text());
2974 SoCamera * camera = getCamera();
2975 if (camera == NULL) {
2976 G4warn <<
"setViewPt: Camera is null. Unable to set the viewpoint." <<
2985 G4warn <<
"setViewPt: There are no viewpoints to load." <<
G4endl;
2992 if (SoQtExaminerViewer::isAnimating()) stopAnimating();
2998 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
3015 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3018 camera = getCamera();
3019 ((SoOrthographicCamera *) camera)->height.setValue(
3022 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3024 }
else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3027 camera = getCamera();
3028 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3031 ((SoOrthographicCamera *) camera)->height.setValue(
3034 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::setViewPt",
3035 "Only Perspective and Orthographic cameras are supported.");
3042void G4OpenInventorQtExaminerViewer::NextViewPtCB()
3056 AuxWindowDialog->
lineEdit->setText(QString(viewptname));
3059void G4OpenInventorQtExaminerViewer::PrevViewPtCB()
3073 AuxWindowDialog->
lineEdit->setText(QString(viewptname));
3077void G4OpenInventorQtExaminerViewer::AbbrOutputCB(
bool checked)
3086void G4OpenInventorQtExaminerViewer::PickRefPathCB()
3095 setComponentCursor(SoQtCursor(SoQtCursor::CROSSHAIR));
3100void G4OpenInventorQtExaminerViewer::SwitchWireFrameCB(
bool checked)
3107 setDrawStyle(SoQtViewer::STILL, SoQtViewer::VIEW_LINE);
3108 setDrawStyle(SoQtViewer::INTERACTIVE, SoQtViewer::VIEW_LINE);
3110 setDrawStyle(SoQtViewer::STILL, SoQtViewer::VIEW_AS_IS);
3111 setDrawStyle(SoQtViewer::INTERACTIVE,
3112 SoQtViewer::VIEW_SAME_AS_STILL);
3117void G4OpenInventorQtExaminerViewer::SwitchAxesCB(
bool checked)
3121 setFeedbackVisibility(checked);
3130void G4OpenInventorQtExaminerViewer::DetachCB()
3135 viewerParent->setParent(viewerParent2);
3136 removeAppPushButton(detachButton);
3141void G4OpenInventorQtExaminerViewer::DeleteBookmarkCB()
3147 QListWidgetItem* listitem = AuxWindowDialog->
listWidget->currentItem();
3148 if (!listitem)
return;
3149 if (!(listitem->isSelected()))
return;
3151 QString vpnamein = listitem->text();
3153 char* vpName = strdup(qPrintable(vpnamein));
3169 std::ofstream out(
"temporaryFile.txt");
3175 out << line <<
"\n";
3177 while (getline(
fileIn, line)) {
3178 end = line.find_last_not_of(
' ');
3179 line = line.substr(0, end + 1);
3180 if (!strcmp(line.c_str(), vpName)) {
3181 while (line.size()) {
3185 while (getline(
fileIn, line))
3186 out << line <<
"\n";
3188 while (line.size()) {
3189 out << line <<
"\n";
3196 std::size_t idx = 0;
3198 while (idx < size) {
3199 if (!strcmp(
viewPtList[idx].viewPtName, vpName)) {
3212 int istat = remove(
fileName.c_str());
3215 msgbox.setFont(*font);
3216 QString messagetxt =
"Error removing bookmarks file";
3218 msgbox.setText(messagetxt);
3222 istat = rename(
"temporaryFile.txt",
fileName.c_str());
3225 msgbox.setFont(*font);
3226 QString messagetxt =
"Error renaming bookmarks file";
3228 msgbox.setText(messagetxt);
3233 fileOut.seekp(0, std::ios::end);
3247void G4OpenInventorQtExaminerViewer::RenameBookmarkCB()
3252 QListWidgetItem* listitem = AuxWindowDialog->
listWidget->currentItem();
3253 if (!listitem)
return;
3254 if (!(listitem->isSelected()))
return;
3256 QString vpnamein = listitem->text();
3258 QInputDialog* inputdialog =
new QInputDialog(getParentWidget());
3259 inputdialog->setFont(*font);
3260 inputdialog->setWindowTitle(tr(
"Enter"));
3261 inputdialog->setLabelText(
"New bookmark name");
3262 inputdialog->adjustSize();
3264 if (inputdialog->exec() == QDialog::Accepted)
3265 newnamein=inputdialog->textValue().trimmed();
3268 if (newnamein.isEmpty())
return;
3270 char* newname = strdup(qPrintable(newnamein));
3273 for (std::size_t i = 0; i < size; ++i) {
3274 if (!strcmp(newname,
viewPtList[i].viewPtName)) {
3276 msgbox.setFont(*font);
3277 msgbox.setText(
"Bookmark name is already in use");
3284 listitem->setText(QString(newname));
3285 AuxWindowDialog->
lineEdit->setText(newname);
3296 std::size_t idx = 0, end, pos;
3298 std::string line, newName;
3307 while (getline(
fileIn, line)) {
3308 end = line.find_last_not_of(
' ');
3309 line = line.substr(0, end + 1);
3313 fileOut.seekp(0, std::ios::end);
3324 while (idx < size) {
3334void G4OpenInventorQtExaminerViewer::SortBookmarksCB()
3344 std::vector<std::string> charList;
3350 for (
int i = 0; i < (int)
viewPtList.size(); i++) {
3352 charList.push_back(
viewPtList[i].viewPtName);
3356 std::sort(charList.begin(), charList.end());
3362 for (
int i = 0; i < (int)
viewPtList.size(); i++) {
3366 new QListWidgetItem(charList[i].c_str(), AuxWindowDialog->
listWidget);
3379 float x, y, z, angle;
3380 std::size_t sortIdx = 0, unsortIdx = 0;
3389 std::size_t size = sortedViewPts.size();
3390 while (sortIdx < size) {
3391 while (strcmp(sortedViewPts[sortIdx].c_str(),
3395 std::string vpName =
viewPtList[unsortIdx].viewPtName;
3399 fileOut << vpName << std::endl;
3400 viewPtList[unsortIdx].position.getValue(x, y, z);
3401 fileOut << x <<
" " << y <<
" " << z << std::endl;
3404 viewPtList[unsortIdx].orientation.getValue(axis, angle);
3405 axis.getValue(x, y, z);
3406 fileOut << x <<
" " << y <<
" " << z <<
" " << angle << std::endl;
3409 <<
viewPtList[unsortIdx].height << std::endl;
3432 float multiplicator = float(std::exp(diffvalue));
3433 SoCamera *cam = getCamera();
3435 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3436 const float oldfocaldist = cam->focalDistance.getValue();
3437 const float newfocaldist = oldfocaldist * multiplicator;
3440 cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
3442 const SbVec3f oldpos = cam->position.getValue();
3443 const SbVec3f newpos = oldpos + (newfocaldist - oldfocaldist) * -direction;
3444 cam->position = newpos;
3445 cam->focalDistance = newfocaldist;
3446 }
else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
3447 SoOrthographicCamera * oc = (SoOrthographicCamera *)cam;
3448 oc->height = oc->height.getValue() * multiplicator;
3462 SoCamera *cam = getCamera();
3463 const SoType type(ev->getTypeId());
3468 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
3469 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
3474 switch (me->getButton()) {
3476 case SoMouseButtonEvent::BUTTON4:
3477 if (me->getState() == SoButtonEvent::DOWN) {
3484 case SoMouseButtonEvent::BUTTON5:
3485 if (me->getState() == SoButtonEvent::DOWN) {
3502 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
3503 SoKeyboardEvent* ke = (SoKeyboardEvent*)ev;
3505 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
3506 switch (ke->getKey()) {
3507 case SoKeyboardEvent::E:
3508 if (externalQtApp) {
3513 "E KEY PRESSED, EXITING OIQT VIEWER SECONDARY LOOP" <<
3515 SoQt::exitMainLoop();
3519 case SoKeyboardEvent::LEFT_SHIFT:
3520 this->lshiftdown =
true;
3522 case SoKeyboardEvent::RIGHT_SHIFT:
3523 this->rshiftdown =
true;
3525 case SoKeyboardEvent::LEFT_CONTROL:
3526 this->lctrldown =
true;
3528 case SoKeyboardEvent::RIGHT_CONTROL:
3529 this->rctrldown =
true;
3531 case SoKeyboardEvent::SPACE:
3553 case SoKeyboardEvent::ESCAPE:
3569 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
3580 case SoKeyboardEvent::DELETE:
3592 case SoKeyboardEvent::LEFT_ARROW:
3595 if ((this->lshiftdown) || (this->rshiftdown)) {
3599 else if ((this->lctrldown) || (this->rctrldown)) {
3600 if (SoQtExaminerViewer::isAnimating())
3615 if (SoQtExaminerViewer::isAnimating())
3639 cam->position =
myCam->position;
3643 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3646 this->bottomWheelMotion(
3647 this->getBottomWheelValue() + 0.1f);
3657 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3658 "Unhandled viewer state");
3663 case SoKeyboardEvent::RIGHT_ARROW:
3666 if ((this->lshiftdown) || (this->rshiftdown)) {
3670 else if ((this->lctrldown) || (this->rctrldown)) {
3671 if (SoQtExaminerViewer::isAnimating())
3684 if (SoQtExaminerViewer::isAnimating())
3705 cam->position =
myCam->position;
3709 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3712 this->bottomWheelMotion(
3713 this->getBottomWheelValue() - 0.1f);
3722 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3723 "Unhandled viewer state");
3728 case SoKeyboardEvent::DOWN_ARROW:
3732 if ((this->lshiftdown) || (this->rshiftdown)) {
3737 if (SoQtExaminerViewer::isAnimating())
3759 cam->position =
myCam->position;
3765 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3766 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
3775 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3776 "Unhandled viewer state");
3781 case SoKeyboardEvent::UP_ARROW:
3784 if ((this->lshiftdown) || (this->rshiftdown)) {
3789 if (SoQtExaminerViewer::isAnimating())
3812 cam->position =
myCam->position;
3818 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3819 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
3828 SoDebugError::post(
"G4OpenInventorQtExaminerViewer::processSoEvent",
3829 "Unhandled viewer state");
3834 case SoKeyboardEvent::PAGE_UP:
3885 case SoKeyboardEvent::PAGE_DOWN:
3942 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
3943 switch (ke->getKey()) {
3944 case SoKeyboardEvent::LEFT_SHIFT:
3945 this->lshiftdown =
false;
3947 case SoKeyboardEvent::RIGHT_SHIFT:
3948 this->rshiftdown =
false;
3950 case SoKeyboardEvent::LEFT_CONTROL:
3951 this->lctrldown =
false;
3953 case SoKeyboardEvent::RIGHT_CONTROL:
3954 this->rctrldown =
false;
3969 return SoQtExaminerViewer::processSoEvent(ev);
3976void G4OpenInventorQtExaminerViewer::FileLoadSceneGraphCB()
3980 QFileDialog filedialog(getParentWidget(), tr(
"Load Scene Graph"));
3981 filedialog.setFileMode(QFileDialog::AnyFile);
3982 filedialog.setFont(*font);
3983 if (!filedialog.exec())
return;
3984 QStringList filenameinlist = filedialog.selectedFiles();
3985 QString filenamein = filenameinlist[0];
3989 if (sceneInput.openFile(qPrintable(filenamein))) {
3994 msgbox.setFont(*font);
3995 QString messagetxt =
"Error reading scene graph file ";
3996 messagetxt.append(filenamein);
3997 msgbox.setText(messagetxt);
3999 sceneInput.closeFile();
4004 msgbox.setFont(*font);
4005 QString messagetxt =
"Error opening scene graph file ";
4006 messagetxt.append(filenamein);
4007 msgbox.setText(messagetxt);
4012 SoSeparator* root = (SoSeparator*)getSceneGraph();
4018void G4OpenInventorQtExaminerViewer::FileSaveSceneGraphCB()
4022 QFileDialog filedialog(getParentWidget(), tr(
"Save scene graph"));
4023 filedialog.setFileMode(QFileDialog::AnyFile);
4025 filedialog.setAcceptMode(QFileDialog::AcceptSave);
4026 filedialog.setFont(*font);
4027 if (!filedialog.exec())
return;
4028 QStringList filenameinlist = filedialog.selectedFiles();
4029 QString filenamein = filenameinlist[0];
4031 SoWriteAction writeAction;
4032 SoSeparator* root = (SoSeparator*)getSceneGraph();
4034 SoOutput* out = writeAction.getOutput();
4036 if (out->openFile(qPrintable(filenamein))) {
4037 out->setBinary(
FALSE);
4038 writeAction.apply(root);
4042 msgbox.setFont(*font);
4043 QString messagetxt =
"Error opening file ";
4044 messagetxt.append(filenamein);
4045 msgbox.setText(messagetxt);
4051void 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