Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenInventorXtExaminerViewer Class Reference

#include <G4OpenInventorXtExaminerViewer.hh>

+ Inheritance diagram for G4OpenInventorXtExaminerViewer:

Public Member Functions

 G4OpenInventorXtExaminerViewer (Widget parent=NULL, const char *name=NULL, SbBool embed=TRUE, SoXtFullViewer::BuildFlag flag=BUILD_ALL, SoXtViewer::Type type=BROWSER)
 
 ~G4OpenInventorXtExaminerViewer ()
 
template<class T >
void parseString (T &t, const std::string &s, bool &error)
 
Widget addMenu (std::string name)
 
void addButton (Widget menu, std::string name, XtCallbackProc)
 
Widget getMenuBar ()
 
Widget getMenu ()
 
void warningMsgDialog (std::string, String, XtCallbackProc)
 
Widget createScale (Widget, char *, int, float)
 
void addEscapeCallback (void(*cb)(void *), void *)
 

Public Attributes

bool warningFlag
 
std::string saveScenegraphFileName
 
Widget saveScenegraphWidget
 
std::string saveRefCoordsFileName
 
Widget saveRefCoordsWidget
 
bool abbrOutputFlag
 
bool pickRefPathFlag
 
bool viewingBeforePickRef
 

Protected Member Functions

 G4OpenInventorXtExaminerViewer (Widget parent, const char *name, SbBool embed, SoXtFullViewer::BuildFlag flag, SoXtViewer::Type type, SbBool build)
 
Widget buildWidget (Widget parent)
 
virtual void createViewerButtons (Widget parent, SbPList *buttonlist)
 
virtual SbBool processSoEvent (const SoEvent *const event)
 
void moveCamera (float dist=0, bool lookdown=false)
 
void rotateCamera ()
 
void updateViewParams (SoKeyboardEvent::Key)
 
bool loadViewPts ()
 
virtual void afterRealizeHook ()
 

Protected Attributes

std::string curEltName
 
SbVec3f camUpVec
 
SbVec3f camDir
 

Friends

class HookEventProcState
 

Detailed Description

Definition at line 63 of file G4OpenInventorXtExaminerViewer.hh.

Constructor & Destructor Documentation

◆ G4OpenInventorXtExaminerViewer() [1/2]

G4OpenInventorXtExaminerViewer::G4OpenInventorXtExaminerViewer ( Widget  parent = NULL,
const char *  name = NULL,
SbBool  embed = TRUE,
SoXtFullViewer::BuildFlag  flag = BUILD_ALL,
SoXtViewer::Type  type = BROWSER 
)

Definition at line 122 of file G4OpenInventorXtExaminerViewer.cc.

124 :
125 SoXtExaminerViewer(parent, name, embed, flag, type, FALSE)
126{
127// Tell GLWidget not to build just yet
128 this->constructor(TRUE);
129}
#define TRUE
Definition: globals.hh:55
#define FALSE
Definition: globals.hh:52

◆ ~G4OpenInventorXtExaminerViewer()

G4OpenInventorXtExaminerViewer::~G4OpenInventorXtExaminerViewer ( )

Definition at line 577 of file G4OpenInventorXtExaminerViewer.cc.

578{
579 if (superimposition != NULL) {
580 removeSuperimposition(superimposition);
581 superimposition->unref();
582 superimposition = NULL;
583 }
584 if (animateSensor->isScheduled())
585 animateSensor->unschedule();
586 delete animateSensor;
587 delete sceneChangeSensor;
588
589 delete[] curViewPtName;
590 delete searcher;
591
592 viewer = 0;
593}

◆ G4OpenInventorXtExaminerViewer() [2/2]

G4OpenInventorXtExaminerViewer::G4OpenInventorXtExaminerViewer ( Widget  parent,
const char *  name,
SbBool  embed,
SoXtFullViewer::BuildFlag  flag,
SoXtViewer::Type  type,
SbBool  build 
)
protected

Definition at line 132 of file G4OpenInventorXtExaminerViewer.cc.

135 :
136 SoXtExaminerViewer(parent, name, embed, flag, type, FALSE)
137{
138 this->constructor(build);
139}

Member Function Documentation

◆ addButton()

void G4OpenInventorXtExaminerViewer::addButton ( Widget  menu,
std::string  name,
XtCallbackProc  cb 
)

Definition at line 668 of file G4OpenInventorXtExaminerViewer.cc.

670{
671 Widget button = XmCreatePushButton(menu, (char *) name.c_str(), NULL, 0);
672 XtManageChild(button);
673 XtAddCallback(button, XmNactivateCallback, cb, this);
674}

Referenced by buildWidget().

◆ addEscapeCallback()

void G4OpenInventorXtExaminerViewer::addEscapeCallback ( void(*)(void *)  cb,
void *  object 
)

Definition at line 4703 of file G4OpenInventorXtExaminerViewer.cc.

4705{
4706 this->escapeCallback = callback;
4707 this->examinerObject = object;
4708}

◆ addMenu()

Widget G4OpenInventorXtExaminerViewer::addMenu ( std::string  name)

Definition at line 654 of file G4OpenInventorXtExaminerViewer.cc.

655{
656 Arg args[1];
657 Widget menu = XmCreatePulldownMenu(menuBar, (char *) name.c_str(), NULL, 0);
658
659 XtSetArg(args[0], XmNsubMenuId, menu);
660 Widget w = XmCreateCascadeButton(menuBar, (char *) name.c_str(), args, 1);
661 XtManageChild(w);
662
663 return menu;
664}

Referenced by buildWidget().

◆ afterRealizeHook()

void G4OpenInventorXtExaminerViewer::afterRealizeHook ( )
protectedvirtual

Definition at line 773 of file G4OpenInventorXtExaminerViewer.cc.

