Choreonoid  1.8
TimeSyncItemEngine.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_BASE_TIME_SYNC_ITEM_ENGINE_H
7 #define CNOID_BASE_TIME_SYNC_ITEM_ENGINE_H
8 
9 #include "Item.h"
10 #include <functional>
11 #include <typeinfo>
12 #include <vector>
13 #include "exportdecl.h"
14 
15 namespace cnoid {
16 
17 class CNOID_EXPORT TimeSyncItemEngine : public Referenced
18 {
19 public:
20  TimeSyncItemEngine(Item* item);
21  virtual ~TimeSyncItemEngine();
22 
23  TimeSyncItemEngine(const TimeSyncItemEngine& org) = delete;
24  TimeSyncItemEngine& operator=(const TimeSyncItemEngine& rhs) = delete;
25 
26  Item* item(){ return item_; }
27 
28  virtual bool onPlaybackInitialized(double time);
29  virtual void onPlaybackStarted(double time);
30  virtual bool onTimeChanged(double time) = 0;
31  virtual void onPlaybackStopped(double time, bool isStoppedManually);
32  virtual bool isTimeSyncAlwaysMaintained() const;
33 
34  void startOngoingTimeUpdate();
35  void startOngoingTimeUpdate(double time);
36  bool isUpdatingOngoingTime() const { return isUpdatingOngoingTime_; }
37  bool isOngoingTimeUpdateAccepted() const { return ongoingTimeId >= 0; }
38  void updateOngoingTime(double time);
39  void stopOngoingTimeUpdate();
40  void refresh();
41 
42 private:
43  ItemPtr item_;
44  int ongoingTimeId;
45  double ongoingTime;
46  bool isActive_;
47  bool isTimeSyncForcedToBeMaintained_;
48  bool isUpdatingOngoingTime_;
49 
51 
52  void activate();
53  void deactivate();
54  void setupOngoingTimeUpdate();
55  bool isTimeSyncForcedToBeMaintained() const { return isTimeSyncForcedToBeMaintained_; }
56 };
57 
59 
60 class ExtensionManager;
61 class Item;
62 
63 class CNOID_EXPORT TimeSyncItemEngineManager
64 {
65 public:
66  static void initializeClass(ExtensionManager* ext);
67  static TimeSyncItemEngineManager* instance();
68 
70 
71  template<class ItemType, class EngineType = TimeSyncItemEngine>
72  void registerFactory(std::function<TimeSyncItemEngine*(ItemType* item, EngineType* prevEngine)> factory){
73  registerFactory_(
74  typeid(ItemType),
75  [factory](Item* item, TimeSyncItemEngine* prevEngine){
76  return factory(static_cast<ItemType*>(item), dynamic_cast<EngineType*>(prevEngine));
77  });
78  }
79 
84  int createEngines(Item* item, std::vector<TimeSyncItemEnginePtr>& io_engines);
85 
86  class Impl;
87 
88 private:
90 
91  void registerFactory_(
92  const std::type_info& type,
93  const std::function<TimeSyncItemEngine*(Item* item, TimeSyncItemEngine* prevEngine)>& factory);
94 
95  Impl* impl;
96 };
97 
98 }
99 
100 #endif
cnoid::TimeSyncItemEngineManager
Definition: TimeSyncItemEngine.h:63
cnoid::TimeSyncItemEngine::item
Item * item()
Definition: TimeSyncItemEngine.h:26
Item.h
cnoid::ExtensionManager
Definition: ExtensionManager.h:23
cnoid::TimeSyncItemEngineManager::registerFactory
void registerFactory(std::function< TimeSyncItemEngine *(ItemType *item, EngineType *prevEngine)> factory)
Definition: TimeSyncItemEngine.h:72
cnoid::TimeSyncItemEngine
Definition: TimeSyncItemEngine.h:17
cnoid::ref_ptr< Item >
cnoid::TimeSyncItemEnginePtr
ref_ptr< TimeSyncItemEngine > TimeSyncItemEnginePtr
Definition: TimeSyncItemEngine.h:58
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::Item
Definition: Item.h:29
cnoid::TimeSyncItemEngine::isOngoingTimeUpdateAccepted
bool isOngoingTimeUpdateAccepted() const
Definition: TimeSyncItemEngine.h:37
cnoid::Referenced
Definition: Referenced.h:54
cnoid::TimeSyncItemEngine::isUpdatingOngoingTime
bool isUpdatingOngoingTime() const
Definition: TimeSyncItemEngine.h:36