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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/*=========================================================================
Program: ParaView
Module: $RCSfile$
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPythonAnimationCue.h"
#include "vtkCommand.h"
#include "vtkObjectFactory.h"
#include "vtkProcessModule.h"
#include "vtkPythonInterpreter.h"
#include <sstream>
vtkStandardNewMacro(vtkPythonAnimationCue);
//----------------------------------------------------------------------------
vtkPythonAnimationCue::vtkPythonAnimationCue()
{
this->Enabled = true;
this->Script = 0;
this->AddObserver(vtkCommand::StartAnimationCueEvent,
this, &vtkPythonAnimationCue::HandleStartCueEvent);
this->AddObserver(vtkCommand::AnimationCueTickEvent,
this, &vtkPythonAnimationCue::HandleTickEvent);
this->AddObserver(vtkCommand::EndAnimationCueEvent,
this, &vtkPythonAnimationCue::HandleEndCueEvent);
}
//----------------------------------------------------------------------------
vtkPythonAnimationCue::~vtkPythonAnimationCue()
{
this->SetScript(NULL);
}
//----------------------------------------------------------------------------
void vtkPythonAnimationCue::HandleStartCueEvent()
{
if (!this->Enabled)
{
return;
}
// Set self to point to this
char addrofthis[1024];
sprintf(addrofthis, "%p", this);
char *aplus = addrofthis;
if ((addrofthis[0] == '0') &&
((addrofthis[1] == 'x') || addrofthis[1] == 'X'))
{
aplus += 2; //skip over "0x"
}
if (this->Script)
{
std::ostringstream stream;
stream << "from paraview import servermanager" << endl;
stream << "def start_cue(foo): pass" << endl;
stream << this->Script << endl;
stream << "_me = servermanager.vtkPythonAnimationCue('" << aplus << "')\n";
stream << "try:\n";
stream << " start_cue(_me)\n";
stream << "finally:\n"
" del _me\n"
" import gc\n"
" gc.collect()\n";
// ensure Python is initialized.
vtkPythonInterpreter::Initialize();
vtkPythonInterpreter::RunSimpleString(stream.str().c_str());
}
}
//----------------------------------------------------------------------------
void vtkPythonAnimationCue::HandleTickEvent()
{
if (!this->Enabled)
{
return;
}
// Set self to point to this
char addrofthis[1024];
sprintf(addrofthis, "%p", this);
char *aplus = addrofthis;
if ((addrofthis[0] == '0') &&
((addrofthis[1] == 'x') || addrofthis[1] == 'X'))
{
aplus += 2; //skip over "0x"
}
if (this->Script)
{
std::ostringstream stream;
stream << "from paraview import servermanager" << endl;
stream << this->Script << endl;
stream << "_me = servermanager.vtkPythonAnimationCue('" << aplus << "')\n";
stream << "try:\n";
stream << " tick(_me)\n";
stream << "finally:\n"
" del _me\n"
" import gc\n"
" gc.collect()\n";
// ensure Python is initialized.
vtkPythonInterpreter::Initialize();
vtkPythonInterpreter::RunSimpleString(stream.str().c_str());
}
}
//----------------------------------------------------------------------------
void vtkPythonAnimationCue::HandleEndCueEvent()
{
if (!this->Enabled)
{
return;
}
// Set self to point to this
char addrofthis[1024];
sprintf(addrofthis, "%p", this);
char *aplus = addrofthis;
if ((addrofthis[0] == '0') &&
((addrofthis[1] == 'x') || addrofthis[1] == 'X'))
{
aplus += 2; //skip over "0x"
}
if (this->Script)
{
std::ostringstream stream;
stream << "from paraview import servermanager" << endl;
stream << "def end_cue(foo): pass" << endl;
stream << this->Script << endl;
stream << "_me = servermanager.vtkPythonAnimationCue('" << aplus << "')\n";
stream << "try:\n";
stream << " end_cue(_me)\n";
stream << "finally:\n"
" del _me\n"
" import gc\n"
" gc.collect()\n";
vtkPythonInterpreter::Initialize();
vtkPythonInterpreter::RunSimpleString(stream.str().c_str());
}
}
//----------------------------------------------------------------------------
void vtkPythonAnimationCue::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Enabled: " << this->Enabled << endl;
os << indent << "Script: " << this->Script << endl;
}
|