774{
775 SoXtExaminerViewer::afterRealizeHook();
776
777 // Default height is used when selecting and viewing scene elements
778 // FWJ Added defaultHeight for Ortho camera
779 SoCamera *cam = getCamera();
780 if (cam) {
781 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
782 defaultHeightAngle =
783 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
784 toggleCameraType();
785 defaultHeight =
786 ((SoOrthographicCamera *) cam)->height.getValue();
787 toggleCameraType();
788 } else {
789 defaultHeight =
790 ((SoOrthographicCamera *) cam)->height.getValue();
791 toggleCameraType();
792 cam = getCamera();
793 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
794 defaultHeightAngle =
795 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
796 toggleCameraType();
797 }
798 }
799
800 // Open the default bookmark file
801 fileIn.open(fileName.c_str());
802 if (!fileIn.fail()) {
803 if (!loadViewPts()) {
804 String dialogName = (char *) "Error Loading File";
805 std::string msg = "Wrong or corrupted input file.";
806 warningMsgDialog(msg, dialogName, NULL);
807 } else {
808 // Opens a file without erasing it
809 fileOut.open(fileName.c_str(), std::ios::in);
810 fileOut.seekp(0, std::ios::end); // For appending new data to the end
811 constructListsDialog(getParentWidget(), this, NULL); // Pop up listsDialog
812
813 if (viewPtList.size()) {
814 // FWJ disabled auto-selection of first viewpoint.
815 // Initial view should be user-controllable & not forced
816 // setViewPt();
817 XtSetSensitive(nextViewPtButton, True);
818 XtSetSensitive(prevViewPtButton, True);
819 }
820 }
821
822 fileIn.close();
823 } else {
824 // Creates a new default bookmark file
825 fileOut.open(fileName.c_str());
826 constructListsDialog(getParentWidget(), this, NULL); // Pop up listsDialog
827 }
828
829 fileIn.clear();
830
831 SoSeparator *root = (SoSeparator *) (getSceneManager()->getSceneGraph());
832 if (root == NULL)
833 SoDebugError::post("G4OpenInventorXtExaminerViewer::afterRealizeHook", "Root is null.");
834 else {
835 root->addChild(myCam); // For position/orientation calculation during animation
836 }
837
838 sceneChangeSensor = new SoNodeSensor;
839 sceneChangeSensor->setFunction(sceneChangeCB);
840 sceneChangeSensor->attach(root);
841 sceneChangeSensor->setData(this);
842
843 // Monitor mouseover events for displaying the name of scene elements
844 // An SoEventCallback is needed instead of using the default processSoEvent
845 // because that last one does not provide us with an SoPath to the object
846 // that was picked
847 SoEventCallback *moCB = new SoEventCallback;
848 moCB->addEventCallback(
849 SoLocation2Event::getClassTypeId(),
850 mouseoverCB, static_cast<void *>(this));
851 root->addChild(moCB);
852
853 // Override the default picking mechanism present in G4OpenInventorViewer
854 // because we want abbreviated output when picking a trajectory
855 SoEventCallback *pickCB = new SoEventCallback;
856 pickCB->addEventCallback(
857 SoMouseButtonEvent::getClassTypeId(),
858 pickingCB, static_cast<void *>(this));
859 root->addChild(pickCB);
860
861}
void warningMsgDialog(std::string, String, XtCallbackProc)

◆ buildWidget()

Widget G4OpenInventorXtExaminerViewer::buildWidget ( Widget  parent)
protected

Definition at line 597 of file G4OpenInventorXtExaminerViewer.cc.

598{
599 Widget shell;
600 Atom WM_DELETE_WINDOW;
601
602 if (!parent)
603 SoDebugError::post("G4OpenInventorXtExaminerViewer::buildWidget", "Error: Parent is null.");
604
605 Arg args[10];
606 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
607 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
608 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
609 XtSetArg(args[3], XmNbottomAttachment, XmATTACH_FORM);
610 Widget form = XmCreateForm(parent, (char *) "Form", args, 4);
611 XtManageChild(form);
612
613 shell = XtParent(form);
614 WM_DELETE_WINDOW = XInternAtom(XtDisplay(parent), "WM_DELETE_WINDOW",
615 False);
616 XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW,
617 (XtCallbackProc)closeMainWindowCB, this);
618
619 XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
620 XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
621 XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
622 menuBar = XmCreateMenuBar(form, (char *) "MenuBar", args, 3);
623 XtManageChild(menuBar);
624
625 fileMenu = addMenu("File");
626 this->addButton(fileMenu, "Open Viewpoint File...", openViewPtFileCB);
627 addButton(fileMenu, "New Viewpoint File", newViewPtFileCB);
628 addButton(fileMenu, "Load Ref. Coords", loadRefCoordsDialogCB);
629 addButton(fileMenu, "Save Ref. Coords", saveRefCoordsDialogCB);
630 addButton(fileMenu, "Load Scene Graph", loadSceneGraphDialogCB);
631 addButton(fileMenu, "Save Scene Graph", saveSceneGraphDialogCB);
632 XtManageChild(
633 XmCreateSeparatorGadget(fileMenu, (char *) "Separator", NULL, 0));
634
635 Widget menu = addMenu("Tools");
636 addButton(menu, "Animate Ref. Particle", animateRefParticleCB);
637 addButton(menu, "Go to start of Ref path", gotoRefPathStartCB);
638 addButton(menu, "Invert Ref path", invertRefPathCB);
639
640 Widget viewerBase = SoXtFullViewer::buildWidget(form);
641
642 XtSetArg(args[0], XmNtopAttachment, XmATTACH_WIDGET);
643 XtSetArg(args[1], XmNtopWidget, menuBar);
644 XtSetArg(args[2], XmNleftAttachment, XmATTACH_FORM);
645 XtSetArg(args[3], XmNrightAttachment, XmATTACH_FORM);
646 XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM);
647 XtSetValues(viewerBase, args, 5);
648
649 return viewerBase;
650}
void addButton(Widget menu, std::string name, XtCallbackProc)

