openmbvcppinterface  3.1.0
OpenMBV C++ Interface
dynamicattributes.h
1/*
2 OpenMBV - Open Multi Body Viewer.
3 Copyright (C) 2009 Markus Friedrich
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef _OPENMBV_DYNAMICATTRIBUTES_H_
21#define _OPENMBV_DYNAMICATTRIBUTES_H_
22
23#include <openmbvcppinterface/body.h>
24
25#include <utility>
26#include "hdf5serie/vectorserie.h"
27
28namespace OpenMBV {
29
54 class DynamicAttributes : public Body {
55 friend class ObjectFactory;
56 public:
57#ifndef SWIG
58 struct PathData {
59 PathData(std::string path_, bool skip_) : path(std::move(path_)), skip(skip_) {}
60 std::string path;
61 bool skip;
62 };
63 using PathDataList = std::vector<PathData>;
64#endif
65 protected:
67 ~DynamicAttributes() override = default;
68
69 PathDataList objectEnable;
70 PathDataList bodyDrawMethod;
71 PathDataList dynamicColoredBodyTransparency;
72
73 void createHDF5File() override;
74 void openHDF5File() override;
75 H5::VectorSerie<Float>* data{nullptr};
76
77 void updateDataSize();
78 int dataSize { 1 };
79
80 public:
81 int getRows() override { return data?data->getRows():0; }
82 std::vector<Float> getRow(int i) override { return data?data->getRow(i):std::vector<Float>(dataSize); }
83
84 int getDataSize() { return dataSize; }
85
86#ifndef SWIG
88 void setObjectEnable(const PathDataList &p);
89 const PathDataList getObjectEnable() const { return objectEnable; }
90#endif
92 void addObjectEnable(const std::string &p, bool skip=false);
93
94#ifndef SWIG
96 void setBodyDrawMethod(const PathDataList &p);
97 const PathDataList getBodyDrawMethod() const { return bodyDrawMethod; }
98#endif
100 void addBodyDrawMethod(const std::string &p, bool skip=false);
101
102#ifndef SWIG
104 void setDynamicColoredBodyTransparency(const PathDataList &p);
105 const PathDataList getDynamicColoredBodyTransparency() const { return dynamicColoredBodyTransparency; }
106#endif
108 void addDynamicColoredBodyTransparency(const std::string &p, bool skip=false);
109
110 void initializeUsingXML(xercesc::DOMElement *element) override;
111 xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent) override;
112
114 template<typename T>
115 void append(const T& row) {
116 if(data==nullptr) throw std::runtime_error("can not append data to an environment object");
117 if(static_cast<int>(row.size())!=dataSize) throw std::runtime_error("the dimension does not match");
118 data->append(row);
119 }
120 };
121
122}
123
124#endif
void getRow(int row, size_t size, T data[])
void append(const T data[], size_t size)
Definition: body.h:32
Control attributes of other objects dynamically.
Definition: dynamicattributes.h:54
void append(const T &row)
Definition: dynamicattributes.h:115
void setObjectEnable(const PathDataList &p)
Definition: dynamicattributes.cc:33
std::vector< Float > getRow(int i) override
Definition: dynamicattributes.h:82
void setBodyDrawMethod(const PathDataList &p)
Definition: dynamicattributes.cc:43
void addDynamicColoredBodyTransparency(const std::string &p, bool skip=false)
Definition: dynamicattributes.cc:58
void addBodyDrawMethod(const std::string &p, bool skip=false)
Definition: dynamicattributes.cc:48
void initializeUsingXML(xercesc::DOMElement *element) override
Definition: dynamicattributes.cc:95
void setDynamicColoredBodyTransparency(const PathDataList &p)
Definition: dynamicattributes.cc:53
int getRows() override
Definition: dynamicattributes.h:81
void addObjectEnable(const std::string &p, bool skip=false)
Definition: dynamicattributes.cc:38
Definition: objectfactory.h:38
Definition: dynamicattributes.h:58