ROP/ROP_Dumper.C
#include <fstream.h>
#include <UT/UT_DSOVersion.h>
#include <CH/CH_LocalVariable.h>
#include <PRM/PRM_Include.h>
#include <OP/OP_OperatorTable.h>
#include <OP/OP_Director.h>
#include <SOP/SOP_Node.h>
#include <ROP/ROP_Error.h>
#include <ROP/ROP_Templates.h>
#include "ROP_Dumper.h"
using namespace HDK_Sample;
int *ROP_Dumper::ifdIndirect = 0;
static PRM_Name theFileName("file", "Save to file");
static PRM_Default theFileDefault(0, "junk.out");
static PRM_Template *
getTemplates()
{
static PRM_Template *theTemplate = 0;
if (theTemplate)
return theTemplate;
theTemplate = new PRM_Template[14];
theTemplate[0] = PRM_Template(PRM_FILE, 1, &theFileName, &theFileDefault);
theTemplate[1] = theRopTemplates[ROP_TPRERENDER_TPLATE];
theTemplate[2] = theRopTemplates[ROP_PRERENDER_TPLATE];
theTemplate[3] = theRopTemplates[ROP_LPRERENDER_TPLATE];
theTemplate[4] = theRopTemplates[ROP_TPREFRAME_TPLATE];
theTemplate[5] = theRopTemplates[ROP_PREFRAME_TPLATE];
theTemplate[6] = theRopTemplates[ROP_LPREFRAME_TPLATE];
theTemplate[7] = theRopTemplates[ROP_TPOSTFRAME_TPLATE];
theTemplate[8] = theRopTemplates[ROP_POSTFRAME_TPLATE];
theTemplate[9] = theRopTemplates[ROP_LPOSTFRAME_TPLATE];
theTemplate[10] = theRopTemplates[ROP_TPOSTRENDER_TPLATE];
theTemplate[11] = theRopTemplates[ROP_POSTRENDER_TPLATE];
theTemplate[12] = theRopTemplates[ROP_LPOSTRENDER_TPLATE];
theTemplate[13] = PRM_Template();
return theTemplate;
}
OP_TemplatePair *
ROP_Dumper::getTemplatePair()
{
static OP_TemplatePair *ropPair = 0;
if (!ropPair)
{
OP_TemplatePair *base;
base = new OP_TemplatePair(getTemplates());
ropPair = new OP_TemplatePair(ROP_Node::getROPbaseTemplate(), base);
}
return ropPair;
}
OP_VariablePair *
ROP_Dumper::getVariablePair()
{
static OP_VariablePair *pair = 0;
if (!pair)
pair = new OP_VariablePair(ROP_Node::myVariableList);
return pair;
}
OP_Node *
ROP_Dumper::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
{
return new ROP_Dumper(net, name, op);
}
ROP_Dumper::ROP_Dumper(OP_Network *net, const char *name, OP_Operator *entry)
: ROP_Node(net, name, entry)
{
if (!ifdIndirect)
ifdIndirect = allocIndirect(16);
}
ROP_Dumper::~ROP_Dumper()
{
}
int
ROP_Dumper::startRender(int , float tstart, float tend)
{
myEndTime = tend;
if (error() < UT_ERROR_ABORT)
executePreRenderScript(tstart);
return 1;
}
static void
printNode(ostream &os, OP_Node *node, int indent)
{
UT_WorkBuffer wbuf;
wbuf.sprintf("%*s", indent, "");
os << wbuf.buffer() << node->getName() << endl;
for (int i=0; i<node->getNchildren(); ++i)
printNode(os, node->getChild(i), indent+2);
}
ROP_RENDER_CODE
ROP_Dumper::renderFrame(float time, UT_Interrupt *)
{
executePreFrameScript(time);
UT_String file_name;
OUTPUT(file_name, time);
ofstream os(file_name);
printNode(os, OPgetDirector(), 0);
os.close();
if (error() < UT_ERROR_ABORT)
executePostFrameScript(time);
return ROP_CONTINUE_RENDER;
}
ROP_RENDER_CODE
ROP_Dumper::endRender()
{
if (error() < UT_ERROR_ABORT)
executePostRenderScript(myEndTime);
return ROP_CONTINUE_RENDER;
}
void
newDriverOperator(OP_OperatorTable *table)
{
table->addOperator(new OP_Operator("hdk_dumper",
"Dump Tree",
ROP_Dumper::myConstructor,
ROP_Dumper::getTemplatePair(),
0,
0,
ROP_Dumper::getVariablePair(),
OP_FLAG_GENERATOR));
}