◆ createScale()

Widget G4OpenInventorXtExaminerViewer::createScale ( Widget  ,
char *  ,
int  ,
float   
)

◆ createViewerButtons()

void G4OpenInventorXtExaminerViewer::createViewerButtons ( Widget  parent,
SbPList *  buttonlist 
)
protectedvirtual

Definition at line 678 of file G4OpenInventorXtExaminerViewer.cc.

680{
681 int n;
682 Arg args[6];
683 Widget saveViewPtButton, abbrOutputButton, pickRefPathButton;
684
685 // Create original buttons
686 SoXtExaminerViewer::createViewerButtons(parent, buttonlist);
687
688 // Handle disappearing button caused by SoXtExaminerViewer::setCamera
689 Widget emptyButton = XtVaCreateManagedWidget("", xmPushButtonWidgetClass,
690 parent, NULL);
691 buttonlist->append(emptyButton);
692
693 // Left arrow that goes back one view point on click
694 n = 0;
695 XtSetArg(args[n], XmNtopPosition, 1); n++;
696 XtSetArg(args[n], XmNbottomPosition, 2); n++;
697 XtSetArg(args[n], XmNleftPosition, 0); n++;
698 XtSetArg(args[n], XmNrightPosition, 1); n++;
699 XtSetArg(args[n], XmNarrowDirection, XmARROW_LEFT); n++;
700 XtSetArg(args[n], XmNsensitive, False); n++;
701 prevViewPtButton = XmCreateArrowButtonGadget(parent, (char *) "ArrowL",
702 args, n);
703 XtManageChild(prevViewPtButton);
704 XtAddCallback(prevViewPtButton, XmNactivateCallback,
705 G4OpenInventorXtExaminerViewer::prevViewPtCB, this);
706 buttonlist->append(prevViewPtButton);
707
708 // Right arrow that goes forward one view point on click
709 n = 0;
710 XtSetArg(args[n], XmNtopPosition, 1); n++;
711 XtSetArg(args[n], XmNbottomPosition, 2); n++;
712 XtSetArg(args[n], XmNleftPosition, 0); n++;
713 XtSetArg(args[n], XmNrightPosition, 1); n++;
714 XtSetArg(args[n], XmNarrowDirection, XmARROW_RIGHT); n++;
715 XtSetArg(args[n], XmNsensitive, False); n++;
716 nextViewPtButton = XmCreateArrowButtonGadget(parent, (char *) "ArrowR",
717 args, n);
718 XtManageChild(nextViewPtButton);
719 XtAddCallback(nextViewPtButton, XmNactivateCallback,
720 G4OpenInventorXtExaminerViewer::nextViewPtCB, this);
721 buttonlist->append(nextViewPtButton);
722
723 // Save button for storing current camera parameters
724 saveViewPtButton = XtVaCreateManagedWidget("Save", xmPushButtonWidgetClass,
725 parent, NULL);
726 XtAddCallback(saveViewPtButton, XmNactivateCallback,
727 G4OpenInventorXtExaminerViewer::saveViewPtCB, this);
728 Pixmap saveVP, saveVP_ins;
729 saveVP = SoXtInternal::createPixmapFromXpm(saveViewPtButton,
730 saveViewPt_xpm);
731 saveVP_ins = SoXtInternal::createPixmapFromXpm(saveViewPtButton,
732 saveViewPt_xpm, TRUE);
733 XtVaSetValues(saveViewPtButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
734 saveVP, XmNselectPixmap, saveVP, XmNlabelInsensitivePixmap,
735 saveVP_ins, XmNselectInsensitivePixmap, saveVP_ins, NULL);
736 buttonlist->append(saveViewPtButton);
737
738 // Toggle button to get abbreviated output
739 abbrOutputButton = XtVaCreateManagedWidget("Abbr",
740 xmToggleButtonWidgetClass, parent, XmNindicatorOn, False, NULL);
741 XtAddCallback(abbrOutputButton, XmNdisarmCallback, G4OpenInventorXtExaminerViewer::abbrOutputCB,
742 this);
743 Pixmap consolexpm, consolexpm_ins;
744 consolexpm = SoXtInternal::createPixmapFromXpm(abbrOutputButton,
745 console_xpm);
746 consolexpm_ins = SoXtInternal::createPixmapFromXpm(abbrOutputButton,
747 console_xpm, TRUE);
748 XtVaSetValues(abbrOutputButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
749 consolexpm, XmNselectPixmap, consolexpm, XmNlabelInsensitivePixmap,
750 consolexpm_ins, XmNselectInsensitivePixmap, consolexpm_ins, NULL);
751 buttonlist->append(abbrOutputButton);
752
753 // Button for selecting the beam that will act as reference path
754 pickRefPathButton = XtVaCreateManagedWidget("Refpath", xmPushButtonWidgetClass,
755 parent, NULL);
756 XtAddCallback(pickRefPathButton, XmNactivateCallback,
757 G4OpenInventorXtExaminerViewer::pickRefPathCB, this);
758 Pixmap favoritesxpm, favoritesxpm_ins;
759 favoritesxpm = SoXtInternal::createPixmapFromXpm(pickRefPathButton,
760 favorites_xpm);
761 favoritesxpm_ins = SoXtInternal::createPixmapFromXpm(pickRefPathButton,
762 favorites_xpm, TRUE);
763 XtVaSetValues(pickRefPathButton, XmNlabelType, XmPIXMAP, XmNlabelPixmap,
764 favoritesxpm, XmNselectPixmap, favoritesxpm, XmNlabelInsensitivePixmap,
765 favoritesxpm_ins, XmNselectInsensitivePixmap, favoritesxpm_ins, NULL);
766 buttonlist->append(pickRefPathButton);
767
768}
static Pixmap createPixmapFromXpm(Widget button, const char **xpm, SbBool ghost=FALSE)

