Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/draw_style 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 tools_sg_draw_style
0005 #define tools_sg_draw_style
0006 
0007 #include "node"
0008 
0009 #include "lpat"
0010 #include "sf_enum"
0011 #include "render_action"
0012 #include "pick_action"
0013 #include "bbox_action"
0014 
0015 namespace tools {
0016 namespace sg {
0017 
0018 class draw_style : public node {
0019   TOOLS_NODE(draw_style,tools::sg::draw_style,node)
0020 public:
0021   sf_enum<draw_type> style;
0022   sf<float> line_width;
0023   sf<lpat> line_pattern;
0024   sf<float> point_size;
0025   sf<bool> cull_face;
0026   sf<bool> winding_ccw;
0027   sf<bool> point_smooth;
0028 public:
0029   virtual const desc_fields& node_desc_fields() const {
0030     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::draw_style)
0031     static const desc_fields s_v(parent::node_desc_fields(),7, //WARNING : take care of count.
0032       TOOLS_ARG_FIELD_DESC(style),
0033       TOOLS_ARG_FIELD_DESC(line_width),
0034       TOOLS_ARG_FIELD_DESC(line_pattern),
0035       TOOLS_ARG_FIELD_DESC(point_size),
0036       TOOLS_ARG_FIELD_DESC(cull_face),
0037       TOOLS_ARG_FIELD_DESC(winding_ccw),
0038       TOOLS_ARG_FIELD_DESC(point_smooth)
0039     );
0040     return s_v;
0041   }
0042 private:
0043   void add_fields(){
0044     add_field(&style);
0045     add_field(&line_width);
0046     add_field(&line_pattern);
0047     add_field(&point_size);
0048     add_field(&cull_face);
0049     add_field(&winding_ccw);
0050     add_field(&point_smooth);
0051   }
0052 public:
0053   virtual void render(render_action& a_action) {
0054     state& state = a_action.state();
0055     _set_state(state);
0056 
0057     if(style.value()==draw_lines) {
0058       a_action.line_width(state.m_line_width);
0059     } else if(style.value()==draw_points) {
0060       a_action.point_size(state.m_point_size);
0061       a_action.set_point_smooth(state.m_GL_POINT_SMOOTH);
0062     } else if(style.value()==draw_filled) {
0063       a_action.set_cull_face(state.m_GL_CULL_FACE);
0064       a_action.set_winding(state.m_winding);
0065     }
0066   }
0067   virtual void pick(pick_action& a_action) {_set_state(a_action.state());}
0068   virtual void bbox(bbox_action& a_action) {_set_state(a_action.state());}
0069 public:
0070   draw_style()
0071   :parent()
0072   ,style(draw_filled)
0073   ,line_width(1) //NOTE : 0 induces a 501 gl error.
0074   ,line_pattern(line_solid)
0075   ,point_size(1)
0076   ,cull_face(true)
0077   ,winding_ccw(true)
0078   ,point_smooth(false)
0079   {
0080     add_fields();
0081   }
0082   virtual ~draw_style(){}
0083 public:
0084   draw_style(const draw_style& a_from)
0085   :parent(a_from)
0086   ,style(a_from.style)
0087   ,line_width(a_from.line_width)
0088   ,line_pattern(a_from.line_pattern)
0089   ,point_size(a_from.point_size)
0090   ,cull_face(a_from.cull_face)
0091   ,winding_ccw(a_from.winding_ccw)
0092   ,point_smooth(a_from.point_smooth)
0093   {
0094     add_fields();
0095   }
0096   draw_style& operator=(const draw_style& a_from){
0097     parent::operator=(a_from);
0098 
0099     style = a_from.style;
0100     line_width = a_from.line_width;
0101     line_pattern = a_from.line_pattern;
0102     point_size = a_from.point_size;
0103     cull_face = a_from.cull_face;
0104     winding_ccw = a_from.winding_ccw;
0105     point_smooth = a_from.point_smooth;
0106 
0107     return *this;
0108   }
0109 protected:
0110   void _set_state(state& a_state) {
0111     a_state.m_draw_type = style;
0112     a_state.m_line_width = line_width;
0113     a_state.m_line_pattern = line_pattern;
0114     a_state.m_point_size = point_size;
0115     a_state.m_GL_CULL_FACE = cull_face;
0116     a_state.m_winding = winding_ccw.value()?sg::winding_ccw:sg::winding_cw;
0117     a_state.m_GL_POINT_SMOOTH = point_smooth;
0118   }
0119 };
0120 
0121 }}
0122 
0123 #endif