SOP/SOP_BlindData.C
#include <UT/UT_CPIO.h>
#include <UT/UT_DSOVersion.h>
#include <GU/GU_Detail.h>
#include <PRM/PRM_Include.h>
#include <OP/OP_Operator.h>
#include <OP/OP_OperatorTable.h>
#include <OP/OP_SaveFlags.h>
#include "SOP_BlindData.h"
using namespace HDK_Sample;
void
newSopOperator(OP_OperatorTable *table)
{
table->addOperator(new OP_Operator("hdk_blinddata",
"BlindData",
SOP_BlindData::myConstructor,
SOP_BlindData::myTemplateList,
1,
1,
0));
}
PRM_Template
SOP_BlindData::myTemplateList[] = {
PRM_Template(),
};
OP_Node *
SOP_BlindData::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
{
return new SOP_BlindData(net, name, op);
}
SOP_BlindData::SOP_BlindData(OP_Network *net, const char *name, OP_Operator *op)
: SOP_Node(net, name, op)
{
}
SOP_BlindData::~SOP_BlindData() {}
OP_ERROR
SOP_BlindData::cookMySop(OP_Context &context)
{
if (lockInputs(context) >= UT_ERROR_ABORT)
return error();
duplicateSource(0, context);
unlockInputs();
return error();
}
const char *
SOP_BlindData::inputLabel(unsigned) const
{
return "Source Geometry";
}
static const char *theExtension = "mydata";
OP_ERROR
SOP_BlindData::save(ostream &os, const OP_SaveFlags &flags,
const char *path_prefix)
{
UT_CPIO packet;
char path[UT_SMALLBUF];
clearErrors();
if (SOP_Node::save(os, flags, path_prefix) >= UT_ERROR_ABORT)
return error();
ostrstream ts(path, UT_SMALLBUF); ts << path_prefix << getName() << "."
<< theExtension << ends;
packet.open(os, path);
savePrivateData(os, flags.getBinary());
packet.close(os);
return error();
}
bool
SOP_BlindData::load(UT_IStream &is, const char *extension, const char *path)
{
if (!strcmp(extension, theExtension))
{
loadPrivateData(is);
return (error() < UT_ERROR_ABORT);
}
return SOP_Node::load(is, extension, path);
}
int
SOP_BlindData::loadPrivateData(UT_IStream &is)
{
UT_String data;
bool result;
result = data.load(is);
return !result ? 0 : 1;
}
int
SOP_BlindData::savePrivateData(ostream &os, int binary)
{
UT_String data;
data = "This is my private data";
data.save(os, binary);
return !os ? 0 : 1;
}