◆ getMenu()

Widget G4OpenInventorXtExaminerViewer::getMenu ( )
inline

Definition at line 90 of file G4OpenInventorXtExaminerViewer.hh.

90{ return fileMenu; }

◆ getMenuBar()

Widget G4OpenInventorXtExaminerViewer::getMenuBar ( )
inline

Definition at line 89 of file G4OpenInventorXtExaminerViewer.hh.

89{ return menuBar; }

◆ loadViewPts()

bool G4OpenInventorXtExaminerViewer::loadViewPts ( )
protected

Definition at line 3301 of file G4OpenInventorXtExaminerViewer.cc.

3302{
3303 bool error = false;
3304 viewPtData tmp;
3305 std::string token;
3306 SbVec3f axis;
3307 SbRotation orient;
3308 float x, y, z, angle;
3309
3310 // Gets the last view point accessed, stored in the first line of the data file.
3311 fileIn >> token;
3312 parseString<int>(viewPtIdx, token, error);
3313 getline(fileIn, token); // Remove "\n"
3314 // Converts data from string type into necessary types
3315 while (getline(fileIn, token)) {
3316
3317 int end = token.find_last_not_of(' '); // Remove padded spaces
3318 token = token.substr(0, end + 1);
3319
3320 char *vpName = new char[token.size() + 1];
3321 strcpy(vpName, token.c_str());
3322 tmp.viewPtName = vpName;
3323 fileIn >> token;
3324
3325 parseString<float>(x, token, error);
3326 fileIn >> token;
3327 parseString<float>(y, token, error);
3328 fileIn >> token;
3329 parseString<float>(z, token, error);
3330 fileIn >> token;
3331 tmp.position = axis.setValue(x, y, z);
3332
3333 parseString<float>(x, token, error);
3334 fileIn >> token;
3335 parseString<float>(y, token, error);
3336 fileIn >> token;
3337 parseString<float>(z, token, error);
3338 fileIn >> token;
3339 parseString<float>(angle, token, error);
3340 fileIn >> token;
3341 orient.setValue(axis.setValue(x, y, z), angle);
3342 tmp.orientation = orient.getValue();
3343
3344 int camType;
3345 parseString<int>(camType, token, error);
3346 fileIn >> token;
3347 tmp.camType = (CameraType) camType;
3348
3349 parseString<float>(tmp.height, token, error);
3350 fileIn >> token;
3351 parseString<float>(tmp.focalDistance, token, error);
3352 fileIn >> token;
3353 parseString<float>(tmp.nearDistance, token, error);
3354 fileIn >> token;
3355 parseString<float>(tmp.farDistance, token, error);
3356 fileIn >> token;
3357 parseString<int>(tmp.viewportMapping, token, error);
3358 fileIn >> token;
3359 parseString<float>(tmp.aspectRatio, token, error);
3360
3361 getline(fileIn, token); // To remove "\n" characters
3362 getline(fileIn, token);
3363
3364 if (error) {
3365 viewPtIdx = 0;
3366 viewPtList.clear();
3367 return false;
3368 }
3369 viewPtList.push_back(tmp);
3370 }
3371
3372 return true;
3373}

Referenced by afterRealizeHook().

◆ moveCamera()

void G4OpenInventorXtExaminerViewer::moveCamera ( float  dist = 0,
bool  lookdown = false 
)
protected

Definition at line 893 of file G4OpenInventorXtExaminerViewer.cc.

894{
895
896 SoCamera *cam = getCamera();
897 SbVec3f p1, p2; // The particle moves from p1 to p2
898 SbVec3f particleDir; // Direction vector from p1 to p2
899 SbVec3f camPosNew; // New position of the camera
900
901 if(refParticleTrajectory.size() == 0) {
902 //refParticleTrajectory hasn't been set yet
903 if(dist)
904 distance = dist;
905 else
906 distance = (cam->position.getValue() - center).length();
907
908 cam->position.setValue(center + offsetFromCenter*distance);
909 cam->focalDistance = (cam->position.getValue() - center).length();
910 cam->pointAt(center, upVector);
911 }
912 else{
913
914 // If we move forward past the last trajectory point,
915 // go back to the beginning
916 if (refParticleIdx >= (int) refParticleTrajectory.size() - 1) {
917 prevPt = refParticleTrajectory[refParticleIdx - step];
918 dist = (prevPt - cam->position.getValue()).length();
919 refParticleIdx = 0;
920 }
921 // If we move backward past the beginning,
922 // go to the last trajectory point
923 if (refParticleIdx < 0) {
924 prevPt = refParticleTrajectory[refParticleIdx + step];
925 dist = (prevPt - cam->position.getValue()).length();
926 refParticleIdx = refParticleTrajectory.size() - 2;
927 }
928
929 // Set start and end points
930 p1 = refParticleTrajectory[refParticleIdx];
931 p2 = refParticleTrajectory[refParticleIdx + step];
932
933 // Get the direction from p1 to p2
934 particleDir = p2 - p1;
935 particleDir.normalize();
936
937 if(prevParticleDir == SbVec3f(0,0,0)){
938 // First time entering BEAMLINE mode, look at
939 // the element from the front, with camera upright
940 if(lookdown)
941 camDir = SbVec3f(0,0,1);
942 else
943 camDir = SbVec3f(1,0,0);
944 camUpVec = SbVec3f(0,1,0);
945
946 // In case the start of the goes in a
947 // direction other than +z, rotate the camera accordingly
948 SbRotation rot(SbVec3f(0,0,1), particleDir);
949 rot.multVec(camDir, camDir);
950 rot.multVec(camUpVec, camUpVec);
951
952 }
953 else if(particleDir != prevParticleDir) {
954 // The beamline has changed direction
955
956 SbRotation rot(prevParticleDir, particleDir);
957 rot.multVec(camDir, camDir);
958 rot.multVec(camUpVec, camUpVec);
959
960 }
961
962 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
963 if (!dist)
964 distance = (prevPt - cam->position.getValue()).length();
965 else
966 distance = dist;
967 }
968
969 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
970 if (!dist)
971 distance = (prevPt - cam->position.getValue()).length();
972 else
973 distance = dist;
974 }
975
976
977 float x,y,z;
978 prevPt.getValue(x,y,z);
979
980
981 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
982 camPosNew = p2 - (camDir*distance);
983 }
984 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
985 camPosNew = p2 - (camDir);
986 }
987
988 cam->position = camPosNew;
989 cam->pointAt(p2, camUpVec);
990 // FWJ Disabled: zooms out the Persp camera much too far
991 // and can't recover by zooming in!
992 // cam->focalDistance = (p2 - camPosNew).length();
993
994 p2.getValue(x,y,z);
995 camPosNew.getValue(x,y,z);
996
997 prevParticleDir = particleDir;
998 prevPt = p1; // For accurate distance calculation
999
1000 }
1001
1002}

