StateInstanceFactory.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 Christian Mandery (christian.mandery 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
24
29#include "XmlReader.h"
30
31
32using namespace armarx::exceptions::local;
33using namespace armarx::statechartio;
34using namespace armarx::statechartmodel;
35
36// TODO: This function is copied from XmlReader. The code duplication will be resolved once we use the RapidXmlWrapper here.
37QString
38readAttribute(rapidxml::xml_node<>* node, const QString& attributeName, bool required = true)
39{
40 rapidxml::xml_attribute<>* attribute = node->first_attribute(attributeName.toUtf8());
41
42 if (!attribute)
43 {
44 if (required)
45 {
46 throw XmlReaderException("Attribute \"" + attributeName.toStdString() + "\" for \"" +
47 node->name() + "\" node not found!");
48 }
49 else
50 {
51 return "";
52 }
53 }
54
55 return QString::fromUtf8(attribute->value());
56}
57
58StateInstanceFactoryBase::SubClassRegistry
59 EndStateInstanceFactory::registry(EndStateInstanceFactory::getName(),
61StateInstanceFactoryBase::SubClassRegistry
62 LocalStateInstanceFactory::registry(LocalStateInstanceFactory::getName(),
64StateInstanceFactoryBase::SubClassRegistry
65 RemoteStateInstanceFactory::registry(RemoteStateInstanceFactory::getName(),
67StateInstanceFactoryBase::SubClassRegistry
68 DynamicRemoteStateInstanceFactory::registry(DynamicRemoteStateInstanceFactory::getName(),
70
76
82
85{
86 QString instanceName = readAttribute(xmlNode, "name");
87 QString eventName = readAttribute(xmlNode, "event");
88
89 EndStatePtr endStateInstance(new EndState(instanceName, eventName, parentState));
90 endStateInstance->setPosition(
91 QPointF(readAttribute(xmlNode, "left").toFloat(), readAttribute(xmlNode, "top").toFloat()));
92 endStateInstance->setBoundingBox(readAttribute(xmlNode, "boundingSquareSize").toFloat());
93
94 return endStateInstance;
95}
96
99{
101 new EndStateInstanceFactory(xmlParentPair.first, xmlParentPair.second));
102 return factoryPtr;
103}
104
111
114{
115 QString uuid = readAttribute(xmlNode, "refuuid");
116 QString instanceName = readAttribute(xmlNode, "name");
117
118 LocalStatePtr localStateInstance(new LocalState(uuid, instanceName, parentState));
119 localStateInstance->setPosition(
120 QPointF(readAttribute(xmlNode, "left").toFloat(), readAttribute(xmlNode, "top").toFloat()));
121 localStateInstance->setBoundingBox(readAttribute(xmlNode, "boundingSquareSize").toFloat());
122
123 return localStateInstance;
124}
125
128{
130 new LocalStateInstanceFactory(xmlParentPair.first, xmlParentPair.second));
131 return factoryPtr;
132}
133
140
143{
144 QString uuid = readAttribute(xmlNode, "refuuid");
145 QString instanceName = readAttribute(xmlNode, "name");
146
147 statechartmodel::RemoteStatePtr remoteStateInstance(
148 new statechartmodel::RemoteState(uuid, instanceName, parentState));
149 remoteStateInstance->proxyName = readAttribute(xmlNode, "proxyName");
150 remoteStateInstance->setPosition(
151 QPointF(readAttribute(xmlNode, "left").toFloat(), readAttribute(xmlNode, "top").toFloat()));
152 remoteStateInstance->setBoundingBox(readAttribute(xmlNode, "boundingSquareSize").toFloat());
153
154 return remoteStateInstance;
155}
156
159{
161 new RemoteStateInstanceFactory(xmlParentPair.first, xmlParentPair.second));
162 return factoryPtr;
163}
164
171
174{
175 QString instanceName = readAttribute(xmlNode, "name");
176 QString uuid = readAttribute(xmlNode, "refuuid");
177 DynamicRemoteStatePtr dynamicRemoteStateInstance(
178 new statechartmodel::DynamicRemoteState(uuid, instanceName, parentState));
179 dynamicRemoteStateInstance->setPosition(
180 QPointF(readAttribute(xmlNode, "left").toFloat(), readAttribute(xmlNode, "top").toFloat()));
181 dynamicRemoteStateInstance->setBoundingBox(
182 readAttribute(xmlNode, "boundingSquareSize").toFloat());
183
184 return dynamicRemoteStateInstance;
185}
186
189{
191 new DynamicRemoteStateInstanceFactory(xmlParentPair.first, xmlParentPair.second));
192 return factoryPtr;
193}
QString readAttribute(rapidxml::xml_node<> *node, const QString &attributeName, bool required=true)
DynamicRemoteStateInstanceFactory(rapidxml::xml_node<> *xmlNode, armarx::statechartmodel::StatePtr parentState)
static StateInstanceFactoryBasePtr createInstance(XmlParentPair)
armarx::statechartmodel::StateInstancePtr getStateInstance() override
static StateInstanceFactoryBasePtr createInstance(XmlParentPair)
EndStateInstanceFactory(rapidxml::xml_node<> *xmlNode, armarx::statechartmodel::StatePtr parentState)
armarx::statechartmodel::StateInstancePtr getStateInstance() override
static StateInstanceFactoryBasePtr createInstance(XmlParentPair)
armarx::statechartmodel::StateInstancePtr getStateInstance() override
LocalStateInstanceFactory(rapidxml::xml_node<> *xmlNode, armarx::statechartmodel::StatePtr parentState)
RemoteStateInstanceFactory(rapidxml::xml_node<> *xmlNode, armarx::statechartmodel::StatePtr parentState)
static StateInstanceFactoryBasePtr createInstance(XmlParentPair)
armarx::statechartmodel::StateInstancePtr getStateInstance() override
armarx::statechartmodel::StatePtr parentState
StateInstanceFactoryBase(rapidxml::xml_node<> *xmlNode, armarx::statechartmodel::StatePtr parentState)
Class representing attribute node of XML document.
Definition rapidxml.hpp:907
Ch * value() const
Gets value of node.
Definition rapidxml.hpp:795
Ch * name() const
Gets name of the node.
Definition rapidxml.hpp:774
Class representing a node of XML document.
xml_attribute< Ch > * first_attribute(const Ch *name=nullptr, std::size_t name_size=0, bool case_sensitive=true) const
Gets first attribute of node, optionally matching attribute name.
std::pair< rapidxml::xml_node<> *, armarx::statechartmodel::StatePtr > XmlParentPair
std::shared_ptr< StateInstanceFactoryBase > StateInstanceFactoryBasePtr
std::shared_ptr< State > StatePtr
Definition State.h:48
std::shared_ptr< StateInstance > StateInstancePtr
std::shared_ptr< LocalState > LocalStatePtr
Definition LocalState.h:47
std::shared_ptr< RemoteState > RemoteStatePtr
Definition RemoteState.h:47
std::shared_ptr< EndState > EndStatePtr
Definition EndState.h:45
IceInternal::Handle< DynamicRemoteState > DynamicRemoteStatePtr
float toFloat(const std::string &input)
Converts a string to float and uses always dot as seperator.