SECRelation.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 MemoryX::
17* @author Mirko Waechter ( mirko.waechter at kit dot edu)
18* @date 2013
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "SECRelation.h"
24
27
29#include "../ObjectClass.h"
30
31namespace memoryx
32{
33
37
38 SECRelation::SECRelation(const std::string& relationName,
39 const memoryx::ObjectClassList& possibleObjects1,
40 const memoryx::ObjectClassList& possibleObjects2)
41 {
42 name = relationName;
43 ARMARX_CHECK_EXPRESSION(possibleObjects1.size() > 0);
44 ARMARX_CHECK_EXPRESSION(possibleObjects2.size() > 0);
45 objects1 = possibleObjects1;
46 objects2 = possibleObjects2;
47 }
48
49 SECRelation::SECRelation(const std::string& relationName,
50 const ObjectClassBasePtr& possibleObject1,
51 const ObjectClassBasePtr& possibleObject2)
52 {
53 name = relationName;
54 ARMARX_CHECK_EXPRESSION(possibleObject1);
55 ARMARX_CHECK_EXPRESSION(possibleObject2);
56 objects1.push_back(possibleObject1);
57 objects2.push_back(possibleObject2);
58 }
59
60 Ice::ObjectPtr
62 {
63 return clone();
64 }
65
66 bool
67 SECRelation::isEqual(const SECRelationBasePtr& other, bool ignoreName) const
68 {
69 return _isEqual(other, ignoreName, false);
70 }
71
72 bool
73 SECRelation::isEqual(const SECRelationBasePtr& other, const Ice::Current&) const
74 {
75 return isEqual(other, false);
76 }
77
78 bool
79 SECRelation::hasEqualObjects(const SECRelationBasePtr& other, const Ice::Current&)
80 {
81 return isEqual(other, true);
82 }
83
84 std::string
85 SECRelation::getName(const Ice::Current& c) const
86 {
87 return name;
88 }
89
90 void
91 SECRelation::setName(const std::string& name, const Ice::Current&)
92 {
93 this->name = name;
94 }
95
96 std::string
101
102 std::string
107
108 bool
109 SECRelation::_isEqual(const SECRelationBasePtr& other, bool ignoreName, bool reversed) const
110 {
111 if (!ignoreName && getName() != other->getName())
112 {
113 return false;
114 }
115
116 bool foundMatchObj1 = false;
117
118 for (ObjectClassList::const_iterator it = objects1.begin(); it != objects1.end(); it++)
119 {
120 for (ObjectClassList::const_iterator itOther = other->objects1.begin();
121 itOther != other->objects1.end();
122 itOther++)
123 {
124 // ARMARX_VERBOSE_S << "Comparing " << (*it)->getName() << " with " << (*itOther)->getName();
125 if ((*it)->compare(*itOther) ==
126 eEqualClass /*|| (*itOther)->compare(*it) == eEqualClass*/)
127 {
128 foundMatchObj1 = true;
129 }
130 }
131 }
132
133 bool foundMatchObj2 = false;
134
135 for (ObjectClassList::const_iterator it = objects2.begin(); it != objects2.end(); it++)
136 {
137 for (ObjectClassList::const_iterator itOther = other->objects2.begin();
138 itOther != other->objects2.end();
139 itOther++)
140 {
141 // ARMARX_VERBOSE_S << "Comparing " << (*it)->getName() << " with " << (*itOther)->getName();
142 if ((*it)->compare(*itOther) ==
143 eEqualClass /*|| (*itOther)->compare(*it) == eEqualClass*/)
144 {
145 foundMatchObj2 = true;
146 }
147 }
148 }
149
150 bool result = foundMatchObj1 && foundMatchObj2;
151
152 if (!result && !reversed)
153 {
154 SECRelationBasePtr inverseRelation =
155 new SECRelation(getName(), other->objects2, other->objects1);
156 return _isEqual(inverseRelation, ignoreName, true);
157 }
158 else
159 {
160 return result;
161 }
162 }
163
165 {
166 name = "NoConnection";
167 }
168
169 Relations::NoConnectionRelation::NoConnectionRelation(const ObjectClassList& possibleObjects1,
170 const ObjectClassList& possibleObjects2) :
171 SECRelation("NoConnection", possibleObjects1, possibleObjects2)
172 {
173 }
174
176 const ObjectClassBasePtr& possibleObject1,
177 const ObjectClassBasePtr& possibleObject2) :
178 SECRelation("NoConnection", possibleObject1, possibleObject2)
179 {
180 }
181
183 {
184 name = "Touching";
185 }
186
187 Relations::TouchingRelation::TouchingRelation(const ObjectClassList& possibleObjects1,
188 const ObjectClassList& possibleObjects2) :
189 SECRelation("Touching", possibleObjects1, possibleObjects2)
190 {
191 }
192
193 Relations::TouchingRelation::TouchingRelation(const ObjectClassBasePtr& possibleObject1,
194 const ObjectClassBasePtr& possibleObject2) :
195 SECRelation("Touching", possibleObject1, possibleObject2)
196 {
197 }
198
200 {
201 name = "BehindOf";
202 }
203
204 Relations::BehindOfRelation::BehindOfRelation(const ObjectClassList& possibleObjects1,
205 const ObjectClassList& possibleObjects2) :
206 SECRelation("BehindOf", possibleObjects1, possibleObjects2)
207 {
208 }
209
210 Relations::BehindOfRelation::BehindOfRelation(const ObjectClassBasePtr& possibleObject1,
211 const ObjectClassBasePtr& possibleObject2) :
212 SECRelation("BehindOf", possibleObject1, possibleObject2)
213 {
214 }
215
217 {
218 name = "LeftTo";
219 }
220
221 Relations::LeftToRelation::LeftToRelation(const ObjectClassList& possibleObjects1,
222 const ObjectClassList& possibleObjects2) :
223 SECRelation("LeftTo", possibleObjects1, possibleObjects2)
224 {
225 }
226
227 Relations::LeftToRelation::LeftToRelation(const ObjectClassBasePtr& possibleObject1,
228 const ObjectClassBasePtr& possibleObject2) :
229 SECRelation("LeftTo", possibleObject1, possibleObject2)
230 {
231 }
232
234 {
235 name = "RightTo";
236 }
237
238 Relations::RightToRelation::RightToRelation(const ObjectClassList& possibleObjects1,
239 const ObjectClassList& possibleObjects2) :
240 SECRelation("RightTo", possibleObjects1, possibleObjects2)
241 {
242 }
243
244 Relations::RightToRelation::RightToRelation(const ObjectClassBasePtr& possibleObject1,
245 const ObjectClassBasePtr& possibleObject2) :
246 SECRelation("RightTo", possibleObject1, possibleObject2)
247 {
248 }
249
250 armarx::VariantDataClassPtr
251 SECRelation::clone(const Ice::Current&) const
252 {
253 SECRelationPtr result = new SECRelation();
254 result->name = getName();
255
256 for (ObjectClassList::const_iterator it = objects1.begin(); it != objects1.end(); it++)
257 {
258 result->objects1.push_back(ObjectClassBasePtr::dynamicCast((*it)->ice_clone()));
259 }
260
261 for (ObjectClassList::const_iterator it = objects2.begin(); it != objects2.end(); it++)
262 {
263 result->objects2.push_back(ObjectClassBasePtr::dynamicCast((*it)->ice_clone()));
264 }
265
266 return result;
267 }
268
269 std::string
270 SECRelation::output(const Ice::Current&) const
271 {
272 return getName() + " between " + objects1ToString() + " and " + objects2ToString();
273 }
274
275 Ice::Int
276 SECRelation::getType(const Ice::Current&) const
277 {
279 }
280
281 bool
282 SECRelation::validate(const Ice::Current&)
283 {
284 return true;
285 }
286
287 void
288 SECRelation::serialize(const armarx::ObjectSerializerBasePtr& serializer,
289 const Ice::Current&) const
290 {
292 armarx::AbstractObjectSerializerPtr::dynamicCast(serializer);
293 obj->setString("relationName", getName());
294 obj->setStringArray("objects1", ObjectClassMemorySegment::ObjectsToStringList(objects1));
295 obj->setStringArray("objects2", ObjectClassMemorySegment::ObjectsToStringList(objects2));
296 }
297
298 void
299 SECRelation::deserialize(const armarx::ObjectSerializerBasePtr& serializer, const Ice::Current&)
300 {
302 armarx::AbstractObjectSerializerPtr::dynamicCast(serializer);
303 name = obj->getString("relationName");
304 Ice::StringSeq objectStrings1;
305 obj->getStringArray("objects1", objectStrings1);
306
307 for (Ice::StringSeq::iterator it = objectStrings1.begin(); it != objectStrings1.end(); it++)
308 {
309 ObjectClassPtr newObj = new ObjectClass();
310 newObj->setName(*it);
311 objects1.push_back(newObj);
312 }
313
314 Ice::StringSeq objectStrings2;
315 obj->getStringArray("objects2", objectStrings2);
316
317 for (Ice::StringSeq::iterator it = objectStrings2.begin(); it != objectStrings2.end(); it++)
318 {
319 ObjectClassPtr newObj = new ObjectClass();
320 newObj->setName(*it);
321 objects2.push_back(newObj);
322 }
323 }
324
325} // namespace memoryx
constexpr T c
static std::string ObjectsToString(const ObjectClassList &objects)
static Ice::StringSeq ObjectsToStringList(const ObjectClassList &objects)
std::string objects2ToString() const
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
bool hasEqualObjects(const SECRelationBasePtr &other, const Ice::Current &c=Ice::emptyCurrent) override
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const Ice::Current &c=Ice::emptyCurrent) override
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const Ice::Current &c=Ice::emptyCurrent) const override
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
void setName(const std::string &name, const Ice::Current &c=Ice::emptyCurrent) override
std::string getName(const Ice::Current &c=Ice::emptyCurrent) const override
bool _isEqual(const SECRelationBasePtr &other, bool ignoreName=false, bool reversed=false) const
armarx::VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
std::string objects1ToString() const
Ice::Int getType(const Ice::Current &c=Ice::emptyCurrent) const override
Ice::ObjectPtr ice_clone() const override
bool isEqual(const SECRelationBasePtr &other, bool ignoreName) const
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
IceInternal::Handle< AbstractObjectSerializer > AbstractObjectSerializerPtr
const armarx::VariantTypeId SECRelation
Definition SECRelation.h:30
VirtualRobot headers.
IceInternal::Handle< SECRelation > SECRelationPtr
IceInternal::Handle< ObjectClass > ObjectClassPtr
Definition ObjectClass.h:35