source: flair-src/branches/mavlink/lib/FlairCore/src/Widget.cpp@ 63

Last change on this file since 63 was 63, checked in by Thomas Fuhrmann, 8 years ago

Save config on target and save all locally are now working

File size: 6.7 KB
RevLine 
[2]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[2]4// %flair:license}
5// created: 2012/05/02
6// filename: Widget.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Abstract class for all Framework's widget classes
14//
15//
16/*********************************************************************/
17
18#include "Widget.h"
19#include "Widget_impl.h"
20
21using std::string;
22
[63]23//remove, for tests
24#include <iostream>
25
[15]26namespace flair {
27namespace gui {
[2]28
29using namespace core;
30
[15]31Widget::Widget(const Widget *parent, string name, string type)
32 : Object(parent, name, type) {
33 pimpl_ = new Widget_impl(this, parent, name, type);
[2]34}
35
[15]36Widget::~Widget() { delete pimpl_; }
[2]37
[15]38template <> bool Widget::GetPersistentXmlProp(std::string prop, double &value) {
39 xmlChar *result = NULL;
40 result = xmlGetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
[2]41
[15]42 if (result != NULL) {
43 value = xmlXPathCastStringToNumber(result);
44 xmlFree(result);
45 return true;
46 } else {
47 return false;
48 }
[2]49}
50
[15]51template <> bool Widget::GetPersistentXmlProp(std::string prop, float &value) {
52 double tmp;
53 if (GetPersistentXmlProp<double>(prop, tmp)) {
54 value = tmp;
55 return true;
56 } else {
57 return false;
58 }
[2]59}
60
[15]61template <> bool Widget::GetPersistentXmlProp(std::string prop, bool &value) {
62 double tmp;
63 if (GetPersistentXmlProp<double>(prop, tmp)) {
64 value = tmp;
65 return true;
66 } else {
67 return false;
68 }
[2]69}
70
71template <>
[15]72bool Widget::GetPersistentXmlProp(std::string prop, int32_t &value) {
73 double tmp;
74 if (GetPersistentXmlProp<double>(prop, tmp)) {
75 value = tmp;
76 return true;
77 } else {
78 return false;
79 }
[2]80}
81
82template <>
[15]83bool Widget::GetPersistentXmlProp(std::string prop, uint16_t &value) {
84 double tmp;
85 if (GetPersistentXmlProp<double>(prop, tmp)) {
86 value = tmp;
87 return true;
88 } else {
89 return false;
90 }
[2]91}
92
93template <>
[53]94bool Widget::GetPersistentXmlProp(std::string prop, std::string &value) {
95 xmlChar *result = NULL;
96 result = xmlGetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
97 if (result != NULL) {
[59]98 value = std::string((char *)result);
[53]99 xmlFree(result);
100 return true;
101 } else {
102 return false;
103 }
104}
105
106template <>
[15]107void Widget::SetVolatileXmlProp(string prop, string value, xmlNodePtr node) {
108 if (node == NULL)
109 node = pimpl_->send_node;
110 xmlSetProp(node, (xmlChar *)prop.c_str(), (xmlChar *)value.c_str());
[2]111}
112
113template <>
[15]114void Widget::SetVolatileXmlProp(string prop, char *value, xmlNodePtr node) {
115 if (node == NULL)
116 node = pimpl_->send_node;
117 xmlSetProp(node, (xmlChar *)prop.c_str(), (xmlChar *)value);
[2]118}
119
120template <>
[15]121void Widget::SetVolatileXmlProp(string prop, double value, xmlNodePtr node) {
122 xmlChar *xmlChar_value = xmlXPathCastNumberToString(value);
[2]123
[15]124 if (node == NULL)
125 node = pimpl_->send_node;
126 xmlSetProp(node, (xmlChar *)prop.c_str(), xmlChar_value);
127 xmlFree(xmlChar_value);
[2]128}
129
130template <>
[15]131void Widget::SetVolatileXmlProp(string prop, float value, xmlNodePtr node) {
132 SetVolatileXmlProp<double>(prop, value, node);
[2]133}
134
135template <>
[15]136void Widget::SetVolatileXmlProp(string prop, int32_t value, xmlNodePtr node) {
137 SetVolatileXmlProp<double>(prop, value, node);
[2]138}
139
140template <>
[15]141void Widget::SetVolatileXmlProp(string prop, uint32_t value, xmlNodePtr node) {
142 SetVolatileXmlProp<double>(prop, value, node);
[2]143}
144
145template <>
[15]146void Widget::SetVolatileXmlProp(string prop, int16_t value, xmlNodePtr node) {
147 SetVolatileXmlProp<double>(prop, value, node);
[2]148}
149
150template <>
[15]151void Widget::SetVolatileXmlProp(string prop, uint16_t value, xmlNodePtr node) {
152 SetVolatileXmlProp<double>(prop, value, node);
[2]153}
154
155template <>
[15]156void Widget::SetVolatileXmlProp(string prop, int8_t value, xmlNodePtr node) {
157 SetVolatileXmlProp<double>(prop, value, node);
[2]158}
159
160template <>
[15]161void Widget::SetVolatileXmlProp(string prop, uint8_t value, xmlNodePtr node) {
162 SetVolatileXmlProp<double>(prop, value, node);
[2]163}
164
165template <>
[15]166void Widget::SetVolatileXmlProp(string prop, bool value, xmlNodePtr node) {
167 SetVolatileXmlProp<double>(prop, value, node);
[2]168}
169
170template <>
[15]171void Widget::SetVolatileXmlProp(string prop, xmlChar *value, xmlNodePtr node) {
172 if (node == NULL)
173 node = pimpl_->send_node;
174 xmlSetProp(node, (xmlChar *)prop.c_str(), value);
[2]175}
176
177template <>
[15]178void Widget::SetVolatileXmlProp(string prop, DataType const &dataType,
179 xmlNodePtr node) {
180 if (node == NULL)
181 node = pimpl_->send_node;
182 xmlSetProp(node, (xmlChar *)prop.c_str(),
183 (xmlChar *)dataType.GetDescription().c_str());
184 /*
185 switch(dataType)
186 {
187 case io_data::Float:
188 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"float");
189 break;
190 case io_data::Int8_t:
191 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"int8_t");
192 break;
193 case io_data::Int16_t:
194 xmlSetProp(node,(xmlChar*)prop.c_str(),(xmlChar*)"int16_t");
195 break;
196 }
197 */
[2]198}
199
[15]200template <> void Widget::SetPersistentXmlProp(std::string prop, double value) {
201 SetVolatileXmlProp(prop, value);
202 SetVolatileXmlProp(prop, value, pimpl_->file_node);
[2]203}
204
[15]205template <> void Widget::SetPersistentXmlProp(std::string prop, float value) {
206 SetVolatileXmlProp(prop, value);
207 SetVolatileXmlProp(prop, value, pimpl_->file_node);
[2]208}
209
[15]210template <> void Widget::SetPersistentXmlProp(std::string prop, int32_t value) {
211 SetVolatileXmlProp(prop, value);
212 SetVolatileXmlProp(prop, value, pimpl_->file_node);
[2]213}
214
215template <>
[15]216void Widget::SetPersistentXmlProp(std::string prop, uint16_t value) {
217 SetVolatileXmlProp(prop, value);
218 SetVolatileXmlProp(prop, value, pimpl_->file_node);
[2]219}
220
[15]221template <> void Widget::SetPersistentXmlProp(std::string prop, bool value) {
222 SetVolatileXmlProp(prop, value);
223 SetVolatileXmlProp(prop, value, pimpl_->file_node);
[2]224}
225
[63]226template <> void Widget::SetPersistentXmlProp(std::string prop, std::string value) {
227 SetVolatileXmlProp(prop, value);
228 SetVolatileXmlProp(prop, value, pimpl_->file_node);
229}
230
231void Widget::UnsetPersistentXmlProp(std::string prop) {
232 xmlNodePtr Node = pimpl_->file_node;
233
234 for(xmlAttrPtr attr = Node->properties; NULL != attr; attr = attr->next)
235 {
236 std::cout << attr->name << std::endl;
237 }
238
239 int ret = xmlUnsetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
240 std::cout << "UnsetPersistentXmlProp, item= " << prop << "result = " << ret << std::endl;
241
242 for(xmlAttrPtr attr = Node->properties; NULL != attr; attr = attr->next)
243 {
244 std::cout << attr->name << std::endl;
245 }
246}
247
[15]248void Widget::SendXml(void) { pimpl_->SendXml(); }
[2]249
[15]250void Widget::setEnabled(bool status) { pimpl_->setEnabled(status); }
[2]251
[15]252bool Widget::isEnabled(void) const { return pimpl_->isenabled; }
[2]253
254} // end namespace gui
255} // end namespace flair
Note: See TracBrowser for help on using the repository browser.