diff --git a/Kinetic_data_structures/include/CGAL/Kinetic/IO/internal/GUI_base.h b/Kinetic_data_structures/include/CGAL/Kinetic/IO/internal/GUI_base.h index 6e568b76eca..9b1cc5a20fa 100644 --- a/Kinetic_data_structures/include/CGAL/Kinetic/IO/internal/GUI_base.h +++ b/Kinetic_data_structures/include/CGAL/Kinetic/IO/internal/GUI_base.h @@ -60,10 +60,10 @@ public: Gui_base(typename Simulator::Handle sh): mode_(STOPPED), paused_mode_(STOPPED), fps_(60), speed_log_(0), dir_of_time_(1), timer_(new Timer()), - timer_callback_(timer_,const_cast(this)), drawable_(NULL), processing_(false) { sim_= sh; target_cur_time_= CGAL::to_interval(sim_->current_time()).first; + CGAL_KINETIC_INIT_LISTEN(Timer, timer_); } virtual ~Gui_base() { @@ -111,19 +111,20 @@ public: } } - class Listener_core + /*class Listener_core { public: typedef typename This::Handle Notifier_handle; typedef enum {CURRENT_TIME} Notification_type; - }; + };*/ //! The class to extend if you want to receive events. /*! See CGAL::Listener to a description of how runtime notifications are handled. */ - typedef CGAL::Kinetic::Listener Listener; - friend class CGAL::Kinetic::Listener; + CGAL_KINETIC_LISTENER(CURRENT_TIME); + //typedef CGAL::Kinetic::Listener Listener; + //friend class CGAL::Kinetic::Listener; //! get the simulator typename Simulator::Handle& simulator() { @@ -177,16 +178,9 @@ protected: } } - const Listener* listener() const - { - return drawable_; - } + - void set_listener(Listener* d) { - drawable_=d; - } - - class Timer_listener: public Timer::Listener + /*class Timer_listener: public Timer::Listener { public: Timer_listener(Timer *tm, This *t):Timer::Listener(tm), t_(t) { @@ -198,7 +192,8 @@ protected: This *t_; }; - friend class Timer_listener; + friend class Timer_listener;*/ + CGAL_KINETIC_LISTEN1(Timer, TICKS, timer_rang); void timer_rang() { // do something here @@ -309,7 +304,8 @@ protected: default: std::cerr << "Run callback in invalid mode." << std::endl; } - if (drawable_ != NULL) drawable_->new_notification(Listener::CURRENT_TIME); + CGAL_KINETIC_SIGNAL(CURRENT_TIME); + // if (drawable_ != NULL) drawable_->new_notification(Listener::CURRENT_TIME); set_is_processing(false); diff --git a/Kinetic_data_structures/include/CGAL/Kinetic/IO/internal/Qt_timer.h b/Kinetic_data_structures/include/CGAL/Kinetic/IO/internal/Qt_timer.h index c8316d907f9..26ddbad221c 100644 --- a/Kinetic_data_structures/include/CGAL/Kinetic/IO/internal/Qt_timer.h +++ b/Kinetic_data_structures/include/CGAL/Kinetic/IO/internal/Qt_timer.h @@ -24,56 +24,56 @@ #include namespace CGAL { - namespace Kinetic + namespace Kinetic + { + namespace internal { - namespace internal - { - class Qt_timer: QObject - { - Q_OBJECT - public: - class Listener - { - public: - typedef Qt_timer* Notifier_handle; - Listener(Notifier_handle h): h_(h){h->set_listener(this);} - typedef enum {TICKS} - Notification_type; - virtual void new_notification(Notification_type) =0; - virtual ~Listener() { - h_->set_listener(NULL); - } - protected: - Notifier_handle h_; - }; + class Qt_timer: QObject + { + Q_OBJECT + public: + class Listener + { + public: + typedef Qt_timer* Notifier_handle; + Listener(Notifier_handle h): h_(h){h->set_listener(this);} + typedef enum {TICKS} + Notification_type; + virtual void new_notification(Notification_type) =0; + virtual ~Listener() { + h_->set_listener(NULL); + } + protected: + Notifier_handle h_; + }; - Qt_timer(); + Qt_timer(); - int ticks() const - { - return tick_; - } - void clear() { -//CGAL_precondition(id_!=-1); - if (id_!= -1) timer_.killTimer(id_); - id_=-1; - }; - void run(double time_in_seconds); - protected: - QTimer timer_; - Listener *cb_; - int tick_; - int id_; + int ticks() const + { + return tick_; + } + void clear() { + //CGAL_precondition(id_!=-1); + if (id_!= -1) timer_.killTimer(id_); + id_=-1; + }; + void run(double time_in_seconds); + protected: + QTimer timer_; + Listener *cb_; + int tick_; + int id_; - friend class Listener; - void set_listener(Listener *l) { - cb_=l; - } + friend class Listener; + void set_listener(Listener *l) { + cb_=l; + } - private slots: - void timerDone(); - }; - }; + private slots: + void timerDone(); + }; }; + }; }; #endif diff --git a/Kinetic_data_structures/include/CGAL/Kinetic/Listener.h b/Kinetic_data_structures/include/CGAL/Kinetic/Listener.h index a87e65c06d2..6d4e1d63c13 100644 --- a/Kinetic_data_structures/include/CGAL/Kinetic/Listener.h +++ b/Kinetic_data_structures/include/CGAL/Kinetic/Listener.h @@ -169,5 +169,20 @@ private: \ #define CGAL_KINETIC_SIGNAL(field) if (listener_!= NULL) listener_->new_notification(Listener::field) #define CGAL_KINETIC_LISTENER_DESTRUCTOR CGAL_assertion(listener_==NULL); + +#define CGAL_KINETIC_LISTEN1(Notifier, Signal, func) private:\ + class Notifier##_listener: public Notifier::Listener {\ + This *t_; \ + public: \ + Notifier##_listener(Notifier* tm, This &t): Notifier::Listener(tm), t_(t){} \ + void new_notification(typename Notifier::Listener::Notification_type t) {\ + if (t== Notifier::Listener::Signal) t_->func(); \ + }\ + };\ + friend class Notifier##_listener;\ + Notifier##_listener listener_##Notifier##_; + +#define CGAL_KINETIC_INIT_LISTEN(Notifier, ptr) listener_##Notifier##_=Notifier##_listener(ptr, const_cast(this)) + CGAL_KINETIC_END_NAMESPACE #endif diff --git a/Kinetic_data_structures/include/CGAL/Kinetic/Ref_counted.h b/Kinetic_data_structures/include/CGAL/Kinetic/Ref_counted.h index fffb92e3cba..84634784320 100644 --- a/Kinetic_data_structures/include/CGAL/Kinetic/Ref_counted.h +++ b/Kinetic_data_structures/include/CGAL/Kinetic/Ref_counted.h @@ -37,14 +37,14 @@ void intrusive_ptr_release(const Ref_counted_base *t); class Ref_counted_base: boost::noncopyable { typedef Ref_counted_base This; - Ref_counted_base(const Ref_counted_base&) : reference_count_(0) { + /*Ref_counted_base(const Ref_counted_base&) : reference_count_(0) { std::cerr << "Copy constructor called. Why?" << std::endl; - } - Ref_counted_base operator=(const Ref_counted_base&) const + }*/ + /*Ref_counted_base operator=(const Ref_counted_base&) const { std::cerr << "Assignment called. Why?" << std::endl; return *this; - } + }*/ public: Ref_counted_base() : reference_count_(0) {}