Referenced by processSoEvent().

◆ parseString()

template<class T >
void G4OpenInventorXtExaminerViewer::parseString ( T &  t,
const std::string &  s,
bool &  error 
)

Definition at line 3379 of file G4OpenInventorXtExaminerViewer.cc.

3381{
3382 std::istringstream str(s);
3383 if ((str >> t).fail())
3384 error = true;
3385}

◆ processSoEvent()

SbBool G4OpenInventorXtExaminerViewer::processSoEvent ( const SoEvent *const  event)
protectedvirtual

Definition at line 1256 of file G4OpenInventorXtExaminerViewer.cc.

1256 {
1257 SoCamera *cam = getCamera();
1258 const SoType type(ev->getTypeId());
1259
1260 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
1261 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
1262
1263 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1264 || currentState == PAUSED_ANIMATION) {
1265 switch (me->getButton()) {
1266 case SoMouseButtonEvent::BUTTON4: // Scroll wheel up
1267 if (me->getState() == SoButtonEvent::DOWN) {
1268 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1269 float hAngle =
1270 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1271 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1272 + 0.01f;
1273 return TRUE;
1274 } else if (cam->isOfType(
1275 SoOrthographicCamera::getClassTypeId())) {
1276 float height =
1277 ((SoOrthographicCamera *) cam)->height.getValue();
1278 ((SoOrthographicCamera *) cam)->height = height + 5;
1279 return TRUE;
1280 }
1281 }
1282 break;
1283 case SoMouseButtonEvent::BUTTON5: // Scroll wheel down
1284 if (me->getState() == SoButtonEvent::DOWN) {
1285 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1286 float hAngle =
1287 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
1288 if (hAngle > 0.01)
1289 ((SoPerspectiveCamera *) cam)->heightAngle = hAngle
1290 - 0.01f;
1291 return TRUE;
1292 } else if (cam->isOfType(
1293 SoOrthographicCamera::getClassTypeId())) {
1294 float height =
1295 ((SoOrthographicCamera *) cam)->height.getValue();
1296 if (height > 5)
1297 ((SoOrthographicCamera *) cam)->height = height - 5;
1298 return TRUE;
1299 }
1300 }
1301 break;
1302 default:
1303 break;
1304 }
1305 }
1306 if (currentState == GENERAL) {
1307
1308 }
1309 }
1310
1311 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
1312 SoKeyboardEvent * ke = (SoKeyboardEvent *) ev;
1313
1314 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
1315 switch (ke->getKey()) {
1316 case SoKeyboardEvent::LEFT_SHIFT:
1317 this->lshiftdown = true;
1318 return TRUE;
1319 case SoKeyboardEvent::RIGHT_SHIFT:
1320 this->rshiftdown = true;
1321 return TRUE;
1322 case SoKeyboardEvent::LEFT_CONTROL:
1323 this->lctrldown = true;
1324 return TRUE;
1325 case SoKeyboardEvent::RIGHT_CONTROL:
1326 this->rctrldown = true;
1327 return TRUE;
1328 case SoKeyboardEvent::SPACE:
1329 if (currentState == ANIMATION
1330 || currentState == REVERSED_ANIMATION) {
1331 beforePausing = currentState;
1332 currentState = PAUSED_ANIMATION;
1333 if (animateSensor->isScheduled())
1334 animateSensor->unschedule();
1335 return TRUE;
1336 } else if (currentState == PAUSED_ANIMATION) {
1337 if (maxSpeed) {
1338 if ((beforePausing == ANIMATION
1339 && refParticleIdx
1340 < (int) refParticleTrajectory.size() - 1)
1341 || (beforePausing == REVERSED_ANIMATION
1342 && refParticleIdx > 0)) {
1343 currentState = beforePausing;
1344 animateRefParticle();
1345 }
1346 }
1347 return TRUE;
1348 }
1349 break;
1350 case SoKeyboardEvent::ESCAPE:
1351 if (currentState == ANIMATION
1352 || currentState == REVERSED_ANIMATION
1353 || currentState == PAUSED_ANIMATION) {
1354
1355 if (animateSensor->isScheduled())
1356 animateSensor->unschedule();
1357 currentState = prevState;
1358 refParticleIdx = prevRefIdx;
1359 setSuperimpositionEnabled(superimposition, FALSE);
1360 maxSpeed = 0.0f;
1361 step = 1;
1362
1363 scheduleRedraw();
1364 if (currentState == VIEWPOINT) {
1365 setSuperimpositionEnabled(superimposition, TRUE);
1366 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
1367 animSpeedOutlineSwitch->whichChild.setValue(
1368 SO_SWITCH_NONE);
1369 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1370
1371 scheduleRedraw();
1372 }
1373 restoreCamera();
1374 return TRUE;
1375 }
1376 break;
1377 case SoKeyboardEvent::DELETE:
1378 if (viewPtList.size()
1379 && (currentState != ANIMATION
1380 || currentState != REVERSED_ANIMATION
1381 || currentState != PAUSED_ANIMATION)) {
1382 String dialogName = (char *) "Delete Viewpoint";
1383 std::string msg = "Are you sure you want to delete current viewpoint?";
1384 warningMsgDialog(msg, dialogName, deleteViewPtCB);
1385 return TRUE;
1386 }
1387 break;
1388 case SoKeyboardEvent::LEFT_ARROW:
1389 switch (currentState) {
1390 case BEAMLINE:
1391 if ((this->lshiftdown) || (this->rshiftdown)){
1392 refParticleIdx -= step;
1393 moveCamera();
1394 }
1395 else if ((this->lctrldown) || (this->rctrldown)){
1396 if (SoXtExaminerViewer::isAnimating())
1397 stopAnimating();
1398 prevState = currentState;
1399 currentState = ROTATING;
1400 animateBtwPtsPeriod = 0.08f;
1401
1402 SbVec3f tmp = camDir;
1403 tmp.negate();
1404 rotAxis = tmp;
1405
1406 rotCnt = ROT_CNT;
1407 moveCamera(); // To make sure camera is perpendicular to the beamline
1408
1409 rotateCamera();
1410 }
1411 else{
1412 if (SoXtExaminerViewer::isAnimating())
1413 stopAnimating();
1414 prevState = currentState;
1415 currentState = ROTATING;
1416 animateBtwPtsPeriod = 0.08f;
1417
1418 SbVec3f tmp = camUpVec;
1419 tmp.negate();
1420 rotAxis = tmp;
1421
1422 rotCnt = ROT_CNT;
1423 moveCamera(); // To make sure camera is perpendicular to the beamline
1424
1425 rotateCamera();
1426
1427 }
1428 return TRUE;
1429
1430 case ANIMATION:
1431 case REVERSED_ANIMATION:
1432 left_right -= 1.5f;
1433 return TRUE;
1434 case PAUSED_ANIMATION:
1435 left_right -= 1.5f;
1436 setStartingPtForAnimation();
1437 cam->position = myCam->position;
1438 return TRUE;
1439 case GENERAL:
1440 case VIEWPOINT:
1441 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1442 // Using this allows us to look around without
1443 // changing the camera parameters (camDir, camUpVec)
1444 this->bottomWheelMotion(
1445 this->getBottomWheelValue() + 0.1f);
1446
1447 return TRUE;
1448 }
1449 break;
1450 case ROTATING:
1451 // For this state, let the keyboard event
1452 // be handled by superclass
1453 break;
1454 default:
1455 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1456 "Unhandled viewer state");
1457 break;
1458 }
1459 break;
1460
1461 case SoKeyboardEvent::RIGHT_ARROW:
1462 switch(currentState){
1463 case BEAMLINE:
1464 if ((this->lshiftdown) || (this->rshiftdown)){
1465 refParticleIdx += step;
1466 moveCamera();
1467 }
1468 else if ((this->lctrldown) || (this->rctrldown)){
1469 if (SoXtExaminerViewer::isAnimating())
1470 stopAnimating();
1471 prevState = currentState;
1472 currentState = ROTATING;
1473 animateBtwPtsPeriod = 0.08f;
1474
1475 rotAxis = camDir;
1476
1477 rotCnt = ROT_CNT;
1478 moveCamera(); // To make sure camera is perpendicular to the beamline
1479
1480 rotateCamera();
1481 }
1482 else{
1483 if (SoXtExaminerViewer::isAnimating())
1484 stopAnimating();
1485 prevState = currentState;
1486 currentState = ROTATING;
1487 animateBtwPtsPeriod = 0.08f;
1488
1489 rotAxis = camUpVec;
1490
1491 rotCnt = ROT_CNT;
1492 moveCamera(); // To make sure camera is perpendicular to the beamline
1493
1494 rotateCamera();
1495 }
1496 return TRUE;
1497
1498 case ANIMATION:
1499 case REVERSED_ANIMATION:
1500 left_right += 1.5f;
1501 return TRUE;
1502 case PAUSED_ANIMATION:
1503 left_right += 1.5f;
1504 setStartingPtForAnimation();
1505 cam->position = myCam->position;
1506 return TRUE;
1507 case GENERAL:
1508 case VIEWPOINT:
1509 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1510 // Using this allows us to look around without
1511 // changing the camera parameters (camDir, camUpVec)
1512 this->bottomWheelMotion(
1513 this->getBottomWheelValue() - 0.1f);
1514 return TRUE;
1515 }
1516 break;
1517 case ROTATING:
1518 // For this state, let the keyboard event
1519 // be handled by superclass
1520 break;
1521 default:
1522 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1523 "Unhandled viewer state");
1524 break;
1525 }
1526 break;
1527
1528 case SoKeyboardEvent::DOWN_ARROW:
1529 switch(currentState){
1530 case BEAMLINE:
1531
1532 if ((this->lshiftdown) || (this->rshiftdown)){
1533 refParticleIdx -= step;
1534 moveCamera();
1535 }
1536 else{
1537 if (SoXtExaminerViewer::isAnimating())
1538 stopAnimating();
1539 prevState = currentState;
1540 currentState = ROTATING;
1541 animateBtwPtsPeriod = 0.08f;
1542
1543 rotAxis = camDir.cross(camUpVec);
1544
1545 rotCnt = ROT_CNT;
1546 moveCamera(); // To make sure camera is perpendicular to the beamline
1547
1548 rotateCamera();
1549
1550 }
1551 return TRUE;
1552
1553 case ANIMATION:
1554 case REVERSED_ANIMATION:
1555 up_down -= 1.5f;
1556 return TRUE;
1557 case PAUSED_ANIMATION:
1558 up_down -= 1.5f;
1559 setStartingPtForAnimation();
1560 cam->position = myCam->position;
1561 return TRUE;
1562 case GENERAL:
1563 case VIEWPOINT:
1564 // Using this allows us to look around without
1565 // changing the camera parameters (camDir, camUpVec)
1566 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1567 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
1568 return TRUE;
1569 }
1570 break;
1571 case ROTATING:
1572 // For this state, let the keyboard event
1573 // be handled by superclass
1574 break;
1575 default:
1576 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1577 "Unhandled viewer state");
1578 break;
1579 }
1580 break;
1581
1582 case SoKeyboardEvent::UP_ARROW:
1583 switch(currentState){
1584 case BEAMLINE:
1585 if ((this->lshiftdown) || (this->rshiftdown)){
1586 refParticleIdx -= step;
1587 moveCamera();
1588 }
1589 else{
1590 if (SoXtExaminerViewer::isAnimating())
1591 stopAnimating();
1592 prevState = currentState;
1593 currentState = ROTATING;
1594 animateBtwPtsPeriod = 0.08f;
1595
1596 rotAxis = camUpVec.cross(camDir);
1597
1598 rotCnt = ROT_CNT;
1599 moveCamera();
1600
1601 rotateCamera();
1602
1603
1604 }
1605 return TRUE;
1606 case ANIMATION:
1607 case REVERSED_ANIMATION:
1608 up_down += 1.5f;
1609 return TRUE;
1610 case PAUSED_ANIMATION:
1611 up_down += 1.5f;
1612 setStartingPtForAnimation();
1613 cam->position = myCam->position;
1614 return TRUE;
1615 case GENERAL:
1616 case VIEWPOINT:
1617 // Using this allows us to look around without
1618 // changing the camera parameters (camDir, camUpVec)
1619 if ((!this->lshiftdown) && (!this->rshiftdown)) {
1620 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
1621 return TRUE;
1622 }
1623 break;
1624 case ROTATING:
1625 // For this state, let the keyboard event
1626 // be handled by superclass
1627 break;
1628 default:
1629 SoDebugError::post("G4OpenInventorXtExaminerViewer::processSoEvent",
1630 "Unhandled viewer state");
1631 break;
1632 }
1633 break;
1634
1635 case SoKeyboardEvent::PAGE_UP:
1636 switch(currentState){
1637 case BEAMLINE:
1638 if (step < (int) refParticleTrajectory.size() / 5) // Magic number
1639 step++;
1640 return TRUE;
1641 case ANIMATION:
1642 incSpeed();
1643 maxSpeed += SPEED_INDICATOR_STEP;
1644 if (maxSpeed > 0.8)
1645 maxSpeed = MAX_SPEED_INDICATOR;
1646 scheduleRedraw();
1647
1648 return TRUE;
1649 case REVERSED_ANIMATION:
1650 if(!animateSensor->isScheduled()){
1651 currentState = ANIMATION;
1652 if (refParticleIdx
1653 < (int) refParticleTrajectory.size() - 1) {
1654 refParticleIdx++;
1655 maxSpeed = SPEED_INDICATOR_STEP;
1656 scheduleRedraw();
1657 animateRefParticle();
1658 }
1659 }
1660 else{
1661 maxSpeed += SPEED_INDICATOR_STEP;
1662 decSpeed();
1663 scheduleRedraw();
1664 }
1665 return TRUE;
1666 case PAUSED_ANIMATION:
1667 maxSpeed += SPEED_INDICATOR_STEP;
1668 if (maxSpeed > 0.8)
1669 maxSpeed = MAX_SPEED_INDICATOR;
1670
1671 if (beforePausing == ANIMATION) {
1672 incSpeed();
1673 } else {
1674 decSpeed();
1675 if (animateBtwPtsPeriod >= MIN_SPEED)
1676 beforePausing = ANIMATION;
1677 }
1678
1679 scheduleRedraw();
1680 return TRUE;
1681 default: //fall through
1682 break;
1683 }
1684 break;
1685
1686 case SoKeyboardEvent::PAGE_DOWN:
1687 switch(currentState){
1688 case BEAMLINE:
1689 if (step > 1)
1690 step--;
1691 return TRUE;
1692 case ANIMATION:
1693 if(!animateSensor->isScheduled()){
1694 currentState = REVERSED_ANIMATION;
1695 if (refParticleIdx > 1) {
1696 refParticleIdx--;
1697 maxSpeed = -SPEED_INDICATOR_STEP;
1698 scheduleRedraw();
1699 animateRefParticle();
1700 }
1701 }
1702 else{
1703 maxSpeed -= SPEED_INDICATOR_STEP;
1704 decSpeed();
1705 scheduleRedraw();
1706 }
1707 return TRUE;
1708 case REVERSED_ANIMATION:
1709 incSpeed();
1710 maxSpeed -= SPEED_INDICATOR_STEP;
1711 if (maxSpeed < -0.8)
1712 maxSpeed = -MAX_SPEED_INDICATOR;
1713 scheduleRedraw();
1714 return TRUE;
1715 case PAUSED_ANIMATION:
1716 maxSpeed -= SPEED_INDICATOR_STEP;
1717 if (maxSpeed < -0.8)
1718 maxSpeed = -MAX_SPEED_INDICATOR;
1719 if (beforePausing == REVERSED_ANIMATION) {
1720 incSpeed();
1721 } else {
1722 decSpeed();
1723 if (animateBtwPtsPeriod >= MIN_SPEED)
1724 beforePausing = REVERSED_ANIMATION;
1725 }
1726 scheduleRedraw();
1727 return TRUE;
1728 default:
1729 //fall through
1730 break;
1731 }
1732 break;
1733
1734 case SoKeyboardEvent::E:
1735 this->escapeCallback(this->examinerObject);
1736 break;
1737
1738 default:
1739 break; // To get rid of compiler warnings
1740 }
1741 }
1742 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
1743 switch (ke->getKey()) {
1744 case SoKeyboardEvent::LEFT_SHIFT:
1745 this->lshiftdown = false;
1746 return TRUE;
1747 case SoKeyboardEvent::RIGHT_SHIFT:
1748 this->rshiftdown = false;
1749 return TRUE;
1750 case SoKeyboardEvent::LEFT_CONTROL:
1751 this->lctrldown = false;
1752 return TRUE;
1753 case SoKeyboardEvent::RIGHT_CONTROL:
1754 this->rctrldown = false;
1755 return TRUE;
1756 default:
1757 break;
1758 }
1759 }
1760 }
1761
1762 if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
1763 || currentState == ROTATING)
1764 return FALSE;
1765 else
1766 return SoXtExaminerViewer::processSoEvent(ev);
1767}
#define MAX_SPEED_INDICATOR
#define SPEED_INDICATOR_STEP
void moveCamera(float dist=0, bool lookdown=false)

