Choreonoid  1.8
PutPropertyFunction.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_BASE_PUT_PROPERTY_FUNCTION_H
6 #define CNOID_BASE_PUT_PROPERTY_FUNCTION_H
7 
8 #include <cnoid/Selection>
9 #include <functional>
10 #include "exportdecl.h"
11 
12 namespace cnoid {
13 
15 {
16  std::string filename_;
17  std::string baseDirectory_;
18  std::vector<std::string> filters_;
19  bool isFullpathDisplayMode_ = false;
20  bool isExistingFileMode_ = true;
21  bool isExtensionRemovalModeForFileDialogSelection_ = false;
22 
23 public:
25  FilePathProperty(const std::string& filename) : filename_(filename) { }
26  FilePathProperty(const std::string& filename, const std::vector<std::string>& filters)
27  : filename_(filename), filters_(filters) { }
28 
29  const std::string& filename() const { return filename_; };
30  void setFilename(const std::string& filename) { filename_ = filename; }
31 
33  isExtensionRemovalModeForFileDialogSelection_ = on; }
35  return isExtensionRemovalModeForFileDialogSelection_; }
36 
37  const std::string& baseDirectory() const { return baseDirectory_; };
38  void setBaseDirectory(const std::string& dir) { baseDirectory_ = dir; }
39 
40  const std::vector<std::string>& filters() const { return filters_; }
41  void setFilters(const std::vector<std::string>& filters){ filters_ = filters; }
42 
43  bool isFullpathDisplayMode() const { return isFullpathDisplayMode_; }
44  void setFullpathDisplayMode(bool on) { isFullpathDisplayMode_ = on; }
45 
46  bool isExistingFileMode() const { return isExistingFileMode_; }
47  void setExistingFileMode(bool on) { isExistingFileMode_ = on; }
48 };
49 
50 
51 class CNOID_EXPORT PutPropertyFunction
52 {
53 public:
54  virtual ~PutPropertyFunction();
55 
56  virtual PutPropertyFunction& decimals(int d) = 0;
57  virtual PutPropertyFunction& min(double min) = 0;
58  virtual PutPropertyFunction& max(double max) = 0;
59  virtual PutPropertyFunction& min(int min) = 0;
60  virtual PutPropertyFunction& max(int max) = 0;
61  virtual PutPropertyFunction& reset() = 0;
62 
63  // bool
64  virtual void operator()(const std::string& name, bool value) = 0;
65  virtual void operator()(const std::string& name, bool value,
66  const std::function<bool(bool)>& changeFunc) = 0;
67  // int
68  virtual void operator()(const std::string& name, int value) = 0;
69  virtual void operator()(const std::string& name, int value,
70  const std::function<bool(int)>& changeFunc) = 0;
71  // double
72  virtual void operator()(const std::string& name, double value) = 0;
73  virtual void operator()(const std::string& name, double value,
74  const std::function<bool(double)>& changeFunc) = 0;
75  // string
76  virtual void operator()(const std::string& name, const std::string& value) = 0;
77  virtual void operator()(const std::string& name, const std::string& value,
78  const std::function<bool(const std::string&)>& changeFunc) = 0;
79  // Selection
80  virtual void operator()(const std::string& name, const Selection& selection) = 0;
81  virtual void operator()(const std::string& name, const Selection& selection,
82  const std::function<bool(int which)>& changeFunc) = 0;
83  // FilePath
84  virtual void operator()(const std::string& name, const FilePathProperty& filepath) = 0;
85  virtual void operator()(const std::string& name, const FilePathProperty& filepath,
86  const std::function<bool(const std::string&)>& changeFunc) = 0;
87 };
88 
89 
90 template <class ValueType>
92 {
93  ValueType& variable;
94 public:
95  ChangeProperty(ValueType& variable) : variable(variable) { }
96  bool operator()(const ValueType& value){
97  variable = value;
98  return true;
99  }
100 };
101 
102 template <>
104 {
105  Selection& selection;
106 public:
107  ChangeProperty(Selection& variable) : selection(variable) { }
108  bool operator()(int value){
109  selection.select(value);
110  return true;
111  }
112 };
113 
114 template<class ValueType>
116  return ChangeProperty<ValueType>(variable);
117 }
118 
119 }
120 
121 #endif
cnoid::Selection
Definition: Selection.h:15
cnoid::ChangeProperty< Selection >::ChangeProperty
ChangeProperty(Selection &variable)
Definition: PutPropertyFunction.h:107
cnoid::FilePathProperty::setFullpathDisplayMode
void setFullpathDisplayMode(bool on)
Definition: PutPropertyFunction.h:44
cnoid::PutPropertyFunction
Definition: PutPropertyFunction.h:51
cnoid::FilePathProperty::setFilters
void setFilters(const std::vector< std::string > &filters)
Definition: PutPropertyFunction.h:41
cnoid::FilePathProperty::FilePathProperty
FilePathProperty()
Definition: PutPropertyFunction.h:24
cnoid::ChangeProperty::operator()
bool operator()(const ValueType &value)
Definition: PutPropertyFunction.h:96
cnoid::ChangeProperty::ChangeProperty
ChangeProperty(ValueType &variable)
Definition: PutPropertyFunction.h:95
cnoid::FilePathProperty::filename
const std::string & filename() const
Definition: PutPropertyFunction.h:29
cnoid::ChangeProperty< Selection >::operator()
bool operator()(int value)
Definition: PutPropertyFunction.h:108
cnoid::FilePathProperty::setBaseDirectory
void setBaseDirectory(const std::string &dir)
Definition: PutPropertyFunction.h:38
cnoid::FilePathProperty::setExtensionRemovalModeForFileDialogSelection
void setExtensionRemovalModeForFileDialogSelection(bool on)
Definition: PutPropertyFunction.h:32
cnoid::FilePathProperty::FilePathProperty
FilePathProperty(const std::string &filename)
Definition: PutPropertyFunction.h:25
cnoid::ChangeProperty
Definition: PutPropertyFunction.h:91
cnoid::FilePathProperty::isFullpathDisplayMode
bool isFullpathDisplayMode() const
Definition: PutPropertyFunction.h:43
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::FilePathProperty::isExtensionRemovalModeForFileDialogSelection
bool isExtensionRemovalModeForFileDialogSelection() const
Definition: PutPropertyFunction.h:34
cnoid::FilePathProperty::filters
const std::vector< std::string > & filters() const
Definition: PutPropertyFunction.h:40
cnoid::FilePathProperty
Definition: PutPropertyFunction.h:14
cnoid::FilePathProperty::baseDirectory
const std::string & baseDirectory() const
Definition: PutPropertyFunction.h:37
cnoid::FilePathProperty::FilePathProperty
FilePathProperty(const std::string &filename, const std::vector< std::string > &filters)
Definition: PutPropertyFunction.h:26
cnoid::changeProperty
ChangeProperty< ValueType > changeProperty(ValueType &variable)
Definition: PutPropertyFunction.h:115
cnoid::FilePathProperty::setFilename
void setFilename(const std::string &filename)
Definition: PutPropertyFunction.h:30
cnoid::FilePathProperty::setExistingFileMode
void setExistingFileMode(bool on)
Definition: PutPropertyFunction.h:47
cnoid::FilePathProperty::isExistingFileMode
bool isExistingFileMode() const
Definition: PutPropertyFunction.h:46