Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_viewer 5 #define tools_sg_viewer 6 7 #include "group" 8 9 #ifdef TOOLS_MEM 10 #include "../mem" 11 #endif 12 13 #include "cursor_shape" 14 15 namespace tools { 16 namespace sg { 17 18 class viewer { 19 public: 20 TOOLS_SCLASS(tools::sg::viewer) 21 virtual void* cast(const std::string& a_clas 22 if(void* p = cmp_cast<viewer>(this,a_class 23 else return 0; 24 } 25 public: 26 virtual void set_size(unsigned int a_w,unsig 27 //m_out << "debug : tools::sg::viewer::set 28 // << " ww " << a_w 29 // << " wh " << a_h 30 // << std::endl; 31 size_event e(m_ww,m_wh,a_w,a_h); 32 m_ww = a_w; 33 m_wh = a_h; 34 event_action action(m_out,m_ww,m_wh,e); 35 action.set_do_switch_children(true); //And 36 m_sg.event(action); //used by m_plots in p 37 } 38 39 virtual bool set_cursor_shape(cursor_shape) 40 public: 41 viewer(std::ostream& a_out,unsigned int a_wi 42 :m_out(a_out) 43 ,m_clear_color(1,1,1) 44 ,m_ww(a_width) 45 ,m_wh(a_height) 46 ,m_use_gsto(false) 47 ,m_produce_out_jpeg(false) 48 ,m_produce_out_png(false) 49 ,m_produce_out_file() 50 ,m_produce_out_bpp(4) 51 { 52 #ifdef TOOLS_MEM 53 mem::increment(s_class().c_str()); 54 #endif 55 } 56 virtual ~viewer(){ 57 m_sg.clear(); //we must delete node before 58 #ifdef TOOLS_MEM 59 mem::decrement(s_class().c_str()); 60 #endif 61 } 62 public: 63 viewer(const viewer& a_from) 64 :m_out(a_from.m_out) 65 ,m_clear_color(a_from.m_clear_color) 66 ,m_ww(a_from.m_ww) 67 ,m_wh(a_from.m_wh) 68 ,m_sg(a_from.m_sg) 69 ,m_use_gsto(a_from.m_use_gsto) 70 ,m_produce_out_jpeg(a_from.m_produce_out_jpe 71 ,m_produce_out_png(a_from.m_produce_out_png) 72 ,m_produce_out_file(a_from.m_produce_out_fil 73 ,m_produce_out_bpp(a_from.m_produce_out_bpp) 74 { 75 #ifdef TOOLS_MEM 76 mem::increment(s_class().c_str()); 77 #endif 78 } 79 viewer& operator=(const viewer& a_from){ 80 m_clear_color = a_from.m_clear_color; 81 m_ww = a_from.m_ww; 82 m_wh = a_from.m_wh; 83 m_sg = a_from.m_sg; 84 m_use_gsto = a_from.m_use_gsto; 85 m_produce_out_jpeg = a_from.m_produce_out_ 86 m_produce_out_png = a_from.m_produce_out_p 87 m_produce_out_file = a_from.m_produce_out_ 88 m_produce_out_bpp = a_from.m_produce_out_b 89 return *this; 90 } 91 public: 92 bool set_default_cursor_shape() {return set_ 93 94 group& sg() {return m_sg;} 95 const group& sg() const {return m_sg;} 96 97 unsigned int width() const {return m_ww;} 98 unsigned int height() const {return m_wh;} 99 100 bool screen2aspect(int a_x,int a_y,float& a_ 101 // convert screen point in [aspect,1] coor 102 //if(!m_ww) {a_wx = a_wy = 0;return false; 103 //if(!m_wh) {a_wx = a_wy = 0;return false; 104 float aspect = float(m_ww)/float(m_wh); 105 float wch = 1; 106 float wcw = wch*aspect; 107 a_wx = float(a_x) * wcw/float(m_ww); 108 a_wy = float(a_y) * wch/float(m_wh); 109 return true; 110 } 111 112 void set_clear_color(float a_r,float a_g,flo 113 m_clear_color = colorf(a_r,a_g,a_b,a_a); 114 } 115 void set_clear_color(const colorf& a_color) 116 m_clear_color = a_color; 117 } 118 void get_clear_color(float& a_r,float& a_g,f 119 a_r = m_clear_color.r(); 120 a_g = m_clear_color.g(); 121 a_b = m_clear_color.b(); 122 a_a = m_clear_color.a(); 123 } 124 125 const colorf& background() const {return m_c 126 127 std::ostream& out() const {return m_out;} 128 129 const std::string& out_dir() const {return m 130 131 132 void set_produce_out_jpeg(bool a_value) {m_p 133 bool produce_out_jpeg() const {return m_prod 134 135 void set_produce_out_png(bool a_value) {m_pr 136 bool produce_out_png() const {return m_produ 137 138 void set_produce_out_file(const std::string& 139 const std::string& produce_out_file() const 140 141 void set_produce_out_bpp(unsigned int a_bpp) 142 unsigned int produce_out_bpp() const {return 143 protected: 144 // iPod : 320 x 480 145 // iPad : 768 x 1024 146 // SGS : API-1 : 320 x 533, API-5 : 480 x 80 147 // SGT : 1024 x 600 ? 148 149 // LRI WILD : borders w = 100 x h = 120. 4x8 150 // LAL ARTS : borders 88x100. 2x4 screens of 151 152 //bool is_iPad() const { 153 // if( (m_ww==768) && (m_wh==1024) ) return 154 // if( (m_wh==768) && (m_ww==1024) ) return 155 // return false; 156 //} 157 //bool is_SGS() const { 158 // //API : 1 159 // //if( (m_ww==320) && (m_wh==533) ) retur 160 // //if( (m_wh==320) && (m_ww==533) ) retur 161 // 162 // //API : 5 163 // if( (m_ww==480) && (m_wh==800) ) return 164 // if( (m_wh==480) && (m_ww==800) ) return 165 // return false; 166 //} 167 168 protected: 169 std::ostream& m_out; 170 colorf m_clear_color; 171 unsigned int m_ww; 172 unsigned int m_wh; 173 group m_sg; 174 std::string m_out_dir; 175 bool m_use_gsto; 176 bool m_produce_out_jpeg; 177 bool m_produce_out_png; 178 std::string m_produce_out_file; 179 unsigned int m_produce_out_bpp; 180 }; 181 182 }} 183 184 #include "../pointer" 185 186 namespace tools { 187 namespace sg { 188 189 // used with Python and lua : 190 inline viewer* cast_viewer(const std::string& 191 void* p; 192 if(!to_pointer(a_s,p)) return 0; //read with 193 return (viewer*)p; 194 } 195 196 }} 197 198 #endif 199