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
00030
00031
00032
00033
00034 #ifndef __OP_INPUTCHANGEHELPER_H__
00035 #define __OP_INPUTCHANGEHELPER_H__
00036
00037 #include "OP_API.h"
00038 #include <UT/UT_Assert.h>
00039 #include <UT/UT_IntArray.h>
00040 #include "OP_Node.h"
00041
00042 class OP_API OP_InputChangeHelper
00043 {
00044 public:
00045
00046
00047 void resetChangedSourceFlags()
00048 {
00049 myDuplicateCounts.resize(0);
00050 }
00051
00052
00053
00054
00055 void inputConnectChanged(const OP_Node &node, int which_input)
00056 {
00057 if (which_input >= 0)
00058 setDuplicateCount(which_input, -1, node.maxInputs());
00059 else
00060 resetChangedSourceFlags();
00061 }
00062
00063
00064
00065
00066
00067
00068 bool useInput(const OP_Node &node, unsigned idx, bool &changed, bool force)
00069 {
00070
00071
00072 if (!checkChangedSourceFlags(node, idx, changed))
00073 return false;
00074
00075 if (force || changed)
00076 {
00077 OP_Node * src = node.getInput(idx);
00078
00079 setDuplicateCount(idx, src->getCookCount(), node.maxInputs());
00080
00081 changed = true;
00082 }
00083
00084
00085 return true;
00086 }
00087
00088
00089
00090
00091 bool checkChangedSourceFlags(const OP_Node &node, unsigned idx,
00092 bool &changed)
00093 {
00094 OP_Node * src;
00095
00096 src = node.getInput(idx);
00097 if (!src || src->error() >= UT_ERROR_ABORT)
00098 {
00099 changed = true;
00100 return false;
00101 }
00102
00103 changed = (src->getCookCount() != getDuplicateCount(idx));
00104 return true;
00105 }
00106
00107 private:
00108 int getDuplicateCount(int idx)
00109 {
00110 if (idx >= 0 && idx < myDuplicateCounts.entries())
00111 return myDuplicateCounts(idx);
00112 return -1;
00113 }
00114 void setDuplicateCount(int idx, int count, int max_inputs)
00115 {
00116 if (idx >= 0 && idx < max_inputs)
00117 {
00118 while (idx >= myDuplicateCounts.entries())
00119 myDuplicateCounts.append(-1);
00120 myDuplicateCounts(idx) = count;
00121 }
00122 else
00123 {
00124 UT_ASSERT(!"Untested code path");
00125 myDuplicateCounts.entries(0);
00126 }
00127 }
00128
00129 private:
00130 UT_IntArray myDuplicateCounts;
00131 };
00132
00133 #endif // __OP_INPUTCHANGEHELPER_H__