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
30using namespace armarx;
31using namespace MemoryXUtility;
32
33// DO NOT EDIT NEXT LINE
34DeleteObjectInstanceFromWorkingMemory::SubClassRegistry
36 DeleteObjectInstanceFromWorkingMemory::GetName(),
38
39void
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
88void
90{
91 TimeUtil::MSSleep(in.getWaitTime());
92 emitSuccess();
93}
94
95// DO NOT EDIT NEXT FUNCTION
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition TimeUtil.cpp:100
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)