◆ rotateCamera()

void G4OpenInventorXtExaminerViewer::rotateCamera ( )
protected

Definition at line 866 of file G4OpenInventorXtExaminerViewer.cc.

867{
868 SoCamera *cam = getCamera();
869
870 SbRotation rot(rotAxis, M_PI / (2 * ROT_CNT));
871 rot.multVec(camDir, camDir);
872 rot.multVec(camUpVec, camUpVec);
873
874 SbVec3f camPosNew = prevPt - (camDir*distance);
875 cam->position = camPosNew;
876 cam->pointAt(prevPt, camUpVec);
877 cam->focalDistance = (prevPt - camPosNew).length();
878
879 rotCnt--;
880
881 if (animateSensorRotation->isScheduled()) {
882 animateSensorRotation->unschedule();
883 }
884
885 animateSensorRotation->setBaseTime(SbTime::getTimeOfDay());
886 animateSensorRotation->setInterval(SbTime(0.02));
887 animateSensorRotation->schedule();
888
889}
#define M_PI
Definition: SbMath.h:34

Referenced by processSoEvent().

◆ updateViewParams()

void G4OpenInventorXtExaminerViewer::updateViewParams ( SoKeyboardEvent::Key  )
protected

◆ warningMsgDialog()

void G4OpenInventorXtExaminerViewer::warningMsgDialog ( std::string  msg,
String  dialogName,
XtCallbackProc  cb 
)

