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 DeleteObjectInstanceFromWorkingMemory::Registry(DeleteObjectInstanceFromWorkingMemory::GetName(), &DeleteObjectInstanceFromWorkingMemory::CreateInstance);
35 
37 {
38  memoryx::ObjectInstanceMemorySegmentBasePrx instancesSegment = getWorkingMemory()->getObjectInstancesSegment();
39  if (in.isObjectClassNameSet() and not in.getObjectClassName().empty())
40  {
41  std::string objectClassName = in.getObjectClassName();
42  if (objectClassName.find("/") != std::string::npos)
43  {
44  // It is an armarx::ObjectID.
45  // In this case, we do nothing.
46  ARMARX_INFO << "Got an ObjectID as class name: " << objectClassName;
47 
48  objpose::DetachObjectFromRobotNodeInput input;
49  toIce(input.objectID, ObjectID(objectClassName));
50  getObjectPoseStorage()->detachObjectFromRobotNode(input);
51  }
52  else
53  {
54  memoryx::ObjectInstanceList instances = instancesSegment->getObjectInstancesByClass(objectClassName);
55  ARMARX_INFO << "Removing " << instances.size() << " of object class '" << objectClassName << "'";
56  for (memoryx::ObjectInstanceBasePtr const& instance : instances)
57  {
58  std::string id = instance->getId();
59  ARMARX_INFO << "Removing object of class '" << objectClassName << "' with id '" << id << "'";
60 
61  instancesSegment->removeEntity(id);
62  }
63  }
64  }
65  else if (in.isObjectInstanceChannelSet() || in.isObjectInstanceIdSet())
66  {
67  const std::string id = in.isObjectInstanceIdSet() ? in.getObjectInstanceId() : in.getObjectInstanceChannel()->getDataField("id")->getString();
68  ARMARX_INFO << "Removing object with id '" << id << "'";
69 
70  instancesSegment->removeEntity(id);
71  }
72  else
73  {
74  ARMARX_WARNING << "Neither object instance channel nor ID set.";
75  }
76 }
77 
79 {
80  TimeUtil::MSSleep(in.getWaitTime());
81  emitSuccess();
82 }
83 
84 // DO NOT EDIT NEXT FUNCTION
86 {
88 }
89 
ice_conversions.h
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:11
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:94
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
DeleteObjectInstanceFromWorkingMemory.h
armarx::MemoryXUtility::DeleteObjectInstanceFromWorkingMemory::onEnter
void onEnter() override
Definition: DeleteObjectInstanceFromWorkingMemory.cpp:36
armarx::MemoryXUtility::DeleteObjectInstanceFromWorkingMemory::Registry
static SubClassRegistry Registry
Definition: DeleteObjectInstanceFromWorkingMemory.h:44
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:78
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::MemoryXUtility::DeleteObjectInstanceFromWorkingMemory::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: DeleteObjectInstanceFromWorkingMemory.cpp:85
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::MemoryXUtility::DeleteObjectInstanceFromWorkingMemory::DeleteObjectInstanceFromWorkingMemory
DeleteObjectInstanceFromWorkingMemory(const XMLStateConstructorParams &stateData)
Definition: DeleteObjectInstanceFromWorkingMemory.h:32
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28