StateParameter.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
18 * @date 2014
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "StateParameter.h"
24 
30 
32 {
33 
34  StateParameter::StateParameter() : optional(false)
35  {
36  }
37 
38  void
39  StateParameter::setDefaultValue(const VariantContainerBasePtr& value)
40  {
41  profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())].first =
42  value;
43  }
44 
45  VariantContainerBasePtr
47  {
48  return profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())]
49  .first;
50  }
51 
52  void
53  StateParameter::setDefaultValueJson(const QString& valueJson)
54  {
55  profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())].second =
56  valueJson;
57  }
58 
59  QString
61  {
62  return profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())]
63  .second;
64  }
65 
67  StateParameter::FromIceStateParameter(armarx::StateParameterIceBasePtr param)
68  {
70  p->setDefaultValue(param->defaultValue);
71  JSONObjectPtr json = new JSONObject();
72  std::string typeName;
73  try
74  {
75  if (param->defaultValue)
76  {
77  typeName =
78  VariantContainerType::allTypesToString(param->defaultValue->getContainerType());
79  //std::string dataType = Variant::getDataType(Variant::getTypeId(typeName));
80  p->type = QString::fromStdString(typeName);
81  //p->dataType.fromStdString(dataType);
82  json->serializeIceObject(param->defaultValue);
83  p->setDefaultValueJson(QString::fromStdString(json->asString(false)));
84  }
85  }
86  catch (std::exception& e)
87  {
88  ARMARX_INFO_S << "Default value serialization failed: " << typeName << " - "
89  << e.what();
90  }
91 
92  p->optional = param->optionalParam;
93 
94  return p;
95  }
96 
97  StateParameterIceBasePtr
99  {
100  StateParameterIceBasePtr r = armarx::StateParameter::create();
101  r->defaultValue = param->getDefaultValue();
102  r->optionalParam = param->optional;
103  r->set = false;
104  return r;
105  }
106 
109  {
111  StateParameterMap::const_iterator it = params.begin();
112  for (; it != params.end(); it++)
113  {
114  result[it.key().toStdString()] = ToIceStateParameter(it.value());
115  }
116  return result;
117  }
118 
119 } // namespace armarx::statechartmodel
armarx::statechartmodel::StateParameter::FromIceStateParameter
static statechartmodel::StateParameterPtr FromIceStateParameter(armarx::StateParameterIceBasePtr param)
Definition: StateParameter.cpp:67
JSONObject.h
VariantContainer.h
armarx::JSONObject
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition: JSONObject.h:43
armarx::statechartmodel::StateParameter::ToIceStateParameterMap
static armarx::StateParameterMap ToIceStateParameterMap(statechartmodel::StateParameterMap params)
Definition: StateParameter.cpp:108
armarx::statechartmodel::StateParameter::profileDefaultValues
StateParameterProfileDefaultValueMap profileDefaultValues
Definition: StateParameter.h:74
armarx::statechartmodel::StateParameter::getDefaultValue
VariantContainerBasePtr getDefaultValue()
Definition: StateParameter.cpp:46
StateParameter.h
IceInternal::Handle< JSONObject >
armarx::statechartmodel::StateParameter::ToIceStateParameter
static armarx::StateParameterIceBasePtr ToIceStateParameter(statechartmodel::StateParameterPtr param)
Definition: StateParameter.cpp:98
armarx::statechartmodel::StateParameter
Definition: StateParameter.h:50
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::statechartmodel
Definition: XmlWriter.h:36
StatechartProfiles.h
armarx::statechartmodel::StateParameterPtr
std::shared_ptr< StateParameter > StateParameterPtr
Definition: StateParameter.h:45
armarx::statechartmodel::StateParameter::StateParameter
StateParameter()
Definition: StateParameter.cpp:34
armarx::StateParameter::create
static StateParameterPtr create()
Definition: StateParameter.cpp:59
armarx::StatechartProfiles::GetRootName
static std::string GetRootName()
Definition: StatechartProfiles.h:78
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:202
Logging.h
armarx::statechartmodel::StateParameter::setDefaultValue
void setDefaultValue(const VariantContainerBasePtr &value)
Definition: StateParameter.cpp:39
armarx::statechartmodel::StateParameter::setDefaultValueJson
void setDefaultValueJson(const QString &valueJson)
Definition: StateParameter.cpp:53
armarx::statechartmodel::StateParameter::getDefaultValueJson
QString getDefaultValueJson()
Definition: StateParameter.cpp:60
armarx::VariantContainerType::allTypesToString
static std::string allTypesToString(const ContainerTypePtr &type)
Definition: VariantContainer.cpp:250