MBSim

Project Page
element.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@googlemail.com
18  * rzander@users.berlios.de
19  */
20 
21 #ifndef _ELEMENT_H_
22 #define _ELEMENT_H_
23 
24 #include "fmatvec.h"
25 #include <string>
26 #include <hdf5serie/vectorserie.h>
27 #include "mbsimtinyxml/tinyxml-src/tinyxml.h"
28 
29 #define MBSIMNS "{http://mbsim.berlios.de/MBSim}"
30 
31 #include "mbsim/mbsim_event.h"
32 
33 #ifdef HAVE_OPENMBVCPPINTERFACE
34 namespace OpenMBV {
35  class Group;
36 }
37 #endif
38 
39 namespace H5 {
40  class Group;
41 }
42 
46 namespace MBSim {
47 
48  class ObjectInterface;
49 
55  };
56 
57  // NOTE!!! When adding a new PlotFeature here, the default setting for this feature must
58  // be specified in dynamic_system_solver.cc:DynamicSystemSolver::constructor() and the
59  // new feature must also be added in
60  // element.cc:Element::initializeUsingXML(TiXmlElement *element)
61  // and in
62  // mbsimxml/schema/mbsim.xsd.in
64  enum PlotFeature {
69  notMinimalState, // TODO
80  LASTPLOTFEATURE
81  };
82 
87  enum InitStage {
88  modelBuildup=0, /*< build up complex internal models */
92  plot,
98  LASTINITSTAGE
99  };
100 
101  class DynamicSystemSolver;
102 
109  class Element {
110  public:
114  Element(const std::string &name);
115 
119  virtual ~Element();
120 
121  /* INTERFACE */
125  virtual void initDataInterfaceBase(DynamicSystemSolver *parentds) {};
126 
130  virtual std::string getType() const { return "Element"; }
131 
135  virtual void setDynamicSystemSolver(DynamicSystemSolver *sys) { ds = sys; }
136 
142  virtual void plot(double t, double dt = 1);
143 
149  virtual void plotAtSpecialEvent(double t, double dt = 1) {}
150 
154  virtual void closePlot();
155  /***************************************************/
156 
160  const std::string& getName() const { return name; }
161 
165  const std::string getShortName() const {
166  size_t i = name.length() - 1;
167 
168  while ((name[i-1] != '/') and (i > 0)) {
169  i--;
170  }
171  return name.substr(i, name.length() - i);
172  }
173 
177  void setName(const std::string &str) { name = str; }
178 
183 
188  virtual void init(InitStage stage);
189 
193  virtual void createPlotGroup();
194 
198  H5::Group *getPlotGroup() { return plotGroup; }
199 
206  virtual void setPlotFeature(PlotFeature pf, PlotFeatureStatus value) { plotFeature[pf]=value; }
207 
213  void setPlotFeatureForChildren(PlotFeature pf, PlotFeatureStatus value) { plotFeatureForChildren[pf]=value; }
214 
220  void setPlotFeatureRecursive(PlotFeature pf, PlotFeatureStatus value) { plotFeature[pf]=value; plotFeatureForChildren[pf]=value; }
221 
226 
230  PlotFeatureStatus getPlotFeatureForChildren(PlotFeature pf) { return plotFeatureForChildren[pf]; }
231 
232  virtual void initializeUsingXML(TiXmlElement *element);
233 
237  template<class T>
238  T* getByPath(std::string path) {
239  Element * e = getByPathSearch(path);
240  if (dynamic_cast<T*>(e))
241  return (T*)(e);
242  else
243  throw MBSimError("ERROR in "+getName()+" (Element::getByPath): Element \""+path+"\" not found or not of wanted type!");
244  }
245 
249  virtual Element* getByPathSearch(std::string path) {return 0; }
250 
251  // some convenience function for XML
252  static double getDouble(TiXmlElement *e);
253  static int getInt(TiXmlElement *e);
254  static bool getBool(TiXmlElement *e);
255  static fmatvec::Vec getVec(TiXmlElement *e, int rows=0);
256  static fmatvec::Mat getMat(TiXmlElement *e, int rows=0, int cols=0);
257  static fmatvec::SqrMat getSqrMat(TiXmlElement *e, int size=0);
258  static fmatvec::SymMat getSymMat(TiXmlElement *e, int size=0);
259 
260 #ifdef HAVE_OPENMBVCPPINTERFACE
261  virtual OpenMBV::Group* getOpenMBVGrp() {return 0;}
262 #endif
263 
264  virtual Element* getParent() {return parent;}
265  virtual const Element* getParent() const {return parent;}
266  virtual void setParent(Element* parent_) {parent = parent_;}
271  std::string getPath(char pathDelim='.');
272 
273  protected:
274  Element *parent;
275 
279  std::string name;
280 
285 
289  H5::VectorSerie<double> *plotVectorSerie;
290 
294  std::vector<double> plotVector;
295 
299  std::vector<std::string> plotColumns;
300 
304  H5::Group *plotGroup;
305 
306  void updatePlotFeatures();
307 
308  private:
312  PlotFeatureStatus plotFeature[LASTPLOTFEATURE], plotFeatureForChildren[LASTPLOTFEATURE];
313  };
314 
315 }
316 
317 #endif