00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <UT/UT_DSOVersion.h>
00030 #include <GU/GU_Detail.h>
00031 #include <PRM/PRM_Include.h>
00032 #include <OP/OP_Operator.h>
00033 #include <OP/OP_OperatorTable.h>
00034 #include "SOP_GroupRename.h"
00035
00036 using namespace HDK_Sample;
00037
00038 void
00039 newSopOperator(OP_OperatorTable *table)
00040 {
00041 table->addOperator(new OP_Operator("hdk_grouprename",
00042 "GroupRename",
00043 SOP_GroupRename::myConstructor,
00044 SOP_GroupRename::myTemplateList,
00045 1,
00046 1,
00047 0));
00048 }
00049
00050 static PRM_Name names[] = {
00051 PRM_Name("oldname", "Old Name"),
00052 PRM_Name("newname", "New Name"),
00053 };
00054
00055 PRM_Template
00056 SOP_GroupRename::myTemplateList[] = {
00057 PRM_Template(PRM_STRING, 1, &names[0], 0, &SOP_Node::groupMenu),
00058 PRM_Template(PRM_STRING, 1, &names[1]),
00059 PRM_Template(),
00060 };
00061
00062
00063 OP_Node *
00064 SOP_GroupRename::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
00065 {
00066 return new SOP_GroupRename(net, name, op);
00067 }
00068
00069 SOP_GroupRename::SOP_GroupRename(OP_Network *net, const char *name, OP_Operator *op)
00070 : SOP_Node(net, name, op)
00071 {
00072 }
00073
00074 SOP_GroupRename::~SOP_GroupRename() {}
00075
00076 unsigned
00077 SOP_GroupRename::disableParms()
00078 {
00079 unsigned changed = 0;
00080
00081 return changed;
00082 }
00083
00084
00085 OP_ERROR
00086 SOP_GroupRename::cookInputGroups(OP_Context &context, int alone)
00087 {
00088 return error();
00089 }
00090
00091 static bool
00092 sopRenameGroups( const GB_GroupList &grp_list,
00093 const UT_String &from, const UT_String &to )
00094 {
00095 bool renamed = false;
00096 GB_Group *curr;
00097 UT_String string;
00098
00099 for (curr = grp_list.head(); curr; curr = (GB_Group *)curr->next())
00100 {
00101 string.harden(curr->getName());
00102 string.patternRename(from, to);
00103 if (strcmp(string, curr->getName()))
00104 {
00105 curr->setName(string);
00106 renamed = true;
00107 }
00108 }
00109 return renamed;
00110 }
00111
00112 OP_ERROR
00113 SOP_GroupRename::cookMySop(OP_Context &context)
00114 {
00115 float now = context.myTime;
00116 UT_String oldname, newname;
00117
00118
00119
00120 if (lockInputs(context) >= UT_ERROR_ABORT)
00121 return error();
00122
00123
00124 duplicateSource(0, context);
00125
00126 OLDNAME(oldname, now);
00127 NEWNAME(newname, now);
00128
00129
00130 sopRenameGroups(gdp->primitiveGroups(), oldname, newname);
00131 sopRenameGroups(gdp->pointGroups(), oldname, newname);
00132
00133 unlockInputs();
00134
00135 return error();
00136 }
00137
00138 const char *
00139 SOP_GroupRename::inputLabel(unsigned) const
00140 {
00141 return "Geometry to Rename Groups in";
00142 }