HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SOP_GroupRename.C
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  * The GroupRename SOP. This SOP renames groups.
27  */
28 
29 #include "SOP_GroupRename.h"
30 
31 #include <GU/GU_Detail.h>
32 #include <OP/OP_AutoLockInputs.h>
33 #include <OP/OP_Operator.h>
34 #include <OP/OP_OperatorTable.h>
35 #include <PRM/PRM_Include.h>
36 #include <UT/UT_DSOVersion.h>
37 
38 using namespace HDK_Sample;
39 
40 void
42 {
43  table->addOperator(new OP_Operator(
44  "hdk_grouprename",
45  "GroupRename",
48  1,
49  1,
50  0));
51 }
52 
53 static PRM_Name names[] = {
54  PRM_Name("oldname", "Old Name"),
55  PRM_Name("newname", "New Name"),
56 };
57 
60  PRM_Template(PRM_STRING, 1, &names[0], 0, &SOP_Node::groupMenu),
61  PRM_Template(PRM_STRING, 1, &names[1]),
62  PRM_Template(),
63 };
64 
65 
66 OP_Node *
68 {
69  return new SOP_GroupRename(net, name, op);
70 }
71 
73  : SOP_Node(net, name, op)
74 {
75  // This SOP is a special case for data IDs. It's important to note
76  // that the name is *not* part of the data that the ID is identifying.
77  // That way, attributes with different names can be identified as
78  // having the same data.
80 }
81 
83 
86 {
87  // We must lock our inputs before we try to access their geometry.
88  // OP_AutoLockInputs will automatically unlock our inputs when we return.
89  // NOTE: Don't call unlockInputs yourself when using this!
90  OP_AutoLockInputs inputs(this);
91  if (inputs.lock(context) >= UT_ERROR_ABORT)
92  return error();
93 
94  // Duplicate incoming geometry.
95  duplicateSource(0, context);
96 
97  fpreal now = context.getTime();
98  UT_String oldname;
99  OLDNAME(oldname, now);
100  UT_String newname_str;
101  NEWNAME(newname_str, now);
102 
103  // Rename all matching groups.
104  UT_StringHolder newname(newname_str);
107 
108  // NOTE: No data IDs need to be bumped when just renaming an attribute,
109  // because the data is considered to exclude the name.
110 
111  return error();
112 }
113 
114 const char *
116 {
117  return "Geometry to Rename Groups in";
118 }
virtual OP_ERROR error()
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
PRM_API const PRM_Type PRM_STRING
OP_ERROR lock(OP_Context &context)
Locks all inputs.
fpreal getTime() const
Definition: OP_Context.h:62
UT_ErrorSeverity
Definition: UT_Error.h:25
static PRM_Template myTemplateList[]
void newSopOperator(OP_OperatorTable *table)
bool addOperator(OP_Operator *op, std::ostream *err=nullptr)
const GA_ElementGroupTable & getElementGroupTable(GA_AttributeOwner owner) const
SOP_NodeFlags mySopFlags
Definition: SOP_Node.h:1625
GLuint const GLchar * name
Definition: glcorearb.h:786
GLenum GLenum GLsizei void * table
Definition: glad.h:5129
void setManagesDataIDs(bool onOff)
Definition: SOP_NodeFlags.h:36
static PRM_ChoiceList groupMenu
Definition: SOP_Node.h:1188
const char * inputLabel(unsigned idx) const override
GU_Detail * gdp
Definition: SOP_Node.h:1622
OP_ERROR cookMySop(OP_Context &context) override
fpreal64 fpreal
Definition: SYS_Types.h:277
SOP_GroupRename(OP_Network *net, const char *name, OP_Operator *op)
bool renameGroup(const UT_StringRef &fromname, const UT_StringHolder &toname)
OP_ERROR duplicateSource(unsigned index, OP_Context &context, GU_Detail *gdp, bool clean=true)