Commit 16af4707 authored by Will Schroeder's avatar Will Schroeder
Browse files

ENH:Playback from string

parent b45e9ede
......@@ -20,7 +20,7 @@
#include "vtkObjectFactory.h"
#include "vtkRenderWindowInteractor.h"
vtkCxxRevisionMacro(vtkInteractorEventRecorder, "1.3");
vtkCxxRevisionMacro(vtkInteractorEventRecorder, "1.4");
vtkStandardNewMacro(vtkInteractorEventRecorder);
float vtkInteractorEventRecorder::StreamVersion = 1.0;
......@@ -41,6 +41,8 @@ vtkInteractorEventRecorder::vtkInteractorEventRecorder()
this->InputStream = NULL;
this->OutputStream = NULL;
this->ReadFromInputString = 0;
this->InputString = NULL;
}
vtkInteractorEventRecorder::~vtkInteractorEventRecorder()
......@@ -121,9 +123,11 @@ void vtkInteractorEventRecorder::Record()
delete this->OutputStream;
return;
}
*this->OutputStream << "# StreamVersion " << vtkInteractorEventRecorder::StreamVersion << "\n";
*this->OutputStream << "# StreamVersion "
<< vtkInteractorEventRecorder::StreamVersion << "\n";
}
vtkDebugMacro(<<"Recording");
this->State = vtkInteractorEventRecorder::Recording;
}
}
......@@ -132,16 +136,36 @@ void vtkInteractorEventRecorder::Play()
{
if ( this->State == vtkInteractorEventRecorder::Start )
{
if ( ! this->InputStream ) //need to open file
if ( this->ReadFromInputString )
{
this->InputStream = new ifstream(this->FileName, ios::in);
vtkDebugMacro(<< "Reading from InputString");
int len;
if ( this->InputString == NULL || (len = strlen(this->InputString) <= 0) )
{
vtkErrorMacro(<< "No input string specified");
return;
}
this->InputStream = new istrstream(this->InputString, len);
if (this->InputStream->fail())
{
vtkErrorMacro(<< "Unable to open file: "<< this->FileName);
vtkErrorMacro(<< "Unable to read from string");
delete this->InputStream;
return;
}
}
else
{
if ( ! this->InputStream ) //need to open file
{
this->InputStream = new ifstream(this->FileName, ios::in);
if (this->InputStream->fail())
{
vtkErrorMacro(<< "Unable to open file: "<< this->FileName);
delete this->InputStream;
return;
}
}
}
vtkDebugMacro(<<"Playing");
this->State = vtkInteractorEventRecorder::Playing;
......@@ -157,7 +181,6 @@ void vtkInteractorEventRecorder::Play()
*this->InputStream >> event;
// Quick skip comment
if (*event == '#')
{
this->InputStream->getline(buffer, 512);
......@@ -342,6 +365,18 @@ void vtkInteractorEventRecorder::PrintSelf(ostream& os, vtkIndent indent)
{
os << indent << "File Name: " << this->FileName << "\n";
}
os << indent << "ReadFromInputString: "
<< (this->ReadFromInputString ? "On\n" : "Off\n");
if ( this->InputString )
{
os << indent << "Input String: " << this->InputString << "\n";
}
else
{
os << indent << "Input String: (None)\n";
}
}
......
......@@ -15,13 +15,18 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkInteractorEventRecorder - record VTK events to a file; play them back to an object
// .NAME vtkInteractorEventRecorder - record and play VTK events passing through a vtkRenderWindowInteractor
// .SECTION Description
// vtkInteractorEventRecorder records all VTK events invoked from a
// vtkRenderWindowInteractor. The events are recorded to a
// file. vtkInteractorEventRecorder can also be used to play those events
// back and invoke them on an vtkRenderWindowInteractor.
// back and invoke them on an vtkRenderWindowInteractor. (Note: the events
// can also be played back from a file or string.)
//
// The format of the event file is simple. It is:
// EventName X Y ctrl shift keycode repeatCount keySym
// The format also allows "#" comments.
// .SECTION See Also
// vtkInteractorObserver vtkCallback
......@@ -67,12 +72,28 @@ public:
// Rewind to the beginning of the file.
void Rewind();
// Description:
// Enable reading from an InputString as compared to the default
// behavior, which is to read from a file.
vtkSetMacro(ReadFromInputString,int);
vtkGetMacro(ReadFromInputString,int);
vtkBooleanMacro(ReadFromInputString,int);
// Description:
// Set/Get the string to read from.
vtkSetStringMacro(InputString);
vtkGetStringMacro(InputString);
protected:
vtkInteractorEventRecorder();
~vtkInteractorEventRecorder();
// file to read/write from
char *FileName;
// control whether to read from string
int ReadFromInputString;
char *InputString;
// for reading and writing
istream *InputStream;
......
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