Choreonoid  1.8
StdBodyWriter.h
Go to the documentation of this file.
1 #ifndef CNOID_BODY_STD_BODY_WRITER_H
2 #define CNOID_BODY_STD_BODY_WRITER_H
3 
4 #include <cnoid/StdSceneWriter>
5 #include <functional>
6 #include <typeinfo>
7 #include "exportdecl.h"
8 
9 namespace cnoid {
10 
11 class Body;
12 class Device;
13 class Mapping;
14 class StdSceneWriter;
15 
16 class CNOID_EXPORT StdBodyWriter
17 {
18 public:
19  StdBodyWriter();
20 
21  void setMessageSink(std::ostream& os);
22 
25  LinkToOriginalModelFiles = StdSceneWriter::LinkToOriginalModelFiles,
26  ReplaceWithStdSceneFiles = StdSceneWriter::ReplaceWithStdSceneFiles,
27  ReplaceWithObjModelFiles = StdSceneWriter::ReplaceWithObjModelFiles
28  };
29  void setExtModelFileMode(int mode);
30  int extModelFileMode() const;
31 
32  bool writeBody(Body* body, const std::string& filename);
33 
34  StdSceneWriter* sceneWriter();
35  const StdSceneWriter* sceneWriter() const;
36 
37  template<class DeviceType>
38  static void registerDeviceWriter(
39  const char* typeName,
40  std::function<bool(StdBodyWriter* writer, Mapping* info, const DeviceType* device)> writeFunction)
41  {
42  registerDeviceWriter_(
43  typeid(DeviceType), typeName,
44  [writeFunction](StdBodyWriter* writer, Mapping* info, const Device* device){
45  return writeFunction(writer, info, static_cast<const DeviceType*>(device));
46  });
47  }
48 
49  template<class DeviceType>
51  {
53  const char* typeName,
54  std::function<bool(StdBodyWriter* writer, Mapping* info, const DeviceType* device)> writeFunction)
55  {
56  registerDeviceWriter<DeviceType>(typeName, writeFunction);
57  }
58  };
59 
60  template<class DeviceType>
61  bool writeDeviceAs(Mapping* info, const DeviceType* device)
62  {
63  return writeDeviceAs_(typeid(DeviceType), info, device);
64  }
65 
66 private:
67  class Impl;
68  Impl* impl;
69 
70  static void registerDeviceWriter_(
71  const std::type_info& type, const char* typeName,
72  std::function<bool(StdBodyWriter* writer, Mapping* info, const Device* device)> writeFunction);
73 
74  bool writeDeviceAs_(const std::type_info& type, Mapping* info, const Device* device);
75 };
76 
77 }
78 
79 #endif
cnoid::StdBodyWriter::writeDeviceAs
bool writeDeviceAs(Mapping *info, const DeviceType *device)
Definition: StdBodyWriter.h:61
cnoid::Mapping
Definition: ValueTree.h:253
cnoid::StdBodyWriter::DeviceWriterRegistration
Definition: StdBodyWriter.h:50
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::StdBodyWriter
Definition: StdBodyWriter.h:16
cnoid::StdBodyWriter::ExtModelFileMode
ExtModelFileMode
Definition: StdBodyWriter.h:23
cnoid::StdBodyWriter::registerDeviceWriter
static void registerDeviceWriter(const char *typeName, std::function< bool(StdBodyWriter *writer, Mapping *info, const DeviceType *device)> writeFunction)
Definition: StdBodyWriter.h:38
cnoid::StdSceneWriter::ReplaceWithStdSceneFiles
@ ReplaceWithStdSceneFiles
Definition: StdSceneWriter.h:37
cnoid::StdSceneWriter
Definition: StdSceneWriter.h:15
cnoid::StdSceneWriter::LinkToOriginalModelFiles
@ LinkToOriginalModelFiles
Definition: StdSceneWriter.h:36
cnoid::Body
Definition: Body.h:28
cnoid::Device
Definition: Device.h:53
cnoid::StdSceneWriter::EmbedModels
@ EmbedModels
Definition: StdSceneWriter.h:35
cnoid::StdSceneWriter::ReplaceWithObjModelFiles
@ ReplaceWithObjModelFiles
Definition: StdSceneWriter.h:38
cnoid::StdBodyWriter::DeviceWriterRegistration::DeviceWriterRegistration
DeviceWriterRegistration(const char *typeName, std::function< bool(StdBodyWriter *writer, Mapping *info, const DeviceType *device)> writeFunction)
Definition: StdBodyWriter.h:52