Example #1
0
File: Body.cpp Project: bilwis/RMD
void Body::makeDownstreamPartList(string part_uuid, std::vector<string>* child_list)
{
	boost::shared_ptr<Part> part = getPartByUUID(part_uuid);
	if (part == nullptr)
	{
		return;
	}

	//Part is an Organ: Add all connected organs to the list
	if (part->getType() == TYPE_ORGAN){
		Organ* o = static_cast<Organ*>(part.get());
		for (auto it = o->getConnectedOrgansRW()->begin(); it != o->getConnectedOrgansRW()->end(); it++)
		{
			child_list->push_back(*it);
			makeDownstreamPartList(*it, child_list);
		}
	}

	//Part is a BodyPart: Add all children to the list and call this function on them
	if (part->getType() == TYPE_BODYPART)
	{
		BodyPart* bp = static_cast<BodyPart*>(part.get());
		for (auto it = bp->getChildListRW()->begin(); it != bp->getChildListRW()->end(); it++)
		{
			child_list->push_back(*it);
			makeDownstreamPartList(*it, child_list);
		}
	}
}
Example #2
0
File: Body.cpp Project: bilwis/RMD
void Body::buildPartList(std::vector<GuiObjectLink*>* list, Part* p, int depth)
{
	//debug_print("Depth: %i, Part: %s \n", depth, p->getId());
	if (p->getType() == PartType::TYPE_ORGAN)
	{
		//Append to end of list "gui_list_indent_char [times depth] ORGAN_NAME"
		std::string str = "";

		for (int i = 0; i <= depth; i++)
		{
			str.append(gui_list_indent_char);
		}

		str.append(p->getName());

		list->push_back(
			new GuiObjectLink(
			p->getUUID(),
			new ColoredText(str, part_gui_list_color_organ)
			)
			);

		return;
	}
	if (p->getType() == PartType::TYPE_BODYPART)
	{
		//Append to end of list "gui_list_indent_char [times depth] BODYPART_NAME"
		BodyPart *bp = (BodyPart*)p;
		std::string str = "";

		for (int i = 0; i <= depth; i++)
		{
			str.append(gui_list_indent_char);
		}

		str.append(bp->getName());

		list->push_back(
			new GuiObjectLink(
			bp->getUUID(),
			new ColoredText(str, part_gui_list_color_bodypart)
			)
			);

		//Call this function on all children of the BodyPart
		for (auto it = bp->getChildListRW()->begin(); it != bp->getChildListRW()->end(); it++)
		{
			boost::shared_ptr<Part> part = getPartByUUID(*it);
			if (part == nullptr) { continue; }
			buildPartList(list, part.get(), depth + 1);
		}

		bp = nullptr;

		return;
	}

	debug_error("ERROR: Tried to call recursive part list building function on invalid Part* (neither TYPE_BODYPART nor TYPE_ORGAN)!\n");
	return;
}