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 #include "DOP_GroupAndApply.h"
00029 #include <UT/UT_DSOVersion.h>
00030 #include <SIM/SIM_DataFilter.h>
00031 #include <SIM/SIM_Relationship.h>
00032 #include <SIM/SIM_RelationshipGroup.h>
00033 #include <OP/OP_OperatorTable.h>
00034 #include <DOP/DOP_PRMShared.h>
00035 #include <DOP/DOP_InOutInfo.h>
00036 #include <DOP/DOP_Operator.h>
00037 #include <DOP/DOP_Engine.h>
00038
00039 using namespace HDK_Sample;
00040
00041 void
00042 newDopOperator(OP_OperatorTable *table)
00043 {
00044 OP_Operator *op;
00045
00046
00047
00048
00049
00050 op = new DOP_Operator("hdk_groupandapply", "Group and Apply",
00051 DOP_GroupAndApply::myConstructor,
00052 DOP_GroupAndApply::myTemplateList, 1, 9999, 0,
00053 0, 1);
00054 table->addOperator(op);
00055 }
00056
00057 static PRM_Name theInputIndexName("inputindex", "Input Index");
00058
00059 PRM_Template
00060 DOP_GroupAndApply::myTemplateList[] = {
00061
00062 PRM_Template(PRM_INT_J, 1, &DOPactivationName,
00063 &DOPactivationDefault),
00064
00065 PRM_Template(PRM_STRING, 1, &DOPgroupName, &DOPgroupDefault,
00066 &DOPgroupMenu),
00067
00068
00069 PRM_Template(PRM_INT_J, 1, &theInputIndexName, PRMzeroDefaults),
00070 PRM_Template()
00071 };
00072
00073 OP_Node *
00074 DOP_GroupAndApply::myConstructor(OP_Network *net, const char *name,
00075 OP_Operator *op)
00076 {
00077 return new DOP_GroupAndApply(net, name, op);
00078 }
00079
00080 DOP_GroupAndApply::DOP_GroupAndApply(OP_Network *net, const char *name,
00081 OP_Operator *op)
00082 : DOP_Node(net, name, op)
00083 {
00084 }
00085
00086 DOP_GroupAndApply::~DOP_GroupAndApply()
00087 {
00088 }
00089
00090 void
00091 DOP_GroupAndApply::processObjectsSubclass(fpreal time, int,
00092 const SIM_ObjectArray &objects,
00093 DOP_Engine &engine)
00094 {
00095 SIM_ObjectArray filtered;
00096 UT_String group;
00097 int i, inputindex;
00098
00099
00100
00101
00102
00103 GROUP(group, time);
00104 SIM_DataFilterRootData filter(group);
00105 objects.filter(filter, filtered);
00106
00107
00108 for( i = 0; i < filtered.entries(); i++ )
00109 {
00110
00111
00112
00113
00114
00115
00116 setCurrentObject(i, filtered.entries(), filtered(i));
00117
00118
00119
00120
00121
00122
00123
00124 if( isActive(time) )
00125 {
00126
00127
00128
00129
00130
00131 inputindex = INPUTINDEX(time) + 1;
00132 if( inputindex != 0 && getInput(inputindex) )
00133 {
00134 SIM_Relationship *relationship;
00135 UT_String addtogroup;
00136 char numstr[UT_NUMBUF];
00137
00138
00139
00140 applyDataFromInput(time, inputindex, inputindex,
00141 *filtered(i),
00142 0, engine, 0, true);
00143
00144 UT_String::itoa(numstr, inputindex);
00145 addtogroup = "applygroup_";
00146 addtogroup += numstr;
00147
00148
00149
00150 relationship = engine.addRelationship(addtogroup,
00151 SIM_DATA_RETURN_EXISTING);
00152 if( relationship )
00153 {
00154 relationship->addGroup(filtered(i));
00155 SIM_DATA_CREATE(*relationship, SIM_RELGROUP_DATANAME,
00156 SIM_RelationshipGroup,
00157 SIM_DATA_RETURN_EXISTING);
00158 }
00159 else
00160 addError(DOP_CANTCREATERELATIONSHIP);
00161 }
00162 }
00163 }
00164 }
00165
00166 void
00167 DOP_GroupAndApply::getInputInfoSubclass(int inputidx, DOP_InOutInfo &info)
00168 {
00169
00170
00171 if( inputidx == 0 )
00172 info = DOP_InOutInfo(DOP_INOUT_OBJECTS, false);
00173 else
00174 info = DOP_InOutInfo(DOP_INOUT_DATA, true);
00175 }
00176
00177 void
00178 DOP_GroupAndApply::getOutputInfoSubclass(int , DOP_InOutInfo &info)
00179 {
00180
00181 info = DOP_InOutInfo(DOP_INOUT_OBJECTS, false);
00182 }
00183
00184 void
00185 DOP_GroupAndApply::GROUP(UT_String &str, fpreal t)
00186 {
00187 evalString(str, DOPgroupName.getToken(), 0, t);
00188 }
00189
00190 int
00191 DOP_GroupAndApply::INPUTINDEX(float t)
00192 {
00193 return evalInt(theInputIndexName.getToken(), 0, t);
00194 }
00195