00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __SeExprEdEditable__
00014 #define __SeExprEdEditable__
00015 #include <sstream>
00016 #include <SeVec3d.h>
00017 #include <SeCurve.h>
00018 #include <cstdio>
00019 #include <cstring>
00020 #include <SeExprMacros.h>
00021 #ifdef SEEXPR_USE_ANIMLIB
00022 # include <animlib/AnimCurve.h>
00023 # include <animlib/AnimKeyframe.h>
00024 #endif
00025 inline void printVal(std::stringstream& stream,double v){stream<<v;}
00026 inline void printVal(std::stringstream& stream,const SeVec3d& v){stream<<"["<<v[0]<<","<<v[1]<<","<<v[2]<<"]";}
00027
00028 struct SeExprEdEditable
00029 {
00030 std::string name;
00031 int startPos,endPos;
00032
00033
00034 SeExprEdEditable(const std::string& name,int startPos,int endPos)
00035 :name(name),startPos(startPos),endPos(endPos)
00036 {
00037
00038 }
00039
00040 void updatePositions(const SeExprEdEditable& other)
00041 {
00042 startPos=other.startPos;endPos=other.endPos;
00043 }
00044
00045 virtual ~SeExprEdEditable(){}
00046
00048 virtual bool parseComment(const std::string& comment)=0;
00049 virtual std::string str() const{return std::string("<unknown>");}
00050 virtual void appendString(std::stringstream& stream) const=0;
00051 virtual bool controlsMatch(const SeExprEdEditable&) const=0;
00052
00053 };
00054
00055
00056 struct SeExprEdNumberEditable:public SeExprEdEditable
00057 {
00058 double v;
00059 double min,max;
00060 bool isInt;
00061 SeExprEdNumberEditable(const std::string& name,int startPos,int endPos,double val)
00062 :SeExprEdEditable(name,startPos,endPos),v(val),min(0),max(1),isInt(false)
00063 {}
00064
00065 bool parseComment(const std::string& comment){
00066 if (comment.find('.') != std::string::npos || comment.find('e') != std::string::npos)
00067 {
00068 float fmin,fmax;
00069 if (sscanf(comment.c_str(),"#%f,%f",&fmin,&fmax)==2)
00070 {
00071 min=fmin;
00072 max=fmax;
00073 isInt=false;
00074 return true;
00075 }
00076 }
00077 int imin,imax;
00078 if (sscanf(comment.c_str(),"#%d,%d",&imin,&imax)==2)
00079 {
00080 min=imin;
00081 max=imax;
00082 isInt=true;
00083 return true;
00084 }
00085 return true;
00086 }
00087 std::string str() const{
00088 std::stringstream s;
00089 s<<name<<" "<<v<<" in ["<<min<<","<<max<<"] subset "<<(isInt?"Integers":"Reals");
00090 return s.str();
00091 }
00092 void appendString(std::stringstream& stream) const{stream<<v;}
00093
00094 virtual bool controlsMatch(const SeExprEdEditable& other) const
00095 {
00096 if(const SeExprEdNumberEditable* o=dynamic_cast<const SeExprEdNumberEditable*>(&other)){
00097 return min==o->min && max==o->max && v==o->v && isInt==o->isInt && name==o->name;
00098 }else return false;
00099 }
00100
00101 };
00102
00103
00104 struct SeExprEdVectorEditable:public SeExprEdEditable
00105 {
00106 SeVec3d v;
00107 double min,max;
00108 bool isColor;
00109 SeExprEdVectorEditable(const std::string& name,int startPos,int endPos,const SeVec3d& val)
00110 :SeExprEdEditable(name,startPos,endPos),v(val),min(0),max(1),isColor(true)
00111 {}
00112
00113 bool parseComment(const std::string& comment){
00114 float fmin,fmax;
00115 int numParsed=sscanf(comment.c_str(),"#%f,%f",&fmin,&fmax);
00116 if(numParsed==2){
00117 isColor=false;
00118 min=fmin;
00119 max=fmax;
00120 }
00121 return true;
00122 }
00123 std::string str() const{
00124 std::stringstream s;
00125 s<<name<<" "<<v<<" in ["<<min<<","<<max<<"]";
00126 return s.str();
00127 }
00128
00129 void appendString(std::stringstream& stream) const{printVal(stream,v);}
00130
00131 virtual bool controlsMatch(const SeExprEdEditable& other) const
00132 {
00133 if(const SeExprEdVectorEditable* o=dynamic_cast<const SeExprEdVectorEditable*>(&other)){
00134 return min==o->min && max==o->max && v==o->v && name==o->name;
00135 }else return false;
00136 }
00137
00138 };
00139
00140 struct SeExprEdStringEditable:public SeExprEdEditable
00141 {
00142 std::string v;
00143 std::string type;
00144 SeExprEdStringEditable(int startPos,int endPos,const std::string& val)
00145 :SeExprEdEditable("unknown",startPos,endPos),v(val)
00146 {}
00147
00148 bool parseComment(const std::string& comment){
00149 char namebuf[1024],typebuf[1024];
00150 int parsed=sscanf(comment.c_str(),"#%s %s",typebuf,namebuf);
00151 if(parsed==2){
00152 name=namebuf;
00153 type=typebuf;
00154 return true;
00155 }else{
00156 return false;
00157 }
00158 }
00159
00160 void appendString(std::stringstream& stream) const{
00161
00162 stream<<"\""<<v<<"\"";
00163 }
00164 std::string str() const{
00165 std::stringstream s;
00166 s<<name<<" "<<type<<" = "<<v;
00167 return s.str();
00168 }
00169
00170 virtual bool controlsMatch(const SeExprEdEditable& other) const
00171 {
00172 if(const SeExprEdStringEditable* o=dynamic_cast<const SeExprEdStringEditable*>(&other)){
00173 return v==o->v && type==o->type && name==o->name;
00174 }else return false;
00175 }
00176
00177 };
00178
00179 template<class TVAL>
00180 struct SeExprEdGenericCurveEditable:public SeExprEdEditable
00181 {
00182 typedef typename SeExpr::SeCurve<TVAL> Curve ;
00183 typedef typename SeExpr::SeCurve<TVAL>::CV CV;
00184 typedef typename Curve::InterpType InterpType;
00185
00186 std::vector<CV> cvs;
00187 SeExprEdGenericCurveEditable(const std::string& name,int startPos,int endPos)
00188 :SeExprEdEditable(name,startPos,endPos)
00189 {}
00190
00191 void add(double x,const TVAL& y,int interp){
00192 cvs.push_back(CV(x,y,InterpType(interp)));
00193 }
00194
00195 bool parseComment(const std::string& comment){UNUSED(comment); return true;}
00196 std::string str() const{
00197 std::stringstream s;
00198 s<<name<<" ccurve";
00199 return s.str();
00200 }
00201
00202 private:
00203 public:
00204 void appendString(std::stringstream& stream) const{
00205 for(size_t i=0,sz=cvs.size();i<sz;i++){
00206 const CV& cv=cvs[i];
00207 stream<<","<<cv._pos<<",";
00208 printVal(stream,cv._val);
00209 stream<<","<<cv._interp;
00210 }
00211 }
00212
00213 virtual bool controlsMatch(const SeExprEdEditable& other) const
00214 {
00215 if(const SeExprEdGenericCurveEditable* o=dynamic_cast<const SeExprEdGenericCurveEditable*>(&other)){
00216
00217
00218 UNUSED(o);
00219 return false;
00220 }else return false;
00221 }
00222
00223 };
00224 typedef SeExprEdGenericCurveEditable<SeVec3d> SeExprEdColorCurveEditable;
00225 typedef SeExprEdGenericCurveEditable<double> SeExprEdCurveEditable;
00226
00227
00228 struct SeExprEdAnimCurveEditable:public SeExprEdEditable
00229 {
00230 std::string name;
00231 int startPos,endPos;
00232 #ifdef SEEXPR_USE_ANIMLIB
00233 animlib::AnimCurve curve;
00234 #endif
00235 std::string link;
00236 std::string animationSystemCurve;
00237 std::string newText;
00238
00239 SeExprEdAnimCurveEditable(const std::string& name,int startPos,int endPos)
00240 :SeExprEdEditable(name,startPos,endPos)
00241 #ifdef SEEXPR_USE_ANIMLIB
00242 ,curve(animlib::AnimAttrID())
00243 #endif
00244 {}
00245
00246 ~SeExprEdAnimCurveEditable(){}
00247
00248 bool parseComment(const std::string& comment){
00249 animationSystemCurve=comment;
00250 return true;
00251 }
00252 std::string str() const{
00253 std::stringstream s;
00254 s<<name<<" ccurve";
00255 return s.str();
00256 }
00257 void appendString(std::stringstream& stream) const{
00258 #ifdef SEEXPR_USE_ANIMLIB
00259 if(newText.length()>0) stream<<newText;
00260 else{
00261 stream<<",\""<<animlib::AnimCurve::infinityTypeToString(curve.getPreInfinity())<<"\"";
00262 stream<<",\""<<animlib::AnimCurve::infinityTypeToString(curve.getPostInfinity())<<"\"";
00263 stream<<","<<curve.isWeighted();
00264 stream<<",\""<<link<<"\"";
00265 for(auto it=curve.getFirstKey(),itend=curve.getEndKey();it!=itend;++it){
00266 const animlib::AnimKeyframe& key=*it;
00267 stream<<","<<key.getTime()<<","<<key.getValue()<<","<<key.getInWeight()<<","<<key.getOutWeight()<<","
00268 <<key.getInAngle()<<","<<key.getOutAngle()
00269 <<",\""<<animlib::AnimKeyframe::tangentTypeToString(key.getInTangentType())
00270 <<"\",\""<<animlib::AnimKeyframe::tangentTypeToString(key.getOutTangentType())
00271 <<"\","<<key.isWeightsLocked();
00272 }
00273 }
00274 #else
00275 UNUSED(stream);
00276 #endif
00277 }
00278 virtual bool controlsMatch(const SeExprEdEditable& other) const
00279 {
00280 if(const SeExprEdAnimCurveEditable* o=dynamic_cast<const SeExprEdAnimCurveEditable*>(&other)){
00281
00282
00283 UNUSED(o);
00284 return false;
00285 }else return false;
00286 }
00287
00288 };
00289
00290 #endif
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302