RoboidControl-cpp/Sensor.cpp
2024-12-13 16:58:03 +01:00

41 lines
1.0 KiB
C++

#include "Sensor.h"
#include "Roboid.h"
Sensor::Sensor() : Thing() { // for now, id should be set properly later
this->type = (unsigned char)Thing::SensorType;
}
void Sensor::SetParent(Thing *parent) {
this->parent = parent;
if (this->parent->IsRoboid()) {
Roboid *roboidParent = (Roboid *)this->parent;
roboidParent->perception->AddSensor(this);
}
}
void Sensor::ConnectTo(Thing *oldThing) {
this->name = oldThing->name;
this->id = oldThing->id;
Thing *oldParent = oldThing->GetParent();
oldParent->RemoveChild(oldThing);
oldParent->AddChild(this);
for (int childIx = 0; childIx < oldThing->childCount; childIx++) {
Thing *child = oldThing->GetChild(childIx);
this->AddChild(child);
}
this->position = oldThing->position;
this->orientation = oldThing->orientation;
// delete (thing); // can we do this?
}
void Sensor::ConnectTo(Thing *rootThing, const char *thingName) {
Thing *thing = rootThing->FindChild(thingName);
if (thing != nullptr)
this->ConnectTo(thing);
}