6 #ifndef CNOID_BODY_PLUGIN_SIMULATOR_ITEM_H
7 #define CNOID_BODY_PLUGIN_SIMULATOR_ITEM_H
11 #include <cnoid/EigenTypes>
14 #include "exportdecl.h"
21 class CollisionDetector;
26 class SimulatedMotionEngineManager;
38 int numControllers()
const;
44 void cloneShapesOnce();
48 const std::string& recordItemPrefix()
const;
49 virtual void initializeRecordBuffers();
50 virtual void initializeRecordItems();
55 bool isActive()
const;
56 void setActive(
bool on);
62 void notifyUnrecordedDeviceStateChange(
Device* device);
67 virtual void bufferRecords();
68 virtual void flushRecords();
91 virtual double worldTimeStep();
92 void setTimeStep(
double step);
94 bool startSimulation(
bool doReset =
true);
95 void stopSimulation(
bool isForced =
false);
96 void pauseSimulation();
97 void restartSimulation();
98 bool isRunning()
const;
99 bool isPausing()
const;
100 bool isActive()
const;
103 int currentFrame()
const;
106 double currentTime()
const;
109 int simulationFrame()
const;
112 double simulationTime()
const;
117 SignalProxy<void(
bool isForced)> sigSimulationFinished();
126 REC_FULL = FullRecording,
127 REC_TAIL = TailRecording,
128 REC_NONE = NoRecording,
129 N_RECORDING_MODES = NumRecordingModes
132 void setRecordingMode(
int selection);
133 int recordingMode()
const;
145 TR_UNLIMITED = UnlimitedTime,
146 TR_ACTIVE_CONTROL = ActiveControlTime,
147 TR_SPECIFIED = SpecifiedTime,
148 TR_TIMEBAR = TimeBarTime,
149 N_TIME_RANGE_MODES = NumTimeRangeModes
152 void setTimeRangeMode(
int selection);
154 void setTimeLength(
double length);
156 [[deprecated(
"Use setTimeLength")]]
158 setTimeLength(length);
161 void setActiveControlTimeRangeMode(
bool on);
162 bool isActiveControlTimeRangeMode()
const;
164 void setRealtimeSyncMode(
bool on);
166 void setDeviceStateOutputEnabled(
bool on);
168 bool isRecordingEnabled()
const;
169 bool isDeviceStateOutputEnabled()
const;
171 bool isAllLinkPositionOutputMode();
172 virtual void setAllLinkPositionOutputMode(
bool on);
174 const std::string& controllerOptionString()
const;
179 const std::vector<SimulationBody*>& simulationBodies();
187 int addPreDynamicsFunction(std::function<
void()> func);
188 int addMidDynamicsFunction(std::function<
void()> func);
189 int addPostDynamicsFunction(std::function<
void()> func);
191 void removePreDynamicsFunction(
int id);
192 void removeMidDynamicsFunction(
int id);
193 void removePostDynamicsFunction(
int id);
202 SignalProxy<void(
const std::vector<SimulationBodyPtr>& simulationBodies)>
203 sigSimulationBodyListUpdated();
208 virtual Vector3 getGravity()
const;
215 virtual void clearExternalForces();
220 virtual void setVirtualElasticString(
222 virtual void clearVirtualElasticStrings();
225 virtual bool isForcedPositionActiveFor(
BodyItem* bodyItem)
const;
226 virtual void clearForcedPositions();
235 virtual void onTreePathChanged()
override;
236 virtual void onDisconnectedFromRoot()
override;
238 virtual void clearSimulation();
259 virtual bool initializeSimulation(
const std::vector<SimulationBody*>& simBodies) = 0;
266 virtual bool completeInitializationOfSimulation();
268 virtual void initializeSimulationThread();
270 virtual void finalizeSimulationThread();
276 virtual bool stepSimulation(
const std::vector<SimulationBody*>& activeSimBodies) = 0;
281 virtual void finalizeSimulation();
283 virtual std::shared_ptr<CollisionLinkPairList> getCollisions();
286 virtual bool store(
Archive& archive)
override;
287 virtual bool restore(
const Archive& archive)
override;
293 friend class SimulatedMotionEngineManager;