6 #ifndef CNOID_BODY_PLUGIN_BODY_ITEM_H
7 #define CNOID_BODY_PLUGIN_BODY_ITEM_H
11 #include <cnoid/CollisionLinkPair>
12 #include <cnoid/LocatableItem>
13 #include <cnoid/RenderableItem>
14 #include <cnoid/stdx/optional>
15 #include "exportdecl.h"
21 class LinkKinematicsKit;
22 class InverseKinematics;
24 class PenetrationBlocker;
25 class EditableSceneBody;
34 static void registerBodyItemFileIoSet(
ItemManager* im);
44 virtual bool setName(
const std::string& name)
override;
47 void setBody(
Body* body);
49 bool isSharingShapes()
const;
50 void cloneShapes(
CloneMap& cloneMap);
52 bool makeBodyStatic();
53 bool makeBodyDynamic();
61 void setAttachmentEnabled(
bool on,
bool doNotifyUpdate =
true);
62 bool isAttachmentEnabled()
const;
63 bool attachToParentBody(
bool doNotifyUpdate =
true);
73 void setPresetPose(PresetPoseID
id);
75 Link* currentBaseLink()
const;
76 void setCurrentBaseLink(
Link* link);
78 void calcForwardKinematics(
bool calcVelocity =
false,
bool calcAcceleration =
false);
80 void copyKinematicState();
81 void pasteKinematicState();
83 void storeKinematicState(
BodyState& state);
84 bool restoreKinematicState(
const BodyState& state);
86 void storeInitialState();
87 void restoreInitialState(
bool doNotify =
true);
89 void getInitialState(
BodyState& out_state);
90 void setInitialState(
const BodyState& in_state);
92 [[deprecated(
"This function does nothing.")]]
93 void beginKinematicStateEdit();
94 [[deprecated(
"This function does nothing.")]]
95 void cancelKinematicStateEdit();
96 [[deprecated(
"Use notifyKinematicStateEdited")]]
97 void acceptKinematicStateEdit();
100 std::shared_ptr<InverseKinematics> findPresetIK(
Link* targetLink);
102 std::shared_ptr<InverseKinematics> getCurrentIK(
Link* targetLink);
103 std::shared_ptr<PinDragIK> getOrCreatePinDragIK();
104 std::shared_ptr<PinDragIK> checkPinDragIK();
105 std::shared_ptr<PenetrationBlocker> createPenetrationBlocker(
Link* link,
bool excludeSelfCollisions =
false);
107 [[deprecated(
"Create a new BodyItem and use Item::replace to update the model.")]]
109 [[deprecated(
"Create a new BodyItem and use Item::replace to update the model.")]]
110 void notifyModelUpdate();
119 void notifyKinematicStateChange(
120 bool requestFK =
false,
bool requestVelFK =
false,
bool requestAccFK =
false);
121 void notifyKinematicStateChange(
123 bool requestFK =
false,
bool requestVelFK =
false,
bool requestAccFK =
false);
124 void notifyKinematicStateChangeLater(
125 bool requestFK =
false,
bool requestVelFK =
false,
bool requestAccFK =
false);
126 void notifyKinematicStateChangeLater(
128 bool requestFK =
false,
bool requestVelFK =
false,
bool requestAccFK =
false);
137 void notifyKinematicStateUpdate(
bool doNotifyStateChange =
true);
139 bool isCollisionDetectionEnabled()
const;
140 void setCollisionDetectionEnabled(
bool on);
141 [[deprecated(
"Use setCollisionDetectionEnabled")]]
144 bool isSelfCollisionDetectionEnabled()
const;
145 void setSelfCollisionDetectionEnabled(
bool on);
146 [[deprecated(
"Use setSelfCollisionDetectionEnabled")]]
149 void clearCollisions();
151 std::vector<CollisionLinkPairPtr>&
collisions() {
return collisions_; }
152 const std::vector<CollisionLinkPairPtr>&
collisions()
const {
return collisions_; }
155 std::vector<CollisionLinkPairPtr>&
collisionsOfLink(
int linkIndex) {
return collisionsOfLink_[linkIndex]; }
156 const std::vector<CollisionLinkPairPtr>&
collisionsOfLink(
int linkIndex)
const {
return collisionsOfLink_[linkIndex]; }
162 bool isLeggedBody()
const;
163 bool doLegIkToMoveCm(
const Vector3& c,
bool onlyProjectionToFloor =
false);
166 void setZmp(
const Vector3& zmp);
167 void editZmp(
const Vector3& zmp);
169 enum PositionType { CM_PROJECTION, HOME_COP, RIGHT_HOME_COP, LEFT_HOME_COP, ZERO_MOMENT_POINT };
171 stdx::optional<Vector3> getParticularPosition(PositionType posType);
173 bool setStance(
double width);
178 bool isLocationEditable()
const;
179 void setLocationEditable(
bool on);
183 virtual SgNode* getScene()
override;
187 float transparency()
const;
188 void setTransparency(
float t);
193 virtual Item* doDuplicate()
const override;
194 virtual void doAssign(
Item* item)
override;
195 virtual void onTreePathChanged()
override;
196 virtual void onConnectedToRoot()
override;
198 virtual bool store(
Archive& archive)
override;
199 virtual bool restore(
const Archive& archive)
override;
203 bool isAttachedToParentBody_;
204 std::vector<CollisionLinkPairPtr> collisions_;
205 std::vector<bool> collisionLinkBitSet_;
206 std::vector<std::vector<CollisionLinkPairPtr>> collisionsOfLink_;
207 Signal<void()> sigCollisionsUpdated_;
209 friend class PyBodyPlugin;