Choreonoid  1.8
MprProgramItemBase.h
Go to the documentation of this file.
1 #ifndef CNOID_MANIPULATOR_PLUGIN_MPR_PROGRAM_ITEM_BASE_H
2 #define CNOID_MANIPULATOR_PLUGIN_MPR_PROGRAM_ITEM_BASE_H
3 
4 #include "MprProgram.h"
5 #include <cnoid/Item>
6 #include <typeinfo>
7 #include "exportdecl.h"
8 
9 namespace cnoid {
10 
11 class Archive;
12 class BodyItem;
13 class LinkKinematicsKit;
14 class MprPositionStatement;
15 
16 class CNOID_EXPORT MprProgramItemBase : public Item
17 {
18 public:
19  static void initializeClass(ExtensionManager* ext);
20 
21  virtual ~MprProgramItemBase();
22 
23  virtual bool setName(const std::string& name) override;
24 
25  BodyItem* targetBodyItem();
26 
27  LinkKinematicsKit* kinematicsKit();
28 
29  MprProgram* program();
30  const MprProgram* program() const;
31 
32  bool isStartupProgram() const;
33  bool setAsStartupProgram(bool on, bool doNotify = true);
34 
35  bool moveTo(MprPositionStatement* statement);
36  bool moveTo(MprPosition* position);
37  bool superimposePosition(MprPositionStatement* statement);
38  bool superimposePosition(MprPosition* position);
39  void clearSuperimposition();
40  bool touchupPosition(MprPositionStatement* statement);
41  bool touchupPosition(MprPosition* position);
42 
43  template<class StatementType>
45  std::function<bool(StatementType*, MprProgramItemBase*)> resolve){
46  registerReferenceResolver_(
47  typeid(StatementType),
48  [resolve](MprStatement* statement, MprProgramItemBase* item){
49  return resolve(static_cast<StatementType*>(statement), item); });
50  }
51  bool resolveStatementReferences(MprStatement* statement);
52  bool resolveAllReferences();
53 
54  virtual void doPutProperties(PutPropertyFunction& putProperty) override;
55  virtual bool store(Archive& archive) override;
56  virtual bool restore(const Archive& archive) override;
57 
58 protected:
61  virtual Item* doDuplicate() const override;
62  virtual void onTreePathChanged() override;
63  virtual void onConnectedToRoot() override;
64 
65 private:
66  static void registerReferenceResolver_(
67  const std::type_info& type,
68  const std::function<bool(MprStatement*, MprProgramItemBase*)>& resolve);
69 
70  class Impl;
71  Impl* impl;
72 };
73 
75 
76 }
77 
78 #endif
cnoid::MprProgramItemBasePtr
ref_ptr< MprProgramItemBase > MprProgramItemBasePtr
Definition: MprProgramItemBase.h:74
cnoid::ExtensionManager
Definition: ExtensionManager.h:23
cnoid::MprProgramItemBase::registerReferenceResolver
static void registerReferenceResolver(std::function< bool(StatementType *, MprProgramItemBase *)> resolve)
Definition: MprProgramItemBase.h:44
cnoid::PutPropertyFunction
Definition: PutPropertyFunction.h:51
cnoid::MprProgramItemBase
Definition: MprProgramItemBase.h:16
cnoid::Archive
Definition: Archive.h:22
cnoid::ref_ptr< MprProgramItemBase >
cnoid::BodyItem
Definition: BodyItem.h:28
cnoid::MprPositionStatement
Definition: MprPositionStatement.h:13
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::Item
Definition: Item.h:29
cnoid::LinkKinematicsKit
Definition: LinkKinematicsKit.h:23
cnoid::MprStatement
Definition: MprStatement.h:16
cnoid::MprPosition
Definition: MprPosition.h:23
cnoid::MprProgram
Definition: MprProgram.h:21
MprProgram.h