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