SeExpr
Editable.h
Go to the documentation of this file.
1 /*
2 * Copyright Disney Enterprises, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License
6 * and the following modification to it: Section 6 Trademarks.
7 * deleted and replaced with:
8 *
9 * 6. Trademarks. This License does not grant permission to use the
10 * trade names, trademarks, service marks, or product names of the
11 * Licensor and its affiliates, except as required for reproducing
12 * the content of the NOTICE file.
13 *
14 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * @file Editable.h
18 * @author Andrew Selle
19 */
20 #ifndef __Editable__
21 #define __Editable__
22 #include <sstream>
23 #include <SeExpr2/Vec.h>
24 #include <SeExpr2/Curve.h>
25 #include <cstdio>
26 #include <cstring>
27 #ifdef SEEXPR_USE_ANIMLIB
28 #include <animlib/AnimCurve.h>
29 #include <animlib/AnimKeyframe.h>
30 #endif
31 #include <ExprDeepWater.h>
32 
33 inline void printVal(std::stringstream& stream,double v){stream<<v;}
34 inline void printVal(std::stringstream& stream,const SeExpr2::Vec3d& v){stream<<"["<<v[0]<<","<<v[1]<<","<<v[2]<<"]";}
35 
36 #define UNUSED(x) (void)(x)
37 
38 struct Editable
39 {
40  std::string name;
42 
43 
44  Editable(const std::string& name,int startPos,int endPos)
45  :name(name),startPos(startPos),endPos(endPos)
46  {
47 
48  }
49 
50  void updatePositions(const Editable& other)
51  {
52  startPos=other.startPos;endPos=other.endPos;
53  }
54 
55  virtual ~Editable(){} // must have this to ensure destruction
56 
58  virtual bool parseComment(const std::string& comment)=0;
59  virtual std::string str() const{return std::string("<unknown>");}
60  virtual void appendString(std::stringstream& stream) const=0;
61  virtual bool controlsMatch(const Editable&) const=0;
62 
63 };
64 
65 
66 struct NumberEditable:public Editable
67 {
68  double v;
69  double min,max;
70  bool isInt;
71  NumberEditable(const std::string& name,int startPos,int endPos,double val)
72  :Editable(name,startPos,endPos),v(val),min(0),max(1),isInt(false)
73  {}
74 
75  bool parseComment(const std::string& comment){
76  if (comment.find('.') != std::string::npos || comment.find('e') != std::string::npos)
77  {
78  float fmin,fmax;
79  if (sscanf(comment.c_str(),"#%f,%f",&fmin,&fmax)==2)
80  {
81  min=fmin;
82  max=fmax;
83  isInt=false;
84  return true;
85  }
86  }
87  int imin,imax;
88  if (sscanf(comment.c_str(),"#%d,%d",&imin,&imax)==2)
89  {
90  min=imin;
91  max=imax;
92  isInt=true;
93  return true;
94  }
95  return true;
96  }
97  std::string str() const{
98  std::stringstream s;
99  s<<name<<" "<<v<<" in ["<<min<<","<<max<<"] subset "<<(isInt?"Integers":"Reals");
100  return s.str();
101  }
102  void appendString(std::stringstream& stream) const{stream<<v;}
103 
104  virtual bool controlsMatch(const Editable& other) const
105  {
106  if(const NumberEditable* o=dynamic_cast<const NumberEditable*>(&other)){
107  return min==o->min && max==o->max && v==o->v && isInt==o->isInt && name==o->name;
108  }else return false;
109  }
110 
111 };
112 
113 
115 {
117  double min,max;
118  bool isColor;
119  VectorEditable(const std::string& name,int startPos,int endPos,const SeExpr2::Vec3d& val)
120  :Editable(name,startPos,endPos),v(val),min(0),max(1),isColor(true)
121  {}
122 
123  bool parseComment(const std::string& comment){
124  float fmin,fmax;
125  int numParsed=sscanf(comment.c_str(),"#%f,%f",&fmin,&fmax);
126  if(numParsed==2){
127  isColor=false;
128  min=fmin;
129  max=fmax;
130  }
131  return true;
132  }
133  std::string str() const{
134  std::stringstream s;
135  s<<name<<" "<<v<<" in ["<<min<<","<<max<<"]";
136  return s.str();
137  }
138 
139  void appendString(std::stringstream& stream) const{printVal(stream,v);}
140 
141  virtual bool controlsMatch(const Editable& other) const
142  {
143  if(const VectorEditable* o=dynamic_cast<const VectorEditable*>(&other)){
144  return min==o->min && max==o->max && v==o->v && name==o->name;
145  }else return false;
146  }
147 
148 };
149 
151 {
152  std::string v;
153  std::string type;
154  StringEditable(int startPos,int endPos,const std::string& val)
155  :Editable("unknown",startPos,endPos),v(val)
156  {}
157 
158  bool parseComment(const std::string& comment){
159  char namebuf[1024],typebuf[1024];
160  int parsed=sscanf(comment.c_str(),"#%s %s",typebuf,namebuf);
161  if(parsed==2){
162  name=namebuf;
163  type=typebuf;
164  return true;
165  }else{
166  return false;
167  }
168  }
169 
170  void appendString(std::stringstream& stream) const{
171  // TODO: escape strs
172  stream<<"\""<<v<<"\"";
173  }
174  std::string str() const{
175  std::stringstream s;
176  s<<name<<" "<<type<<" = "<<v;
177  return s.str();
178  }
179 
180  virtual bool controlsMatch(const Editable& other) const
181  {
182  if(const StringEditable* o=dynamic_cast<const StringEditable*>(&other)){
183  return v==o->v && type==o->type && name==o->name;
184  }else return false;
185  }
186 
187 };
188 
189 template<class TVAL>
191 {
192  typedef typename SeExpr2::Curve<TVAL> Curve ;
193  typedef typename SeExpr2::Curve<TVAL>::CV CV;
194  typedef typename Curve::InterpType InterpType;
195 
196  std::vector<CV> cvs;
197  GenericCurveEditable(const std::string& name,int startPos,int endPos)
198  :Editable(name,startPos,endPos)
199  {}
200 
201  void add(double x,const TVAL& y,int interp){
202  cvs.push_back(CV(x,y,InterpType(interp)));
203  }
204 
205  bool parseComment(const std::string& /*comment*/){return true;}
206  std::string str() const{
207  std::stringstream s;
208  s<<name<<" ccurve";
209  return s.str();
210  }
211 
212 private:
213 public:
214  void appendString(std::stringstream& stream) const{
215  for(size_t i=0,sz=cvs.size();i<sz;i++){
216  const CV& cv=cvs[i];
217  stream<<","<<cv._pos<<",";
218  printVal(stream,cv._val);
219  stream<<","<<cv._interp;
220  }
221  }
222 
223  virtual bool controlsMatch(const Editable& other) const
224  {
225  if(const GenericCurveEditable* o=dynamic_cast<const GenericCurveEditable*>(&other)){
226  // TODO: fix this
227 // return cvs==o->cvs && name==o->name;
228  UNUSED(o);
229  return false;
230  }else return false;
231  }
232 
233 };
236 
237 
239 {
240  std::string name;
242 #ifdef SEEXPR_USE_ANIMLIB
243  animlib::AnimCurve curve;
244 #endif
245  std::string link;
246  std::string animationSystemCurve;
247  std::string newText;
248 
249  AnimCurveEditable(const std::string& name,int startPos,int endPos)
250  :Editable(name,startPos,endPos)
251 #ifdef SEEXPR_USE_ANIMLIB
252  ,curve(animlib::AnimAttrID())
253 #endif
254  {}
255 
256  ~AnimCurveEditable(){} // must have this to ensure destruction
257 
258  bool parseComment(const std::string& comment){
259  animationSystemCurve=comment;
260  return true;
261  }
262  std::string str() const{
263  std::stringstream s;
264  s<<name<<" ccurve";
265  return s.str();
266  }
267  void appendString(std::stringstream& stream) const{
268 #ifdef SEEXPR_USE_ANIMLIB
269  if(newText.length()>0) stream<<newText;
270  else{
271  stream<<",\""<<animlib::AnimCurve::infinityTypeToString(curve.getPreInfinity())<<"\"";
272  stream<<",\""<<animlib::AnimCurve::infinityTypeToString(curve.getPostInfinity())<<"\"";
273  stream<<","<<curve.isWeighted();
274  stream<<",\""<<link<<"\"";
275  for(auto it=curve.getFirstKey(),itend=curve.getEndKey();it!=itend;++it){
276  const animlib::AnimKeyframe& key=*it;
277  stream<<","<<key.getTime()<<","<<key.getValue()<<","<<key.getInWeight()<<","<<key.getOutWeight()<<","
278  <<key.getInAngle()<<","<<key.getOutAngle()
279  <<",\""<<animlib::AnimKeyframe::tangentTypeToString(key.getInTangentType())
280  <<"\",\""<<animlib::AnimKeyframe::tangentTypeToString(key.getOutTangentType())
281  <<"\","<<key.isWeightsLocked();
282  }
283  }
284 #else
285  UNUSED(stream);
286 #endif
287  }
288  virtual bool controlsMatch(const Editable& other) const
289  {
290  if(const AnimCurveEditable* o=dynamic_cast<const AnimCurveEditable*>(&other)){
291  // TODO: fix this
292 // return cvs==o->cvs && name==o->name;
293  UNUSED(o);
294  return false;
295  }else return false;
296  }
297 
298 };
299 
300 
302 {
303  std::vector<SeExpr2::Vec3d> colors;
304  std::string labelType;
305 
306  ColorSwatchEditable(const std::string& name,
307  int startPos,int endPos)
308  :Editable(name,startPos,endPos)
309  {}
310 
311 
312  bool parseComment(const std::string& comment){
313  char labelbuf[1024];
314  int parsed=sscanf(comment.c_str(),"#%s",labelbuf);
315  if(parsed==1){
316  labelType=labelbuf;
317  return true;
318  }
319  return true;
320  }
321 
322  std::string str() const{
323  std::stringstream s;
324  s<<name<<" swatch";
325  return s.str();
326  }
327 
328  void appendString(std::stringstream& stream) const{
329  for(size_t i=0,sz=colors.size();i<sz;i++){
330  const SeExpr2::Vec3d& color=colors[i];
331  stream<<",";
332  printVal(stream,color);
333  }
334  }
335 
336  virtual bool controlsMatch(const Editable& other) const
337  {
338  if(const ColorSwatchEditable* o=dynamic_cast<const ColorSwatchEditable*>(&other)){
339  // TODO: determine when controls match
340  UNUSED(o);
341  return false;
342  }else return false;
343  }
344 
345  void add(const SeExpr2::Vec3d& value){
346  colors.push_back(value);
347  }
348 
349  void change(int index, const SeExpr2::Vec3d& value){
350  colors[index] = value;
351  }
352 
353  void remove(int index){
354  colors.erase(colors.begin()+index);
355  }
356 
357  void print(){
358  std::cerr << "\nColorSwatchEditable:\n";
359  for(unsigned int i=0; i<colors.size(); i++){
360  std::cerr << colors[i][0] << ", " << colors[i][1] << ", "
361  << colors[i][2] << std::endl;
362  }
363  }
364 
365 };
366 
368 {
370 
371  DeepWaterEditable(const std::string& name,int startPos,int endPos)
372  :Editable(name,startPos,endPos)
373  {}
374 
375  void setParams(const SeDeepWaterParams& paramsIn){
376  params = paramsIn;
377  }
378 
379  bool parseComment(const std::string& /*comment*/){return true;}
380 
381  std::string str() const{
382  std::stringstream s;
383  s<<name<<" deepWater";
384  return s.str();
385  }
386 
387  void appendString(std::stringstream& stream) const{
388  stream<<","<<params.resolution;
389  stream<<","<<params.tileSize;
390  stream<<","<<params.lengthCutoff;
391  stream<<","<<params.amplitude;
392  stream<<","<<params.windAngle;
393  stream<<","<<params.windSpeed;
394  stream<<","<<params.directionalFactorExponent;
395  stream<<","<<params.directionalReflectionDamping<<",";
396  printVal(stream,params.flowDirection);
397  stream<<","<<params.sharpen;
398  stream<<","<<params.time;
399  stream<<","<<params.filterWidth;
400  }
401 
402  virtual bool controlsMatch(const Editable& other) const
403  {
404  if(const DeepWaterEditable* o=dynamic_cast<const DeepWaterEditable*>(&other)){
405  // TODO: determine when controls match
406  UNUSED(o);
407  return false;
408  }else return false;
409  }
410 };
411 
412 #endif
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:180
SeExpr2::CurveFuncX curve
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:336
virtual void appendString(std::stringstream &stream) const =0
std::string str() const
Definition: Editable.h:174
void change(int index, const SeExpr2::Vec3d &value)
Definition: Editable.h:349
virtual ~Editable()
Definition: Editable.h:55
std::string newText
Definition: Editable.h:247
Interpolation curve class for double-&gt;double and double-&gt;Vec3D.
Definition: Curve.h:38
NumberEditable(const std::string &name, int startPos, int endPos, double val)
Definition: Editable.h:71
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:312
void appendString(std::stringstream &stream) const
Definition: Editable.h:387
SeDeepWaterParams params
Definition: Editable.h:369
std::string str() const
Definition: Editable.h:206
virtual bool controlsMatch(const Editable &) const =0
int endPos
Definition: Editable.h:41
void add(double x, const TVAL &y, int interp)
Definition: Editable.h:201
void appendString(std::stringstream &stream) const
Definition: Editable.h:214
VectorEditable(const std::string &name, int startPos, int endPos, const SeExpr2::Vec3d &val)
Definition: Editable.h:119
std::string str() const
Definition: Editable.h:262
InterpType _interp
Definition: Curve.h:55
GenericCurveEditable< double > CurveEditable
Definition: Editable.h:235
void add(const SeExpr2::Vec3d &value)
Definition: Editable.h:345
void appendString(std::stringstream &stream) const
Definition: Editable.h:139
std::vector< CV > cvs
Definition: Editable.h:196
std::string v
Definition: Editable.h:152
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:141
std::string str() const
Definition: Editable.h:133
void appendString(std::stringstream &stream) const
Definition: Editable.h:170
StringEditable(int startPos, int endPos, const std::string &val)
Definition: Editable.h:154
int startPos
Definition: Editable.h:41
DeepWaterEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:371
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:223
double max
Definition: Editable.h:117
For any rgb or hsl value(except for negative s values)
double _pos
Definition: Curve.h:53
void appendString(std::stringstream &stream) const
Definition: Editable.h:102
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:402
std::string link
Definition: Editable.h:245
void printVal(std::stringstream &stream, double v)
Definition: Editable.h:33
std::string type
Definition: Editable.h:153
The result is computed int int< br >< divstyle="margin-left:40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed).&nbsp
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:288
std::string animationSystemCurve
Definition: Editable.h:246
SeExpr2::Curve< TVAL >::CV CV
Definition: Editable.h:193
double min
Definition: Editable.h:117
SeExpr2::Vec3d flowDirection
Definition: ExprDeepWater.h:46
double v
Definition: Editable.h:68
#define UNUSED(x)
Definition: Editable.h:36
double directionalReflectionDamping
Definition: ExprDeepWater.h:45
std::string name
Definition: Editable.h:240
double max
Definition: Editable.h:69
std::string name
Definition: Editable.h:40
double directionalFactorExponent
Definition: ExprDeepWater.h:44
SeExpr2::Curve< TVAL > Curve
Definition: Editable.h:192
</pre >< h3 > A simple variable reference</h3 > This is not a very interesting subclass of expression until we add some additional variables Variables on some applications may be very dynamic In this we only need x
Definition: tutorial.txt:108
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:158
Curve::InterpType InterpType
Definition: Editable.h:194
virtual bool parseComment(const std::string &comment)=0
parses a comment. if false is returned then delete the control from the editable
double min
Definition: Editable.h:69
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:75
GenericCurveEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:197
virtual std::string str() const
Definition: Editable.h:59
SeExpr2::Vec3d v
Definition: Editable.h:116
std::string str() const
Definition: Editable.h:97
generated ExprParser cpp dev null OUTPUT ExprParser cpp DEPENDS y tab c ExprParser tab h endif((BISON_EXE STREQUAL"BISON_EXE-NOTFOUND") OR(FLEX_EXE STREQUAL"FLEX_EXE-NOTFOUND") OR(SED_EXE STREQUAL"SED_EXE-NOTFOUND")) INSTALL(DIRECTORY $
Definition: CMakeLists.txt:83
virtual bool controlsMatch(const Editable &other) const
Definition: Editable.h:104
void appendString(std::stringstream &stream) const
Definition: Editable.h:328
AnimCurveEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:249
std::string str() const
Definition: Editable.h:322
InterpType
Supported interpolation types.
Definition: Curve.h:43
void appendString(std::stringstream &stream) const
Definition: Editable.h:267
std::string labelType
Definition: Editable.h:304
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:123
you may not use this file except in compliance with the License and the following modification to it
Definition: license.txt:10
bool parseComment(const std::string &comment)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:258
std::vector< SeExpr2::Vec3d > colors
Definition: Editable.h:303
std::string str() const
Definition: Editable.h:381
bool parseComment(const std::string &)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:205
GenericCurveEditable< SeExpr2::Vec3d > ColorCurveEditable
Definition: Editable.h:234
void updatePositions(const Editable &other)
Definition: Editable.h:50
This is the same as the prman cellnoise function< br ></div >< br > float< b > float y< br > float< b > float y
Definition: userdoc.txt:218
ColorSwatchEditable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:306
Editable(const std::string &name, int startPos, int endPos)
Definition: Editable.h:44
void setParams(const SeDeepWaterParams &paramsIn)
Definition: Editable.h:375
bool parseComment(const std::string &)
parses a comment. if false is returned then delete the control from the editable
Definition: Editable.h:379