Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/toolx/X11/sg_viewer is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef toolx_X11_sg_viewer
0005 #define toolx_X11_sg_viewer
0006 
0007 // not pure X11 version. The class inherits tools::sg::viewer that uses GL.
0008 
0009 #include "session"
0010 
0011 #include "../sg/GL_viewer"
0012 
0013 #include "simple_dispatcher"
0014 
0015 namespace tools{namespace sg{class device_interactor;}}
0016 
0017 namespace toolx {
0018 namespace X11 {
0019 
0020 class sg_viewer : public sg::GL_viewer {
0021   typedef sg::GL_viewer parent;
0022 private:
0023   class dispatcher : public simple_dispatcher {
0024     typedef simple_dispatcher parent;
0025   public:
0026     virtual void win_render() {m_sg_viewer.win_render();}
0027     virtual void set_size(unsigned int a_width,unsigned int a_height) {m_sg_viewer.set_size(a_width,a_height);}
0028     virtual dispatcher* copy() const {return new dispatcher(*this);}
0029   public:
0030     dispatcher(sg_viewer& a_sg_viewer)
0031     :parent(a_sg_viewer.m_session,a_sg_viewer.m_win)
0032     ,m_sg_viewer(a_sg_viewer){}
0033     virtual ~dispatcher(){}
0034   protected:
0035     dispatcher(const dispatcher& a_from)
0036     :parent(a_from)
0037     ,m_sg_viewer(a_from.m_sg_viewer)
0038     {}
0039     dispatcher& operator=(const dispatcher& a_from) {
0040       parent::operator=(a_from);
0041       return *this;
0042     }
0043   protected:
0044     sg_viewer& m_sg_viewer;
0045   };
0046 
0047 public:
0048   sg_viewer(session& a_session,
0049             int a_x = 0,int a_y = 0,
0050             unsigned int a_width = 500,unsigned int a_height = 500,
0051             const std::string& a_win_title = "")
0052   :parent(a_session.out(),a_width,a_height)
0053   ,m_session(a_session)
0054   ,m_win(0)
0055   {
0056     if(!m_session.display()) return; //throw
0057     m_win = m_session.create_window(a_win_title.c_str(),a_x,a_y,a_width,a_height);
0058     if(!m_win) return; //throw
0059     m_session.add_dispatcher(new dispatcher(*this));
0060   }
0061   virtual ~sg_viewer() {
0062     if(m_win) {
0063       m_session.remove_dispatchers_with_window(m_win);
0064       m_session.delete_window(m_win);
0065       m_session.sync();
0066     }
0067   }
0068 public:
0069   sg_viewer(const sg_viewer& a_from)
0070   :parent(a_from)
0071   ,m_session(a_from.m_session)
0072   ,m_win(a_from.m_win)
0073   {}
0074   sg_viewer& operator=(const sg_viewer& a_from){
0075     parent::operator=(a_from);
0076     m_win = a_from.m_win;
0077     return *this;
0078   }
0079 public:
0080   bool has_window() const {return m_win?true:false;} //for SWIG
0081 
0082   Window window() const {return m_win;}
0083 
0084   bool show() {
0085     if(!m_win) return false;
0086     m_session.show_window(m_win);
0087     return true;
0088   }
0089 
0090   void win_render() {
0091     if(!m_win) return;
0092     if(::glXMakeCurrent(m_session.display(),m_win,m_session.context())==False){
0093       m_session.out() << "toolx::X11::sg_viewer::win_render : glXMakeCurrent failed." << std::endl;
0094       return;
0095     }
0096     render(); //viewer::render()
0097     ::glXSwapBuffers(m_session.display(),m_win);
0098     if(::glXMakeCurrent(m_session.display(),None,NULL)==False){
0099       m_session.out() << "toolx::X11::sg_viewer::win_render : glXMakeCurrent(None,NULL) failed." << std::endl;
0100     }
0101   }
0102 
0103 public:
0104   void set_device_interactor(tools::sg::device_interactor*) {}
0105 protected:
0106   session& m_session;
0107   Window m_win;
0108 };
0109 
0110 }}
0111 
0112 #endif
0113