OacMemorySegment.h
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::WorkingMemory
17 * @author Kai Welke ( welke at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
26 
28 
30 
31 #include <MemoryX/interface/core/EntityBase.h>
32 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
33 #include <MemoryX/interface/memorytypes/MemorySegments.h>
35 
36 #include <vector>
37 
38 namespace memoryx
39 {
41  virtual public PersistentEntitySegment,
42  virtual public OacMemorySegmentBase
43  {
44  public:
45  OacMemorySegment(PersistentObjectClassSegmentBasePrx objClassSegment, CollectionInterfacePrx entityCollection, Ice::CommunicatorPtr ic, bool useMongoIds = true) :
46  PersistentEntitySegment(entityCollection, ic, useMongoIds), OacMemorySegmentBase(),
47  objClassSegment(objClassSegment)
48  {
49  }
50 
51  OacBasePtr getOacById(const ::std::string& id, const ::Ice::Current& = Ice::emptyCurrent) const override
52  {
53  return completeOac(OacBasePtr::dynamicCast(getEntityById(id)));
54  }
55 
56  OacBasePtr getOacByName(const ::std::string& name, const ::Ice::Current& = Ice::emptyCurrent) const override
57  {
58  return completeOac(OacBasePtr::dynamicCast(getEntityByName(name)));
59  }
60 
61  OacBaseList getAll(const ::Ice::Current& = Ice::emptyCurrent) const override
62  {
63  OacBaseList result;
64 
65  EntityIdList entityIdList = getAllEntityIds();
66 
67  for (EntityIdList::const_iterator it = entityIdList.begin(); it != entityIdList.end(); ++it)
68  {
69  OacBasePtr oac = getOacById(*it);
70 
71  if (oac)
72  {
73  result.push_back(oac);
74  }
75  }
76 
77  return result;
78  }
79 
80  protected:
81 
82  /*!
83  * \brief replaceObjectDummies checks the objects class in the SEC part of an OAC
84  * and completes it with the real object class entities from the
85  * PersistentObjectClassSegment.
86  * \param oac OAC in which the object should be replaced
87  * \return Returns same instance as the parameter oac for convenience.
88  */
89  OacBasePtr replaceObjectDummies(OacBasePtr oac) const;
90 
91  /*!
92  * \brief completeOac checks the data of an OAC and completes it with
93  * data from other segments (e.g: object with only the name are fetched
94  * from the PersistentObjectClassSegment.
95  * \param oac OAC that should be completed.
96  * \return Returns same instance as the parameter oac for convenience.
97  */
98  OacBasePtr completeOac(OacBasePtr oac) const;
99  PersistentObjectClassSegmentBasePrx objClassSegment ;
100 
101  };
102 
104 
105  OacBasePtr OacMemorySegment::completeOac(OacBasePtr oac) const
106  {
107  return replaceObjectDummies(oac);
108  }
109 
110  OacBasePtr OacMemorySegment::replaceObjectDummies(OacBasePtr oac) const
111  {
112  if (!oac)
113  {
114  return NULL;
115  }
116 
117  OacPtr oacCast = OacPtr::dynamicCast(oac);
118 
119  if (!oacCast)
120  {
121  throw IceUtil::NullHandleException("Could not cast OacBase into Oac Ptr", 0);
122  }
123 
124  if (!objClassSegment)
125  {
126  throw armarx::LocalException("PersistentObjectClassSegmentBaseProxy is NULL");
127  }
128 
129  SECObjectRelationsBasePtr pre = oacCast->getPredictionFunction()->getSECPreconditions();
130  SECObjectRelationsBasePtr post = oacCast->getPredictionFunction()->getSECEffects();
131 
132  if (pre)
133  {
135  }
136 
137  if (post)
138  {
140  }
141 
142  return oacCast;
143  }
144 
145 }
146 
cyberglove_with_calib_22dof.ic
ic
Definition: cyberglove_with_calib_22dof.py:22
memoryx::OacMemorySegment::getAll
OacBaseList getAll(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: OacMemorySegment.h:61
memoryx::OacMemorySegment::getOacByName
OacBasePtr getOacByName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: OacMemorySegment.h:56
memoryx::OacMemorySegment::OacMemorySegment
OacMemorySegment(PersistentObjectClassSegmentBasePrx objClassSegment, CollectionInterfacePrx entityCollection, Ice::CommunicatorPtr ic, bool useMongoIds=true)
Definition: OacMemorySegment.h:45
Oac.h
SemanticEventChainSegment.h
memoryx::OacMemorySegment
Definition: OacMemorySegment.h:40
memoryx::OacMemorySegment::replaceObjectDummies
OacBasePtr replaceObjectDummies(OacBasePtr oac) const
replaceObjectDummies checks the objects class in the SEC part of an OAC and completes it with the rea...
Definition: BodySchemaMemorySegment.h:109
PersistentEntitySegment.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::OacPtr
IceInternal::Handle< Oac > OacPtr
Definition: Oac.h:40
IceInternal::Handle< ::Ice::Communicator >
memoryx::SemanticEventChainSegment::ReplaceObjectDummies
static void ReplaceObjectDummies(SECObjectRelationsBasePtr objRelations, PersistentObjectClassSegmentBasePrx objClassSegment)
Definition: SemanticEventChainSegment.cpp:37
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
memoryx::OacMemorySegment::completeOac
OacBasePtr completeOac(OacBasePtr oac) const
completeOac checks the data of an OAC and completes it with data from other segments (e....
Definition: BodySchemaMemorySegment.h:104
memoryx::OacMemorySegment::objClassSegment
PersistentObjectClassSegmentBasePrx objClassSegment
Definition: OacMemorySegment.h:99
memoryx::PersistentEntitySegment
The PersistentEntitySegment class is the base class for all memory segments containing memoryx::Entit...
Definition: PersistentEntitySegment.h:107
memoryx::OacMemorySegment::getOacById
OacBasePtr getOacById(const ::std::string &id, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: OacMemorySegment.h:51
ImportExportComponent.h