Improved connecting
This commit is contained in:
parent
5ee5debf35
commit
6356769aa9
27
Sensor.cpp
27
Sensor.cpp
@ -14,20 +14,27 @@ void Sensor::SetParent(Thing *parent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sensor::ConnectTo(Thing *thing) {
|
void Sensor::ConnectTo(Thing *oldThing) {
|
||||||
this->name = thing->name;
|
this->name = oldThing->name;
|
||||||
this->id = thing->id;
|
this->id = oldThing->id;
|
||||||
|
|
||||||
Thing *thingParent = thing->GetParent();
|
Thing *oldParent = oldThing->GetParent();
|
||||||
thingParent->RemoveChild(thing);
|
|
||||||
thingParent->AddChild(this);
|
oldParent->RemoveChild(oldThing);
|
||||||
this->children = thing->GetChildren();
|
oldParent->AddChild(this);
|
||||||
this->position = thing->position;
|
|
||||||
this->orientation = thing->orientation;
|
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?
|
// delete (thing); // can we do this?
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sensor::ConnectTo(Thing *rootThing, const char *thingName) {
|
void Sensor::ConnectTo(Thing *rootThing, const char *thingName) {
|
||||||
Thing *thing = rootThing->FindChild(thingName);
|
Thing *thing = rootThing->FindChild(thingName);
|
||||||
this->ConnectTo(thing);
|
if (thing != nullptr)
|
||||||
|
this->ConnectTo(thing);
|
||||||
}
|
}
|
||||||
|
@ -65,12 +65,13 @@ void Thing::AddChild(Thing *child) {
|
|||||||
this->childCount++;
|
this->childCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thing *Passer::RoboidControl::Thing::RemoveChild(Thing *child) {
|
Thing *Thing::RemoveChild(Thing *child) {
|
||||||
Thing **newChildren = new Thing *[this->childCount - 1];
|
int newChildCount = this->childCount - 1;
|
||||||
|
Thing **newChildren = new Thing *[newChildCount];
|
||||||
unsigned char newChildIx = 0;
|
unsigned char newChildIx = 0;
|
||||||
for (unsigned char childIx = 0; childIx < this->childCount; childIx++) {
|
for (unsigned char childIx = 0; childIx < this->childCount; childIx++) {
|
||||||
if (this->children[childIx] != child) {
|
if (this->children[childIx] != child) {
|
||||||
if (newChildIx == this->childCount - 1) { // We did not find the child
|
if (newChildIx == newChildCount) { // We did not find the child
|
||||||
// stop copying and return nothing
|
// stop copying and return nothing
|
||||||
delete[] newChildren;
|
delete[] newChildren;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -83,7 +84,7 @@ Thing *Passer::RoboidControl::Thing::RemoveChild(Thing *child) {
|
|||||||
|
|
||||||
delete[] this->children;
|
delete[] this->children;
|
||||||
this->children = newChildren;
|
this->children = newChildren;
|
||||||
this->childCount--;
|
this->childCount = newChildCount;
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
1
Thing.h
1
Thing.h
@ -117,6 +117,7 @@ protected:
|
|||||||
static const unsigned int SensorType = 0x4000;
|
static const unsigned int SensorType = 0x4000;
|
||||||
/// @brief Bitmap for Roboid type
|
/// @brief Bitmap for Roboid type
|
||||||
static const unsigned int RoboidType = 0x2000;
|
static const unsigned int RoboidType = 0x2000;
|
||||||
|
static const unsigned char CustomType = 0x80;
|
||||||
|
|
||||||
/// @brief Basic Thing types
|
/// @brief Basic Thing types
|
||||||
enum class Type {
|
enum class Type {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user