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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include <OSGGraphOpSeq.h>
00045 #include <OSGGraphOpFactory.h>
00046
00047 OSG_USING_NAMESPACE
00048
00049
00050
00051
00052
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 GraphOpSeq::GraphOpSeq(): _GraphOperators(), _excludeNames()
00073 {
00074 }
00075
00076 GraphOpSeq::GraphOpSeq(const std::string params):
00077 _GraphOperators(), _excludeNames()
00078 {
00079 setGraphOps(params);
00080 }
00081
00082 GraphOpSeq::~GraphOpSeq()
00083 {
00084 }
00085
00086 bool GraphOpSeq::run(NodePtr &root)
00087 {
00088 bool res=true;
00089 std::vector<GraphOp *>::iterator it=_GraphOperators.begin();
00090 std::vector<GraphOp *>::iterator en=_GraphOperators.end();
00091
00092 for ( ; it != en; ++it )
00093 {
00094 bool b = (*it)->traverse(root);
00095 res = res & b;
00096 if (!b)
00097 FWARNING(("GraphOpSeq: GraphOp %s could not traverse the scene correctly\n",(*it)->getName().c_str()));
00098 }
00099
00100 return res;
00101 }
00102
00125 void GraphOpSeq::setGraphOps(const std::string params)
00126 {
00127 UInt16 counter = 0;
00128 while (counter < params.length())
00129 {
00130
00131 while (params[counter]==' ')
00132 counter++;
00133
00134 std::string command;
00135 counter = extractStr(params, counter, ")", command) + 1;
00136 FDEBUG(("command: %s\n", command.c_str()));
00137
00138
00139 std::string goname;
00140 UInt16 pos = extractStr(command, 0, "(", goname);
00141 FDEBUG(("GraphOpSeq::setGraphOps: goname: %s\n",goname.c_str()));
00142
00143 GraphOp * go = GraphOpFactory::the().create(goname.c_str());
00144 if (go == NULL)
00145 {
00146 if (goname=="Exclude" || goname=="AddExclude")
00147 {
00148 if (goname=="Exclude")
00149 _excludeNames.clear();
00150
00151 std::string cparams;
00152 extractStr(command, pos, ")", cparams);
00153 FDEBUG(("GraphOpSeq::setGraphOps: cparams: %s\n", cparams.c_str()));
00154 UInt16 i = 0;
00155 while(i < cparams.length())
00156 {
00157 std::string ename;
00158 i = extractStr(cparams, i, ",", ename);
00159 _excludeNames.push_back(ename);
00160 FDEBUG(("GraphOpSeq::setGraphOps: ename: %s\n",ename.c_str()));
00161 }
00162
00163 }
00164 else
00165 FWARNING(("GraphOpSeq::setGraphOps: Invalid GraphOp name given: %s\n",goname.c_str()));
00166 }
00167 else
00168 {
00169 std::string goparams;
00170 extractStr(command, pos, ")", goparams);
00171 FDEBUG(("GraphOpSeq::setGraphOps: goparams: %s\n", goparams.c_str()));
00172 go->setParams(goparams);
00173 std::list<std::string>::iterator it=_excludeNames.begin();
00174 for (; it!=_excludeNames.end(); ++it)
00175 {
00176 go->addToExcludeList(*it);
00177 FDEBUG(("GraphOpSeq::setGraphOps: Added to op: %s\n",(*it).c_str()));
00178 }
00179 _GraphOperators.push_back(go);
00180 }
00181 }
00182 }
00183
00184 void GraphOpSeq::addGraphOp(GraphOp *op)
00185 {
00186 _GraphOperators.push_back(op);
00187 }
00188
00189 void GraphOpSeq::removeGraphOp(GraphOp *op)
00190 {
00191 std::vector<GraphOp *>::iterator it=_GraphOperators.begin();
00192 for (; it!=_GraphOperators.end(); ++it)
00193 if (*it==op)
00194 {
00195 _GraphOperators.erase(it);
00196 break;
00197 }
00198 }
00199
00200 void GraphOpSeq::clearGraphOps(void)
00201 {
00202 _GraphOperators.clear();
00203 }
00204
00205 UInt16 GraphOpSeq::getSize(void)
00206 {
00207 return _GraphOperators.size();
00208 }
00209
00210 GraphOp* GraphOpSeq::getGraphOp(UInt16 index)
00211 {
00212 if (index<getSize())
00213 return _GraphOperators[index];
00214 else
00215 return NULL;
00216 }
00217
00218 bool GraphOpSeq::setGraphOp(UInt16 index, GraphOp *op)
00219 {
00220 if (index<getSize())
00221 {
00222 _GraphOperators[index]=op;
00223 return true;
00224 }
00225 else
00226 return false;
00227 }
00228
00229 bool GraphOpSeq::removeGraphOp(UInt16 index)
00230 {
00231 if (index<getSize())
00232 {
00233 _GraphOperators.erase(_GraphOperators.begin()+index);
00234 return true;
00235 }
00236 else
00237 return false;
00238 }
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 UInt16 GraphOpSeq::extractStr(const std::string param, UInt16 spos,
00249 char* delim, std::string& result)
00250 {
00251 std::string::size_type pos = param.find(delim,spos);
00252 if (pos == std::string::npos)
00253 pos = param.length();
00254
00255 result=param.substr(spos,pos-spos);
00256 return pos+1;
00257 }