Commit 506d3207 authored by David Cole's avatar David Cole
Browse files

BUG: Fix problem using stream eof() method which was yielding bogus events...

BUG: Fix problem using stream eof() method which was yielding bogus events when reading past the end of the stream on some Borland dashboards. Replace with loop of SystemTools::GetLineFromStream calls. Fixes failing InteractorStyleTreeMapHover test on dash14.
parent 9d0b78ec
......@@ -18,8 +18,9 @@
#include "vtkRenderWindowInteractor.h"
#include <vtksys/ios/sstream>
#include <vtksys/SystemTools.hxx>
vtkCxxRevisionMacro(vtkInteractorEventRecorder, "1.15");
vtkCxxRevisionMacro(vtkInteractorEventRecorder, "1.16");
vtkStandardNewMacro(vtkInteractorEventRecorder);
float vtkInteractorEventRecorder::StreamVersion = 1.0f;
......@@ -195,26 +196,27 @@ void vtkInteractorEventRecorder::Play()
this->State = vtkInteractorEventRecorder::Playing;
// Read events and invoke them on the object in question
char event[128], keySym[64], buffer[512];
char event[128], keySym[64];
int pos[2], ctrlKey, shiftKey, keyCode, repeatCount;
float stream_version = 0.0f, tempf;
vtksys_stl::string line;
while ( ! this->InputStream->eof() )
while ( vtksys::SystemTools::GetLineFromStream(*this->InputStream, line) )
{
this->InputStream->width(256);
*this->InputStream >> event;
vtksys_ios::istringstream iss(line);
iss.width(256);
iss >> event;
// Quick skip comment
if (*event == '#')
{
this->InputStream->getline(buffer, 512);
// Parse the StreamVersion (not using >> since comment could be empty)
// Expecting: # StreamVersion x.y
if (strlen(buffer) > 15 && !strncmp(buffer, " StreamVersion ", 15))
if (strlen(line.c_str()) > 16 &&
!strncmp(line.c_str(), "# StreamVersion ", 16))
{
int res = sscanf(buffer + 15, "%f", &tempf);
int res = sscanf(line.c_str() + 16, "%f", &tempf);
if (res && res != EOF)
{
stream_version = tempf;
......@@ -224,31 +226,27 @@ void vtkInteractorEventRecorder::Play()
else
{
unsigned long ievent = vtkCommand::GetEventIdFromString(event);
if (ievent == vtkCommand::NoEvent)
{
this->InputStream->ignore(512, '\n');
}
else
if (ievent != vtkCommand::NoEvent)
{
if (stream_version >= 1.1)
{
// We could grab the time info here
}
*this->InputStream >> pos[0];
*this->InputStream >> pos[1];
*this->InputStream >> ctrlKey;
*this->InputStream >> shiftKey;
*this->InputStream >> keyCode;
*this->InputStream >> repeatCount;
*this->InputStream >> keySym;
iss >> pos[0];
iss >> pos[1];
iss >> ctrlKey;
iss >> shiftKey;
iss >> keyCode;
iss >> repeatCount;
iss >> keySym;
this->Interactor->SetEventPosition(pos);
this->Interactor->SetControlKey(ctrlKey);
this->Interactor->SetShiftKey(shiftKey);
this->Interactor->SetKeyCode(keyCode);
this->Interactor->SetRepeatCount(repeatCount);
this->Interactor->SetKeySym(keySym);
this->Interactor->InvokeEvent(ievent, NULL);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment