DeleteObjectInstanceFromWorkingMemory.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 RobotSkillTemplates::MemoryXUtility
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 
26 //#include <ArmarXCore/observers/variant/DatafieldRef.h>
28 
29 
30 using namespace armarx;
31 using namespace MemoryXUtility;
32 
33 // DO NOT EDIT NEXT LINE
34 DeleteObjectInstanceFromWorkingMemory::SubClassRegistry
36  DeleteObjectInstanceFromWorkingMemory::GetName(),
38 
39 void
41 {
42  memoryx::ObjectInstanceMemorySegmentBasePrx instancesSegment =
43  getWorkingMemory()->getObjectInstancesSegment();
44  if (in.isObjectClassNameSet() and not in.getObjectClassName().empty())
45  {
46  std::string objectClassName = in.getObjectClassName();
47  if (objectClassName.find("/") != std::string::npos)
48  {
49  // It is an armarx::ObjectID.
50  // In this case, we do nothing.
51  ARMARX_INFO << "Got an ObjectID as class name: " << objectClassName;
52 
53  objpose::DetachObjectFromRobotNodeInput input;
54  toIce(input.objectID, ObjectID(objectClassName));
55  getObjectPoseStorage()->detachObjectFromRobotNode(input);
56  }
57  else
58  {
59  memoryx::ObjectInstanceList instances =
60  instancesSegment->getObjectInstancesByClass(objectClassName);
61  ARMARX_INFO << "Removing " << instances.size() << " of object class '"
62  << objectClassName << "'";
63  for (memoryx::ObjectInstanceBasePtr const& instance : instances)
64  {
65  std::string id = instance->getId();
66  ARMARX_INFO << "Removing object of class '" << objectClassName << "' with id '"
67  << id << "'";
68 
69  instancesSegment->removeEntity(id);
70  }
71  }
72  }
73  else if (in.isObjectInstanceChannelSet() || in.isObjectInstanceIdSet())
74  {
75  const std::string id = in.isObjectInstanceIdSet()
76  ? in.getObjectInstanceId()
77  : in.getObjectInstanceChannel()->getDataField("id")->getString();
78  ARMARX_INFO << "Removing object with id '" << id << "'";
79 
80  instancesSegment->removeEntity(id);
81  }
82  else
83  {
84  ARMARX_WARNING << "Neither object instance channel nor ID set.";
85  }
86 }
87 
88 void
90 {
91  TimeUtil::MSSleep(in.getWaitTime());
92  emitSuccess();
93 }
94 
95 // DO NOT EDIT NEXT FUNCTION
98 {
100 }
ice_conversions.h
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:10
armarx::TimeUtil::MSSleep
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition: TimeUtil.cpp:100
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
DeleteObjectInstanceFromWorkingMemory.h
armarx::MemoryXUtility::DeleteObjectInstanceFromWorkingMemory::onEnter
void onEnter() override
Definition: DeleteObjectInstanceFromWorkingMemory.cpp:40
armarx::MemoryXUtility::DeleteObjectInstanceFromWorkingMemory::Registry
static SubClassRegistry Registry
Definition: DeleteObjectInstanceFromWorkingMemory.h:52
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::toIce
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:15
armarx::MemoryXUtility::DeleteObjectInstanceFromWorkingMemory::run
void run() override
Definition: DeleteObjectInstanceFromWorkingMemory.cpp:89
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:12
armarx::MemoryXUtility::DeleteObjectInstanceFromWorkingMemory::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: DeleteObjectInstanceFromWorkingMemory.cpp:97
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::MemoryXUtility::DeleteObjectInstanceFromWorkingMemory::DeleteObjectInstanceFromWorkingMemory
DeleteObjectInstanceFromWorkingMemory(const XMLStateConstructorParams &stateData)
Definition: DeleteObjectInstanceFromWorkingMemory.h:33
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27