Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_ecbk 5 #define tools_sg_ecbk 6 7 // A callback class to handle a response to some event 8 // (viewer/window size, mouse button press, etc...). 9 // It is typically used through the event_dispatcher node. 10 11 #include "bcbk" 12 #include "event" 13 #include "event_action" 14 #include "../forit" 15 #include "../HEADER" 16 17 #include <vector> 18 19 namespace tools { 20 namespace sg { 21 class node; 22 }} 23 24 namespace tools { 25 namespace sg { 26 27 class ecbk : public bcbk { 28 TOOLS_HEADER(ecbk,tools::sg::ecbk,bcbk) 29 public: 30 ecbk(unsigned int a_action = 0) 31 :parent() 32 ,m_action(a_action) 33 ,m_no_set_done(false) 34 ,m_event(0) 35 ,m_event_action(0) 36 ,m_node(0) 37 ,m_z(0) 38 ,m_w(0) 39 {} 40 virtual ~ecbk(){delete m_event;} 41 public: 42 ecbk(const ecbk& a_from) 43 :parent(a_from) 44 ,m_action(a_from.m_action) 45 ,m_no_set_done(a_from.m_no_set_done) 46 ,m_event(0) 47 ,m_event_action(a_from.m_event_action) 48 ,m_node(a_from.m_node) 49 ,m_z(a_from.m_z) 50 ,m_w(a_from.m_w) 51 { 52 if(a_from.m_event) m_event = a_from.m_event->copy(); 53 } 54 ecbk& operator=(const ecbk& a_from){ 55 parent::operator=(a_from); 56 57 m_action = a_from.m_action; 58 m_no_set_done = a_from.m_no_set_done; 59 60 delete m_event; 61 m_event = 0; 62 if(a_from.m_event) m_event = a_from.m_event->copy(); 63 64 m_event_action = a_from.m_event_action; 65 m_node = a_from.m_node; 66 m_z = a_from.m_z; 67 m_w = a_from.m_w; 68 return *this; 69 } 70 public: 71 void set_action(unsigned int a_v){m_action = a_v;} 72 void set_no_set_done(bool a_v) {m_no_set_done = a_v;} 73 // for ArcheryTune : 74 event& event_ref() const {return *m_event;} 75 event_action& event_action_ref() const {return *m_event_action;} 76 public: 77 static void exec_event_cbks(const std::vector<bcbk*>& a_cbks, 78 const event& a_evt, 79 event_action* a_action, 80 node* a_node, 81 float a_z = 0,float a_w = 0) { 82 tools_vforcit(bcbk*,a_cbks,it) { 83 bcbk* _cbk = (*it)->copy(); 84 85 if(ecbk* _ecbk = safe_cast<bcbk,ecbk>(*_cbk)){ 86 delete _ecbk->m_event; 87 _ecbk->m_event = a_evt.copy(); 88 89 _ecbk->m_event_action = a_action; 90 _ecbk->m_node = a_node; 91 _ecbk->m_z = a_z; 92 _ecbk->m_w = a_w; 93 94 _ecbk->action(); 95 96 if(a_action->done()) { 97 delete _cbk; 98 break; 99 } 100 } 101 102 delete _cbk; 103 } 104 } 105 106 public: 107 unsigned int m_action; 108 bool m_no_set_done; //to tell not doing m_event_action->set_done(true). 109 event* m_event; //owner 110 event_action* m_event_action; //not owner. 111 node* m_node; //not owner. 112 float m_z; 113 float m_w; 114 }; 115 116 }} 117 118 #endif