File: AbstractModel.cxx

package info (click to toggle)
itksnap 3.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,196 kB
  • ctags: 9,196
  • sloc: cpp: 62,895; sh: 175; makefile: 13
file content (130 lines) | stat: -rw-r--r-- 3,335 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "AbstractModel.h"
#include "EventBucket.h"

#include <IRISException.h>
#include <vtkObject.h>
#include <vtkCommand.h>

#include "SNAPEventListenerCallbacks.h"


AbstractModel::AbstractModel()
  : itk::Object()
{
  m_EventBucket = new EventBucket();
}

AbstractModel::~AbstractModel()
{
  // Cleanup
  delete m_EventBucket;
  for(std::list<Rebroadcaster *>::iterator it = m_Rebroadcast.begin();
      it != m_Rebroadcast.end(); ++it)
    {
    delete *it;
    }
}

void AbstractModel::Update()
{
  if(!m_EventBucket->IsEmpty())
    {
#ifdef SNAP_DEBUG_EVENTS
    if(flag_snap_debug_events)
      {
      std::cout << "UPDATE called in model " << this->GetNameOfClass()
                << " [" << this << "] "
                << " with " << *m_EventBucket << std::endl << std::flush;
      }
#endif
    this->OnUpdate();
    m_EventBucket->Clear();
    }
}


AbstractModel::Rebroadcaster
::Rebroadcaster(AbstractModel *model, const itk::EventObject &evt)
{          
  m_Model = model;
  m_Event = evt.MakeObject();
}

AbstractModel::Rebroadcaster
::~Rebroadcaster()
{
  delete m_Event;
}

void
AbstractModel::Rebroadcaster
::Broadcast(itk::Object *source, const itk::EventObject &evt)
{
  this->Broadcast((const itk::Object *) source, evt);
}

void
AbstractModel::Rebroadcaster
::Broadcast(const itk::Object *source, const itk::EventObject &evt)
{
#ifdef SNAP_DEBUG_EVENTS
  if(flag_snap_debug_events)
    {
    std::cout << "REBROADCAST event " <<  evt.GetEventName()
              << " from " << source->GetNameOfClass()
              << " [" << source << "] "
              << " as " << m_Event->GetEventName()
              << " from " << m_Model->GetNameOfClass()
              << " [" << m_Model << "] "
              << std::endl << std::flush;
    }
#endif // SNAP_DEBUG_EVENTS
  m_Model->m_EventBucket->PutEvent(evt, source);
  m_Model->InvokeEvent(*m_Event);
}

void
AbstractModel::Rebroadcaster
::BroadcastVTK(vtkObject *source, unsigned long event, void *)
{
#ifdef SNAP_DEBUG_EVENTS
  if(flag_snap_debug_events)
    {
    std::cout << "REBROADCAST VTK event "
              <<  vtkCommand::GetStringFromEventId(event)
              << " from " << source->GetClassName()
              << " [" << source << "] "
              << " as " << m_Event->GetEventName()
              << " from " << m_Model->GetNameOfClass()
              << " [" << m_Model << "] "
              << std::endl << std::flush;
    }
#endif // SNAP_DEBUG_EVENTS

  // TODO: how to package this up for the bucket?
  m_Model->m_EventBucket->PutEvent(VTKEvent(), NULL);
  m_Model->InvokeEvent(*m_Event);
}

#include "Rebroadcaster.h"

unsigned long
AbstractModel::Rebroadcast(
    itk::Object *src, const itk::EventObject &srcEvent, const itk::EventObject &trgEvent)
{
  /*
  Rebroadcaster *reb = new Rebroadcaster(this, trgEvent);
  m_Rebroadcast.push_back(reb);
  return AddListenerPair(src, srcEvent, reb, &Rebroadcaster::Broadcast, &Rebroadcaster::Broadcast);
  */
  return ::Rebroadcaster::Rebroadcast(src, srcEvent, this, trgEvent, m_EventBucket);
}

unsigned long
AbstractModel::Rebroadcast(
    vtkObject *src, unsigned long srcEvent, const itk::EventObject &trgEvent)
{
  Rebroadcaster *reb = new Rebroadcaster(this, trgEvent);
  m_Rebroadcast.push_back(reb);
  return AddListenerVTK(src, srcEvent, reb, &Rebroadcaster::BroadcastVTK);
}