1 #pragma once
2 
3 #ifndef TDOUBLEPARAM_H
4 #define TDOUBLEPARAM_H
5 
6 #include <memory>
7 
8 // TnzCore includes
9 #include "tgeometry.h"
10 #include "tfilepath.h"
11 
12 // TnzBase includes
13 #include "tparam.h"
14 #include "tparamchange.h"
15 
16 // STD includes
17 #include <set>
18 
19 #undef DVAPI
20 #undef DVVAR
21 #ifdef TPARAM_EXPORTS
22 #define DVAPI DV_EXPORT_API
23 #define DVVAR DV_EXPORT_VAR
24 #else
25 #define DVAPI DV_IMPORT_API
26 #define DVVAR DV_IMPORT_VAR
27 #endif
28 
29 //=========================================================
30 
31 //    Forward declarations
32 
33 class TDoubleParam;
34 class TDoubleKeyframe;
35 class TMeasure;
36 class TExpression;
37 class TDoubleKeyframe;
38 
39 namespace TSyntax {
40 class Grammar;
41 class CalculatorNodeVisitor;
42 }
43 
44 #ifdef _WIN32
45 template class DVAPI TPersistDeclarationT<TDoubleParam>;
46 #endif
47 
48 //=========================================================
49 
50 //**************************************************************************
51 //    TDoubleParam  declaration
52 //**************************************************************************
53 
54 class DVAPI TDoubleParam final : public TParam {
55   PERSIST_DECLARATION(TDoubleParam)
56 
57   class Imp;
58   std::unique_ptr<Imp> m_imp;
59 
60 public:
61   TDoubleParam(double v = 0.0);
62   TDoubleParam(const TDoubleParam &src);
63   ~TDoubleParam();
64 
65   TDoubleParam &operator=(const TDoubleParam &);
66 
clone()67   TParam *clone() const override { return new TDoubleParam(*this); }
68   void copy(TParam *src) override;
69 
70   std::string getMeasureName() const;
71   void setMeasureName(std::string name);
72   TMeasure *getMeasure() const;
73 
74   void setValueRange(double min, double max, double step = 1.0);
75   bool getValueRange(double &min, double &max, double &step) const;
76 
77   double getDefaultValue() const;
78   void setDefaultValue(double value);
79 
80   double getValue(double frame, bool leftmost = false) const;
81   // note: if frame is a keyframe separating two segments of different types
82   // (e.g. expression and linear) then getValue(frame,true) can be !=
83   // getValue(frame,false)
84 
85   bool setValue(double frame, double value);
86 
87   // returns the incoming speed vector for keyframe kIndex. kIndex-1 must be
88   // speedinout
89   // if kIndex is not speedinout and handle are linked then recomputes speed.y
90   // taking
91   // in account the next segment
92   TPointD getSpeedIn(int kIndex) const;
93 
94   // returns the outcoming speed vector for keyframe kIndex. kIndex must be
95   // speedinout
96   TPointD getSpeedOut(int kIndex) const;
97 
98   // TPointD getSpeed(double frame);
99 
100   // a specific grammar defines expressions as 'peg2.ns' and allows to
101   // create a link to the appropriate data source (e.g.
102   // the correct stageobject tree)
103   const TSyntax::Grammar *getGrammar() const;
104   void setGrammar(const TSyntax::Grammar *grammar);  // doesn't get ownership.
105 
106   void accept(TSyntax::CalculatorNodeVisitor &visitor);
107 
108   //! cycle controls extrapolation after the last keyframe
109   void enableCycle(bool enabled);
110   bool isCycleEnabled() const;
111 
112   int getKeyframeCount() const;
113   void getKeyframes(std::set<double> &frames) const override;
114   double keyframeIndexToFrame(int index) const override;
115 
116   const TDoubleKeyframe &getKeyframe(int index) const;
117   const TDoubleKeyframe &getKeyframeAt(double frame) const;
118 
119   //! assign k to the kIndex-th keyframe; postcondition: m_frame order is
120   //! maintained
121   void setKeyframe(int kIndex, const TDoubleKeyframe &k);
122 
123   //! call setKeyframe(it.first,it.second) for each it in ks; postcondition:
124   //! m_frame order is maintained
125   void setKeyframes(const std::map<int, TDoubleKeyframe> &ks);
126 
127   //! create a keyframe in k.m_frame (if is needed) and assign k to it
128   void setKeyframe(const TDoubleKeyframe &k);
129 
130   bool isKeyframe(double frame) const override;
131   bool hasKeyframes() const override;
132   void deleteKeyframe(double frame) override;
133   void clearKeyframes() override;
134 
135   int getClosestKeyframe(double frame) const;
136   int getNextKeyframe(double frame) const override;
137   int getPrevKeyframe(double frame) const override;
138 
139   void assignKeyframe(double frame, const TParamP &src, double srcFrame,
140                       bool changedOnly) override;
141 
isAnimatable()142   bool isAnimatable() const override { return true; }
143 
144   void addObserver(TParamObserver *observer) override;
145   void removeObserver(TParamObserver *observer) override;
146 
147   const std::set<TParamObserver *> &observers() const;
148 
149   //! no keyframes, default value not changed
150   bool isDefault() const;
151 
152   void loadData(TIStream &is) override;
153   void saveData(TOStream &os) override;
154   std::string getStreamTag() const;
155 
156   std::string getValueAlias(double frame, int precision) override;
157 };
158 
159 DVAPI void splitSpeedInOutSegment(TDoubleKeyframe &k, TDoubleKeyframe &k0,
160                                   TDoubleKeyframe &k1);
161 
162 //---------------------------------------------------------
163 
164 DEFINE_PARAM_SMARTPOINTER(TDoubleParam, double)
165 
166 #endif  // TDOUBLEPARAM_H
167