Definition at line 3564 of file G4OpenInventorXtExaminerViewer.cc.

3567{
3568 Arg args[5];
3569 unsigned int n;
3570 XmString warningMsg;
3571
3572 warningMsg = XmStringCreateLocalized((char *)msg.c_str());
3573
3574 n = 0;
3575 XtSetArg(args[n], XmNmessageString, warningMsg); n++;
3576 Widget warningDialog = XmCreateWarningDialog(getParentWidget(), dialogName, args, n);
3577 if (cb)
3578 XtAddCallback(warningDialog, XmNokCallback, cb, this);
3579
3580 XmStringFree(warningMsg);
3581
3582 XtVaSetValues (warningDialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
3583 XtUnmanageChild(XtNameToWidget(warningDialog, "Help"));
3584 XtUnmanageChild(XtNameToWidget(warningDialog, "Cancel"));
3585
3586 XtManageChild(warningDialog);
3587}

Referenced by afterRealizeHook(), and processSoEvent().

Friends And Related Function Documentation

◆ HookEventProcState

friend class HookEventProcState
friend

Definition at line 136 of file G4OpenInventorXtExaminerViewer.hh.

Member Data Documentation

◆ abbrOutputFlag

bool G4OpenInventorXtExaminerViewer::abbrOutputFlag

Definition at line 101 of file G4OpenInventorXtExaminerViewer.hh.

◆ camDir

SbVec3f G4OpenInventorXtExaminerViewer::camDir
protected

Definition at line 123 of file G4OpenInventorXtExaminerViewer.hh.

Referenced by moveCamera(), processSoEvent(), and rotateCamera().

◆ camUpVec

SbVec3f G4OpenInventorXtExaminerViewer::camUpVec
protected

Definition at line 122 of file G4OpenInventorXtExaminerViewer.hh.

Referenced by moveCamera(), processSoEvent(), and rotateCamera().

◆ curEltName

std::string G4OpenInventorXtExaminerViewer::curEltName
protected

Definition at line 121 of file G4OpenInventorXtExaminerViewer.hh.

◆ pickRefPathFlag

bool G4OpenInventorXtExaminerViewer::pickRefPathFlag

Definition at line 102 of file G4OpenInventorXtExaminerViewer.hh.

◆ saveRefCoordsFileName

std::string G4OpenInventorXtExaminerViewer::saveRefCoordsFileName

Definition at line 96 of file G4OpenInventorXtExaminerViewer.hh.

◆ saveRefCoordsWidget

Widget G4OpenInventorXtExaminerViewer::saveRefCoordsWidget

Definition at line 97 of file G4OpenInventorXtExaminerViewer.hh.

◆ saveScenegraphFileName

std::string G4OpenInventorXtExaminerViewer::saveScenegraphFileName

Definition at line 94 of file G4OpenInventorXtExaminerViewer.hh.

◆ saveScenegraphWidget

Widget G4OpenInventorXtExaminerViewer::saveScenegraphWidget

Definition at line 95 of file G4OpenInventorXtExaminerViewer.hh.

◆ viewingBeforePickRef

bool G4OpenInventorXtExaminerViewer::viewingBeforePickRef

Definition at line 103 of file G4OpenInventorXtExaminerViewer.hh.

◆ warningFlag

bool G4OpenInventorXtExaminerViewer::warningFlag

Definition at line 92 of file G4OpenInventorXtExaminerViewer.hh.


The documentation for this class was generated from the following files: