1  // This is brl/bbas/bgui3d/bgui3d_examiner_tableau.h
2 #ifndef bgui3d_examiner_tableau_h_
3 #define bgui3d_examiner_tableau_h_
4 //:
5 // \file
6 // \brief  Examiner viewer tableau for 3D scenes
7 // \author Matt Leotta (mleotta@lems.brown.edu)
8 // \date   May 25, 2004
9 //
10 // \verbatim
11 //  Modifications
12 //   <none yet>
13 // \endverbatim
14 
15 #include "bgui3d_fullviewer_tableau.h"
16 #include "bgui3d_examiner_tableau_sptr.h"
17 #include <Inventor/SbLinear.h>
18 #include <Inventor/nodes/SoText2.h>
19 #include <Inventor/nodes/SoSwitch.h>
20 
21 class SbSphereSheetProjector;
22 class SbRotation;
23 class SoTimerSensor;
24 class SoCone;
25 
26 enum Process
27 {
28   SPIN=0,
29   DRAG,
30   PAN,
31   ZOOM,
32   IDLE,
33   SEEK
34 };
35 
36 struct Log
37 {
38   int size;
39   SbVec2f pos1;
40   SbVec2f pos2;
41   SbVec2f pos3;
42 };
43 
44 //:  Examiner viewer tableau for 3D scenes
45 class bgui3d_examiner_tableau : public bgui3d_fullviewer_tableau
46 {
47  public:
48   enum SeekDistance
49   {
50     SEEK_FAR,
51     SEEK_HALF,
52     SEEK_NEAR,
53     SEEK_ZERO
54   };
55 
56   //: Constructor
57   bgui3d_examiner_tableau(SoNode * scene_root = NULL);
58 
59   //: Destructor
60   virtual ~bgui3d_examiner_tableau();
61 
62   //: Handle vgui events
63   virtual bool handle(const vgui_event& event);
64 
65   //: Return the type name of this tableau
66   std::string type_name() const;
67 
68   //: Builds a popup menu
69   virtual void get_popup(const vgui_popup_params&, vgui_menu &m);
70 
71   //: Render the scene graph (called on draw events)
72   virtual bool render();
73 
74   //: Pans the camera
75   void pan(const SbVec2f & currpos, const SbVec2f & prevpos, const float aspect_ratio);
76 
77   //: Zooms the camera
78   void zoom( float aspectratio );
79 
80   //: Spins the camera around the scene
81   void spin(const SbVec2f& currpos, const SbVec2f &prevpos);
82 
83   //: Reorients the camera to the specified rotation
84   void reorient_camera(const SbRotation & rot);
85 
86   //: Updates position log
87   void update_log(SbVec2f pos);
88 
89   //: Resets position log
90   void reset_log();
91 
92   //: Seeks for the object under a mouse click and zooms to it
93   void seek_to_point(SbVec2s pos);
94 
95   //: What to do if events are idle, if enabled
96   bool idle();
97 
98   //: Set the visibility of the axis cross
99   void set_axis_visible(bool state);
100 
101   //: Return true if the axis cross is visible
102   bool axis_visible() const;
103 
104   void set_seek_distance( SeekDistance seek );
105 
106   //void seeksensorCB(void * data, SoSensor * s);
107 
108  protected:
109   // these are made protected (instead of private) so that child classes
110   // can access them
111   vgui_button last_down_button_;
112   SbVec2f last_pos_;
113   Process last_process_;
114   int last_timestamp_;
115 
116   //: draw the axis
117   void draw_axis_cross();
118 
119   //: Draw an arrow for the axis representation
120   void draw_arrow();
121 
122   //: Determine the scale of the scene
123   void find_scale();
124 
125  private:
126   SbSphereSheetProjector* spin_projector_;
127   int spin_sample_counter_;
128   SbRotation spin_increment_;
129   Log log_;
130   SeekDistance seek_distance_;
131   SoTimerSensor* seekSensor_;
132 
133   // The scale of the scene
134   float scale_;
135 
136   bool axis_visible_;
137 
138  public:
139   SbRotation fromRot_;
140   SbRotation toRot_;
141   SbVec3f fromPos_;
142   SbVec3f toPos_;
143 };
144 
145 
146 //: Create a smart pointer to a bgui3d_examiner_tableau.
147 struct bgui3d_examiner_tableau_new : public bgui3d_examiner_tableau_sptr
148 {
149   typedef bgui3d_examiner_tableau_sptr base;
150   bgui3d_examiner_tableau_new(SoNode* scene_root = NULL)
basebgui3d_examiner_tableau_new151    : base(new bgui3d_examiner_tableau(scene_root)) {}
152 };
153 
154 
155 #endif // bgui3d_examiner_tableau_h_
156