-
Notifications
You must be signed in to change notification settings - Fork 21
/
vtkErrorSink.cxx
130 lines (116 loc) · 3.93 KB
/
vtkErrorSink.cxx
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
/*=auto=========================================================================
Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
=========================================================================auto=*/
#include "vtkErrorSink.h"
#include "vtkObjectFactory.h"
vtkStandardNewMacro(vtkErrorSink);
//----------------------------------------------------------------------------
vtkErrorSink::vtkErrorSink()
{
this->CallbackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
this->CallbackCommand->SetCallback(vtkErrorSink::CallbackFunction);
this->CallbackCommand->SetClientData(this);
}
//----------------------------------------------------------------------------
vtkErrorSink::~vtkErrorSink()
{
this->SetObservedObject(nullptr);
}
//----------------------------------------------------------------------------
void vtkErrorSink::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
std::vector<vtkErrorSink::Message>::iterator it = this->MessageList.begin();
os << indent << "MessageList = \n";
while (it != this->MessageList.end())
{
os << indent.GetNextIndent();
switch (it->EventId)
{
case vtkCommand::ErrorEvent: os << "Error: "; break;
case vtkCommand::WarningEvent: os << "Warning: "; break;
}
os << it->MessageText.c_str() << std::endl;
}
}
//----------------------------------------------------------------------------
void vtkErrorSink::DisplayMessages()
{
std::vector<vtkErrorSink::Message>::iterator it = this->MessageList.begin();
while (it != this->MessageList.end())
{
switch (it->EventId)
{
case vtkCommand::ErrorEvent: vtkOutputWindowDisplayErrorText(it->MessageText.c_str()); break;
case vtkCommand::WarningEvent: vtkOutputWindowDisplayWarningText(it->MessageText.c_str()); break;
}
++it;
}
}
//----------------------------------------------------------------------------
void vtkErrorSink::CallbackFunction(vtkObject* vtkNotUsed(caller),
long unsigned int eventId,
void* clientData, void* callData)
{
vtkErrorSink* self = reinterpret_cast<vtkErrorSink*>(clientData);
vtkErrorSink::Message message;
if (callData)
{
message.EventId = eventId;
message.MessageText = reinterpret_cast<char*>(callData);
self->MessageList.push_back(message);
}
}
//----------------------------------------------------------------------------
void vtkErrorSink::SetObservedObject(vtkObject* observedObject)
{
if (observedObject == this->ObservedObject)
{
// no change
return;
}
if (this->ObservedObject)
{
this->ObservedObject->RemoveObservers(vtkCommand::ErrorEvent, this->CallbackCommand);
this->ObservedObject->RemoveObservers(vtkCommand::WarningEvent, this->CallbackCommand);
}
this->ObservedObject = observedObject;
if (this->ObservedObject)
{
this->ObservedObject->AddObserver(vtkCommand::ErrorEvent, this->CallbackCommand);
this->ObservedObject->AddObserver(vtkCommand::WarningEvent, this->CallbackCommand);
}
}
//----------------------------------------------------------------------------
int vtkErrorSink::GetNumberOfMessages()
{
return this->MessageList.size();
}
//----------------------------------------------------------------------------
bool vtkErrorSink::HasErrors()
{
std::vector<vtkErrorSink::Message>::iterator it = this->MessageList.begin();
while (it != this->MessageList.end())
{
if (it->EventId == vtkCommand::ErrorEvent)
{
return true;
}
}
return false;
}
//----------------------------------------------------------------------------
bool vtkErrorSink::HasWarnings()
{
std::vector<vtkErrorSink::Message>::iterator it = this->MessageList.begin();
while (it != this->MessageList.end())
{
if (it->EventId == vtkCommand::WarningEvent)
{
return true;
}
}
return false;
}