Hekateros  3.4.3
RoadNarrows Robotics Robot Arm Project
hekXmlCfg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Hekateros
4 //
5 // Library: libhekateros
6 //
7 // File: hekXmlCfg.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-08-13 19:23:07 -0600 (Thu, 13 Aug 2015) $
12  * $Rev: 4065 $
13  *
14  * \brief HekXmlCfg - \h_hek XML configuration class interface.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \copyright
19  * \h_copy 2013-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #ifndef _HEK_XML_CFG_H
50 #define _HEK_XML_CFG_H
51 
52 #include <string>
53 
54 #include "rnr/rnrconfig.h"
55 #include "rnr/appkit/Xml.h"
56 #include "rnr/tinyxml/tinyxml.h"
57 
58 #include "Hekateros/hekateros.h"
59 #include "Hekateros/hekDescArm.h"
60 #include "Hekateros/hekDescEE.h"
61 #include "Hekateros/hekDesc.h"
62 
63 
64 namespace hekateros
65 {
66  //----------------------------------------------------------------------------
67  // HekXmlCfg Class
68  //----------------------------------------------------------------------------
69 
70  /*!
71  * \brief HekXmlCfg \h_hek XML configuration class.
72  */
73  class HekXmlCfg : public rnr::Xml
74  {
75  public:
76  /*!
77  * \brief Default constructor.
78  */
79  HekXmlCfg() :
80  Xml("hekateros", HekXsiUrl, HekXslUrl),
81  m_strMajElemArm("arm"),
82  m_strMajElemEE("end_effector"),
83  m_strAttrProdId("product_id"),
84  m_strElemProdName("product_name"),
85  m_strElemProdBrief("product_brief"),
86  m_strElemProdHwVer("hw_version"),
87  m_strElemProdDoF("dof"),
88  m_strElemProdSize("size")
89  {
90  }
91 
92  /*!
93  * \brief Destructor.
94  */
95  virtual ~HekXmlCfg()
96  {
97  }
98 
99  /*!
100  * \brief Load XML file into DOM and set the \h_hek description.
101  *
102  * \param [out] desc \h_hek robotic maniputator description.
103  * \param strSearchPath Search path of directory paths.
104  * \param strXmlFileName XML file name.
105  * \param bAllInstances Do [not] load and set all instances of XML files
106  * found.
107  *
108  * \copydoc doc_return_std
109  */
110  virtual int load(HekDesc &desc,
111  const std::string &strSearchPath=HekSysCfgPath,
112  const std::string &strXmlFileName=HekEtcCfg,
113  bool bAllInstances=false);
114 
115  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
116  // I/O Methods
117  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
118 
119  /*!
120  * \brief Load XML file into DOM.
121  *
122  * \param strXmlFileName XML file path name.
123  *
124  * \copydoc doc_return_std
125  */
126  virtual int loadFile(const std::string &strXmlFileName=HekEtcCfg)
127  {
128  int rc;
129 
130  rc = Xml::loadFile(strXmlFileName);
131 
132  return rc < 0? -HEK_ECODE_XML: HEK_OK;
133  }
134 
135  /*!
136  * \brief Load XML file into DOM and set the \h_hek description.
137  *
138  * \param desc \h_hek robotic maniputator description.
139  * \param strXmlFileName XML file path name.
140  *
141  * \copydoc doc_return_std
142  */
143  virtual int loadFile(HekDesc &desc,
144  const std::string &strXmlFileName=HekEtcCfg)
145  {
146  int rc;
147 
148  if( (rc = Xml::loadFile(strXmlFileName)) == OK )
149  {
150  rc = setHekDescFromDOM(desc);
151  }
152 
153  return rc < 0? -HEK_ECODE_XML: HEK_OK;
154  }
155 
156  /*!
157  * \brief Save DOM to XML file.
158  *
159  * \param strXmlFileName XML file path name.
160  *
161  * \copydoc doc_return_std
162  */
163  virtual int saveFile(const std::string &strXmlFileName=HekEtcCfg)
164  {
165  int rc;
166 
167  rc = Xml::saveFile(strXmlFileName);
168 
169  return rc < 0? -HEK_ECODE_XML: HEK_OK;
170  }
171 
172  /*!
173  * \brief Set DOM from \h_hek description and save XML file.
174  *
175  * \param desc \h_hek robotic maniputator description.
176  * \param strXmlFileName XML file path name.
177  *
178  * \copydoc doc_return_std
179  */
180  virtual int saveFile(const HekDesc &desc,
181  const std::string &strXmlFileName=HekEtcCfg)
182  {
183  int rc;
184 
185  if( (rc = setDOMFromHekDesc(desc)) == HEK_OK )
186  {
187  rc = Xml::saveFile(strXmlFileName);
188  }
189 
190  return rc < 0? -HEK_ECODE_XML: HEK_OK;
191  }
192 
193  /*!
194  * \brief Create a template \h_hek XML configuration file.
195  *
196  * Any current DOM is not accessed nor altered.
197  *
198  * \param strXmlFileName XML file path name.
199  *
200  * \copydoc doc_return_std
201  */
202  virtual int createTemplateFile(const std::string &strXmlFileName=HekEtcCfg);
203 
204  /*!
205  * \brief Set \h_hek description for DOM.
206  *
207  * \param desc \h_hek robotic manipulator description.
208  *
209  * \copydoc doc_return_std
210  */
211  virtual int setHekDescFromDOM(HekDesc &desc);
212 
213  /*!
214  * \brief Set the DOM from the \h_hek description.
215  *
216  * \param desc \h_hek robotic manipulator description.
217  *
218  * \copydoc doc_return_std
219  */
220  virtual int setDOMFromHekDesc(const HekDesc &desc);
221 
222  protected:
223  std::string m_strMajElemArm; ///< robotic arm major element name
224  std::string m_strMajElemEE; ///< end effector major element name
225  std::string m_strAttrProdId; ///< product id attribute name
226  std::string m_strElemProdName; ///< product name element name
227  std::string m_strElemProdBrief; ///< product brief element name
228  std::string m_strElemProdHwVer; ///< product hardware version element name
229  std::string m_strElemProdDoF; ///< egrees of freedom element name
230  std::string m_strElemProdSize; ///< product size element name
231 
232  /*!
233  * \brief Set \h_hek robotic base description from the DOM.
234  *
235  * \param pElemMaj Pointer to major DOM base description element.
236  * \param pDesc Point to \h_hek robotic base description.
237  *
238  * \copydoc doc_return_std
239  */
240  virtual int setHekArmDescFromDOM(TiXmlElement *pElemMaj,
241  HekDescArm *pDesc);
242 
243  /*!
244  * \brief Set \h_hek end effector description for DOM.
245  *
246  * \param pElemMaj Pointer to major DOM base description element.
247  * \param pDesc Point to \h_hek end effector description.
248  *
249  * \copydoc doc_return_std
250  */
251  virtual int setHekEEDescFromDOM(TiXmlElement *pElemMaj, HekDescEE *pDesc);
252 
253  /*!
254  * \brief Convert string to \h_hek product size code.
255  *
256  * \param [in] str String in hex, decimal, or octal format.
257  * \param [out] val Converted product size.
258  *
259  * \copydoc doc_return_std
260  */
261  int strToProdSizeCode(const std::string &str, int &val);
262 
263  /*!
264  * \brief Convert product size to string equivalent.
265  *
266  * \param [in] val Product size enumerate.
267  * \param [out] str Converted string equivalent.
268  *
269  * \copydoc doc_return_std
270  */
271  int prodSizeToStr(const int val, std::string &str);
272  };
273 
274 } // hekateros namespace
275 
276 #endif // _HEK_XML_CFG_H
const char *const HekSysCfgPath
System configuration search path.
Definition: hekateros.h:322
static const int HEK_OK
not an error, success
Definition: hekateros.h:70
const char *const HekXsiUrl
xml schema instance url
Definition: hekateros.h:371
HekDesc - Hekateros full robotic manipulator descripition class interface.
virtual int setHekDescFromDOM(HekDesc &desc)
Set <b><i>Hekateros</i></b> description for DOM.
Definition: hekXmlCfg.cxx:218
virtual int load(HekDesc &desc, const std::string &strSearchPath=HekSysCfgPath, const std::string &strXmlFileName=HekEtcCfg, bool bAllInstances=false)
Load XML file into DOM and set the <b><i>Hekateros</i></b> description.
Definition: hekXmlCfg.cxx:69
Hekateros end effector tool description class.
Definition: hekDescEE.h:71
virtual int saveFile(const HekDesc &desc, const std::string &strXmlFileName=HekEtcCfg)
Set DOM from <b><i>Hekateros</i></b> description and save XML file.
Definition: hekXmlCfg.h:180
std::string m_strElemProdName
product name element name
Definition: hekXmlCfg.h:226
std::string m_strAttrProdId
product id attribute name
Definition: hekXmlCfg.h:225
virtual ~HekXmlCfg()
Destructor.
Definition: hekXmlCfg.h:95
static const int HEK_ECODE_XML
XML error.
Definition: hekateros.h:91
virtual int saveFile(const std::string &strXmlFileName=HekEtcCfg)
Save DOM to XML file.
Definition: hekXmlCfg.h:163
virtual int createTemplateFile(const std::string &strXmlFileName=HekEtcCfg)
Create a template <b><i>Hekateros</i></b> XML configuration file.
Definition: hekXmlCfg.cxx:128
std::string m_strElemProdDoF
egrees of freedom element name
Definition: hekXmlCfg.h:229
const char *const HekXslUrl
xml stylesheet url
Definition: hekateros.h:360
HekXmlCfg()
Default constructor.
Definition: hekXmlCfg.h:79
std::string m_strMajElemEE
end effector major element name
Definition: hekXmlCfg.h:224
std::string m_strElemProdSize
product size element name
Definition: hekXmlCfg.h:230
Hekateros robotic arm (manipulator) description class.
Definition: hekDescArm.h:77
virtual int setDOMFromHekDesc(const HekDesc &desc)
Set the DOM from the <b><i>Hekateros</i></b> description.
Definition: hekXmlCfg.cxx:272
Hekateros robotic manipulator full description class.
Definition: hekDesc.h:75
Top-level package include file.
HekXmlCfg <b><i>Hekateros</i></b> XML configuration class.
Definition: hekXmlCfg.h:73
HekDescEE - Hekateros end effector tool description class interface.
HekDescArm - Hekateros robotic arm description class interface.
int prodSizeToStr(const int val, std::string &str)
Convert product size to string equivalent.
Definition: hekXmlCfg.cxx:497
virtual int loadFile(const std::string &strXmlFileName=HekEtcCfg)
Load XML file into DOM.
Definition: hekXmlCfg.h:126
std::string m_strElemProdHwVer
product hardware version element name
Definition: hekXmlCfg.h:228
int strToProdSizeCode(const std::string &str, int &val)
Convert string to <b><i>Hekateros</i></b> product size code.
Definition: hekXmlCfg.cxx:464
std::string m_strMajElemArm
robotic arm major element name
Definition: hekXmlCfg.h:223
virtual int setHekEEDescFromDOM(TiXmlElement *pElemMaj, HekDescEE *pDesc)
Set <b><i>Hekateros</i></b> end effector description for DOM.
Definition: hekXmlCfg.cxx:371
std::string m_strElemProdBrief
product brief element name
Definition: hekXmlCfg.h:227
const char *const HekEtcCfg
xml configuration file
Definition: hekateros.h:333
virtual int loadFile(HekDesc &desc, const std::string &strXmlFileName=HekEtcCfg)
Load XML file into DOM and set the <b><i>Hekateros</i></b> description.
Definition: hekXmlCfg.h:143
The <b><i>Hekateros</i></b> namespace encapsulates all <b><i>Hekateros</i></b> related constructs...
Definition: hekateros.h:56
virtual int setHekArmDescFromDOM(TiXmlElement *pElemMaj, HekDescArm *pDesc)
Set <b><i>Hekateros</i></b> robotic base description from the DOM.
Definition: hekXmlCfg.cxx:278