1 #pragma once
2 
3 #ifndef T_STAGE_OBJECT_SPLINE_INCLUDED
4 #define T_STAGE_OBJECT_SPLINE_INCLUDED
5 
6 #include "tsmartpointer.h"
7 #include "tgeometry.h"
8 #include "tpersist.h"
9 
10 #undef DVAPI
11 #undef DVVAR
12 #ifdef TOONZLIB_EXPORTS
13 #define DVAPI DV_EXPORT_API
14 #define DVVAR DV_EXPORT_VAR
15 #else
16 #define DVAPI DV_IMPORT_API
17 #define DVVAR DV_IMPORT_VAR
18 #endif
19 
20 //=============================================================================
21 // forward declarations
22 class TStroke;
23 class TStageObject;
24 class TDoubleParam;
25 
26 //=============================================================================
27 //! The TStageObjectSpline class define stage object motion path.
28 /*!Inherits \b TSmartObject and \b TPersist.
29 \n The motion path is defined by spline build as \b TStroke getStroke(),
30    and node position getDagNodePos(); spline can be set using setStroke()
31    while node position can be set using setDagNodePos().
32 \n It's possible to clone spline using clone().
33 */
34 //=============================================================================
35 
36 class DVAPI TStageObjectSpline final : public TSmartObject, public TPersist {
37   PERSIST_DECLARATION(TStageObjectSpline)
38   TStroke *m_stroke;
39   DECLARE_CLASS_CODE
40   TPointD m_dagNodePos;
41 
42   int m_id;
43   std::string m_idBase;
44   std::string m_name;
45   bool m_isOpened;
46   std::vector<TDoubleParam *> m_posPathParams;
47 
48 public:
49   TStageObjectSpline();
50   ~TStageObjectSpline();
51 
52   TStageObjectSpline *clone() const;
53 
54   /*!
55 Return spline stroke.
56 \sa setStroke()
57 */
58   const TStroke *getStroke() const;
59   /*!
60 Set spline stroke to \b stroke.
61 \sa getStroke()
62 */
63   void setStroke(TStroke *stroke);  //! keeps ownership
64 
getDagNodePos()65   TPointD getDagNodePos() const { return m_dagNodePos; }
setDagNodePos(const TPointD & pos)66   void setDagNodePos(const TPointD &pos) { m_dagNodePos = pos; }
67 
68   int getId() const;
69   void setId(int id);
70   std::string getName() const;
setName(const std::string & name)71   void setName(const std::string &name) { m_name = name; }
72 
isOpened()73   bool isOpened() const { return m_isOpened; }
setIsOpened(bool value)74   void setIsOpened(bool value) { m_isOpened = value; }
75 
76   void loadData(TIStream &is) override;
77   void saveData(TOStream &os) override;
78 
79   std::string getIconId();
80 
81   //! add the PosPath param if you want to update keyframes values
82   //! when the stroke changes. addParam() calls param->addRef()
83   void addParam(TDoubleParam *param);
84   void removeParam(TDoubleParam *param);
85 
86 private:
87   // not implemented: can't copy a TStageObjectSpline
88   TStageObjectSpline &operator=(const TStageObjectSpline &);
89   TStageObjectSpline(const TStageObjectSpline &);
90 
91   void updatePosPathKeyframes(TStroke *oldSpline, TStroke *newSpline);
92 };
93 
94 #ifdef _WIN32
95 template class TSmartPointerT<TStageObjectSpline>;
96 #endif
97 
98 typedef TSmartPointerT<TStageObjectSpline> TStageObjectSplineP;
99 
100 #endif
101