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 <string.h>
00029 #include <malloc.h>
00030 #include <math.h>
00031 #include <UT/UT_DSOVersion.h>
00032 #include <EXPR/EXPR.h>
00033 #include <EXPR/EX_Vector.h>
00034 #include <OP/OP_Director.h>
00035 #include <OP/OP_Operator.h>
00036 #include <OP/OP_Channels.h>
00037 #include <CH/CH_Support.h>
00038 #include <CMD/CMD_Manager.h>
00039
00040
00041
00042
00043
00044
00045 static OP_Node *
00046 getCwd(float &time, int thread)
00047 {
00048 OP_Channels *chp;
00049 CH_Manager *chman;
00050
00051 chman = OPgetDirector()->getChannelManager();
00052 time = chman->getEvaluateTime(thread);
00053 chp = (OP_Channels *)chman->getEvalCollection(thread);
00054 if (!chp) chp = OPgetDirector()->getCwd()->getChannels();
00055
00056 return (chp) ? chp->getNode() : 0;
00057 }
00058
00059
00060
00061
00062
00063
00064 static void
00065 fn_addOpNameDepend1(EV_FUNCTION *func, EV_SYMBOL **argv, void *ref_id)
00066 {
00067 OP_InterestType type;
00068
00069 if( argv[0] == NULL )
00070 return;
00071
00072 if (func->getUserFlags() & CH_EXPRDATA)
00073 type = OP_INTEREST_NAMEDATA;
00074 else
00075 type = OP_INTEREST_NAME;
00076
00077 OP_Node::addExprOpDependency(argv[0]->value.sval, *((OP_RefId *)ref_id),
00078 type);
00079 }
00080
00081 static void
00082 fn_changeOpRef1(EV_FUNCTION *func, EV_SYMBOL **argv, char **new_args,
00083 const char *new_fullpath, const char *old_fullpath,
00084 const char *old_cwd, const char * ,
00085 const char * )
00086 {
00087 if( argv[0] == NULL )
00088 return;
00089
00090 OP_Node::changeExprOpRef(argv[0]->value.sval, new_args[0], new_fullpath,
00091 old_fullpath, old_cwd);
00092 }
00093
00094
00095
00096
00097
00098 static OP_Node *
00099 findOp(int thread,
00100 const char *object, OP_InterestType interest_type = OP_INTEREST_DATA)
00101 {
00102 OP_Node *cwd;
00103 OP_Node *here;
00104 OP_Node *src;
00105 OP_Context context;
00106
00107
00108 here = getCwd(context.myTime, thread);
00109 if (!here) return 0;
00110
00111
00112 cwd = (*object == '/') ? OPgetDirector() : here;
00113
00114 if (*object == '\0' || !strcmp(object, "."))
00115 src = (OP_Node *)cwd;
00116 else src = (OP_Node *)cwd->findNode(object);
00117
00118
00119 if (!src) return 0;
00120
00121
00122
00123
00124
00125
00126 here->addExtraInput(src, interest_type);
00127
00128 return src;
00129 }
00130
00131 #ifndef EV_START_FN
00132 #define EV_START_FN(name) \
00133 static void name(EV_FUNCTION *, EV_SYMBOL *result,\
00134 EV_SYMBOL **argv, int thread)
00135 #endif // EV_START_FN
00136
00137
00138 EV_START_FN(fn_max)
00139 {
00140 if (argv[0]->value.fval > argv[1]->value.fval)
00141 result->value.fval = argv[0]->value.fval;
00142 else result->value.fval = argv[1]->value.fval;
00143 }
00144
00145
00146 EV_START_FN(fn_min)
00147 {
00148 if (argv[0]->value.fval > argv[1]->value.fval)
00149 result->value.fval = argv[1]->value.fval;
00150 else result->value.fval = argv[0]->value.fval;
00151 }
00152
00153
00154
00155
00156 EV_START_FN(fn_optype_proto)
00157 {
00158 OP_Node *node;
00159 const OP_Operator *opdef;
00160
00161 if (node = findOp(thread, argv[0]->value.sval))
00162 {
00163
00164 opdef = node->getOperator();
00165
00166
00167
00168 result->value.sval = strdup(opdef->getName());
00169 }
00170 else result->value.sval = 0;
00171 }
00172
00173 EV_START_FN(fn_vectorsum)
00174 {
00175 ev_Vector *v0 = (ev_Vector *)argv[0]->value.data;
00176 ev_Vector *v1 = (ev_Vector *)argv[1]->value.data;
00177 ev_Vector *sum = (ev_Vector *)result->value.data;
00178
00179 sum->copy(*v0);
00180 sum->add(*v1);
00181 }
00182
00183
00184 #define EVF EV_TYPEFLOAT
00185 #define EVS EV_TYPESTRING
00186 #define EVV EV_TYPEVECTOR
00187
00188 static int floatArgs[] = { EVF, EVF };
00189 static int stringArgs[] = { EVS };
00190 static int vectorArgs[] = { EVV, EVV };
00191
00192 static EV_FUNCTION funcTable[] = {
00193 EV_FUNCTION(0, "max", 2, EVF, floatArgs, fn_max),
00194 EV_FUNCTION(0, "min", 2, EVF, floatArgs, fn_min),
00195 EV_FUNCTION(0, "optype_proto", 1, EVS, stringArgs, fn_optype_proto),
00196 EV_FUNCTION(0, "vectorsum", 2, EVV, vectorArgs, fn_vectorsum),
00197 EV_FUNCTION(),
00198 };
00199
00200 void
00201 CMDextendLibrary(CMD_Manager *)
00202 {
00203 int i;
00204
00205 for (i = 0; funcTable[i].getName(); i++)
00206 ev_AddFunction(&funcTable[i]);
00207
00208
00209
00210 ev_SetFunctionDependencyCallbacks("optype_proto", fn_addOpNameDepend1,
00211 fn_changeOpRef1);
00212 }