Beispiel #1
0
void ResourceWindow::updateCharacter( Fl_Tree_Item* tree, SmartBody::SBCharacter* character )
{
	SmartBody::SBCharacter* sbcharacter = dynamic_cast<SmartBody::SBCharacter*>(character);
	Fl_Tree_Item* item = resourceTree->add(tree,character->getName().c_str());
	item->user_data((void*) addSpecialName(character->getName()));
	resourceTree->sortorder(FL_TREE_SORT_NONE);		
	Fl_Tree_Item* skeletonFolder = resourceTree->add(item,"skeleton");	
	skeletonFolder->user_data((void*) _reverseSpecialNames["skeleton"]); 
	SmartBody::SBSkeleton* sbSk = sbcharacter->getSkeleton();
	if (sbSk)
	{
		Fl_Tree_Item* charSkItem = resourceTree->add(skeletonFolder, sbSk->getName().c_str());
	}
	Fl_Tree_Item* controllerFolder = resourceTree->add(item,"controllers");	
	controllerFolder->user_data((void*) _reverseSpecialNames["controller"]); 
	controllerFolder->close();
	// add controllers
	MeControllerTreeRoot* ctTree = character->ct_tree_p ;
	if( ctTree )
	{
		int n = ctTree->count_controllers();
		for (int c = 0; c < n; c++)
		{
			//LOG( "%s", ctTree->controller(c)->name() );
			Fl_Tree_Item* ctrlItem = resourceTree->add(controllerFolder,ctTree->controller(c)->getName().c_str());
//			ctrlItem->user_data((void*)ITEM_CONTROLLER);
		}
	}
	/*
	// add gesture map
	Fl_Tree_Item* gestureFolder = resourceTree->add(item,"gestures");	
	gestureFolder->user_data((void*)-1);
	gestureFolder->close();
	// add individual gesture mappings
	SmartBody::SBScene* scene = SmartBody::SBScene::getScene();

	SBGestureMap* gestureMap = scene->getGestureMapManager()->getGestureMap(sbcharacter->getName());
	if (gestureMap)
	{
		std::string lexeme;
		std::string type;
		std::string hand;
		std::string style;
		std::string posture;

		gestureMap->getGestureByInfo(lexeme, type, hand, style, posture);
		Fl_Tree_Item* gestureItem = resourceTree->add(gestureFolder, lexeme.c_str());
		gestureItem->user_data((void*)ITEM_GESTUREMAP);
	}
	*/

	// add NVBG
	Fl_Tree_Item* nvbgItem = resourceTree->add(item, "minibrain");
	nvbgItem->user_data((void*) _reverseSpecialNames["minibrain"]); 
	SmartBody::Nvbg* nvbg = character->getNvbg();
	if (nvbg)
	{
		nvbgItem = resourceTree->add(item, nvbg->getName().c_str());
	}
}
Beispiel #2
0
void RtVarsTree::buildTree() {
	clear();
	if (p_CarState) {
		char buffer[64];
		buffer[sizeof(buffer)-1] = '\0';

		begin();

		// Can Values

		AnalogMapVarIterator v;
		AnalogMapGroupIterator g;

		for (g = p_CarState->analog_data.begin(); g != p_CarState->analog_data.end(); g++) {
			for (v = (*g).second.begin(); v != (*g).second.end(); v++) {
				Fl_Tree_Item *item;

				double physical_value;
				if ((*v).second.Signedness) {
					physical_value = (double)(int32_t)(*v).second.RawValue * (*v).second.Scale + (*v).second.Offset;
				} else {
					physical_value = (double)        (*v).second.RawValue * (*v).second.Scale + (*v).second.Offset;
				}

				snprintf(buffer, sizeof(buffer)-1, "%s/%s = %lu (%lf%s%s)",
					(*g).first.c_str(),
					(*v).first.c_str(),
					(long unsigned)(*v).second.RawValue,
					physical_value,
					(*v).second.Units[0] != '\0' ? " " : "",
					(*v).second.Units
				);

				item = add(buffer);
				item->user_data((void*)NULL);
				printf(">> %s\n", buffer);
			}
		}

		// Pwm Values
		PwmMapIterator p;
		for (p = p_CarState->pwm_data.begin(); p != p_CarState->pwm_data.end(); p++) {
				Fl_Tree_Item *item;
				snprintf(buffer, sizeof(buffer)-1, "PWM/%s = %lu of %lu (%.2lf%%)",
					(*p).first.c_str(),
					(long unsigned)(*p).second.PulseWidth,
					(long unsigned)(*p).second.Period,
					(long unsigned)(*p).second.Period == 0 ? 0.0 : 100.0 * (*p).second.getIntensity()
				);
				item = add(buffer);
				item->user_data((void*)NULL);
				printf(">> %s\n", buffer);
		}

		end();

	}
}
Beispiel #3
0
	int RemoveAIButton::handle(int evt) {
		if(evt == 2) {
			if(appended_ai_tree) 
			{
				std::shared_ptr<AppendAIPatch> aip = std::dynamic_pointer_cast<AppendAIPatch>(mods->get("aip"));
				Fl_Tree_Item* first = appended_ai_tree->first();

				if(first->is_selected()) {
					for(int child = 0; child < first->children(); child++) {
						delete (int*)(first->child(child)->user_data());
					}
					first->clear_children();
					aip->undo();
					aip->set_appended_ai(AppendAIPatch::entity_storage());
					mods_window->redraw();
					return Fl_Button::handle(evt);
				}

				for(int pos = 0; pos < first->children(); pos++)
				{
					if(!first->child(pos)->is_selected()) {
						continue;
					}

					Fl_Tree_Item* selected = first->child(pos);

					int appended_idx = *(int*)selected->user_data();

					//correct indices after removal
					for(int child = 0; child < first->children(); child++) {
						int* idx = (int*)(first->child(child)->user_data());
						if(*idx > appended_idx) {
							(*idx)--;
						}
					}

					AppendAIPatch::entity_storage appended = aip->appended_ai();
					appended.erase(appended.begin()+appended_idx);
					aip->set_appended_ai(appended);
					
					delete (int*)(selected->user_data());
					appended_ai_tree->remove(selected);
				}

				mods_window->redraw();
				if(aip->appended_ai().empty()) {
					aip->undo();
				}
			}
		}

		return Fl_Button::handle(evt);
	}
Beispiel #4
0
static void send_to_editor_cb(Fl_Widget*, void *s) {
	ObjectTree *self = (ObjectTree*)s;
	Fl_Tree_Item *titem = self->first_selected_item();

	if(!titem || !titem->user_data()) return;

	Entity *en = (Entity*)titem->user_data();
	Fl_Text_Buffer *ebuf = self->get_editor_buffer();

	E_RETURN_IF_FAIL(ebuf != NULL);

	char buf[EDELIB_DBUS_EXPLORER_DEFAULT_SCRIPT_EVAL_BUFSIZE];
	if(en->get_prototype_as_scheme(buf, sizeof(buf)))
		ebuf->append(buf);
}
Beispiel #5
0
void ModelerUserInterface::populateList(GroupProperty* group, Fl_Tree_Item* parent) {
	// Create a tree node for this group.
	Fl_Tree_Item* item;
	if (parent == NULL) {
		// HACK: We have to add and remove a fake list item so that the tree
		// control will create a root node to put it under.
		m_controlsTree->remove(m_controlsTree->add("You shouldn't see this."));

		item = m_controlsTree->root();
		item->label(group->getName());
	} else {
		item = m_controlsTree->add(parent, group->getName());
	}
	item->user_data(group);

	// Examine the group's property list for group properties.
	PropertyList* controls = group->getProperties();
	for (PropertyList::iterator iter = controls->begin();
		 iter != controls->end();
		 iter++) {
	    // See if it's a GroupProperty by attempting to cast it
		GroupProperty* childGroup = dynamic_cast<GroupProperty*>(*iter);

		// If it is, add it to the list.
		if (childGroup) {
			ModelerUserInterface::populateList(childGroup, item);
		}
	}
}
Beispiel #6
0
void ResourceWindow::treeCallBack( Fl_Widget* widget, void* data )
{
	//LOG("Tree call back....");

	Fl_Tree      *tree = (Fl_Tree*)widget;
	Fl_Tree_Item *item = (Fl_Tree_Item*)tree->callback_item();	// get selected item
	ResourceWindow* window = (ResourceWindow*)data;
	if (tree->callback_reason() == FL_TREE_REASON_SELECTED)
	{
		std::stringstream strstr;
		strstr <<  window->getNameFromItem(item);
		long specialNameIndex = (long) item->user_data();
		if (specialNameIndex == 0) // assume any item with a special name doesn't need an additional label
			strstr << "/" << item->label();
			
		SBSelectionManager::getSelectionManager()->select(strstr.str());
	}	
	if (tree->callback_reason() == FL_TREE_REASON_DESELECTED)
	{
		std::stringstream strstr;
		strstr <<  window->getNameFromItem(item) << "/" << item->label();
			
		//SBSelectionManager::getSelectionManager()->select("");
	}
}
Beispiel #7
0
std::string ResourceWindow::getNameFromItem(Fl_Tree_Item* item)
{
	// find the item just under the root item
	std::string subname = "";
	Fl_Tree_Item* curItem = item;
	int numSubnames = 0;
	if (!curItem)
		return "";

	if (item == resourceTree->root())
		return "ROOT";

	while (curItem->parent() != resourceTree->root())
	{
		long specialNameIndex = (long) curItem->user_data();
		if (specialNameIndex > 0)
		{
			subname = "/" + _specialNames[specialNameIndex] + subname;
			numSubnames++;
		}
		curItem = curItem->parent();
	}

	return  getNameFromTree(curItem) + subname;
}
Beispiel #8
0
void ModelerUserInterface::TreeCallback(Fl_Tree* tree, void* p) {
	if (tree->callback_reason() == FL_TREE_REASON_SELECTED) {
		Fl_Tree_Item *item = tree->callback_item();

		ModelerUserInterface::getInstance()->pickGroupProperty(
		(GroupProperty*) item->user_data());
	}
}
Beispiel #9
0
void ResourceWindow::updatePath( Fl_Tree_Item* tree, const std::vector<std::string>& pathList )
{
	resourceTree->clear_children(tree);	
	for (size_t p = 0; p < pathList.size(); p++)
	{
		Fl_Tree_Item* item = resourceTree->add(tree, pathList[p].c_str());
		item->user_data(tree->user_data());
	}	
}
void ModelerUserInterface::CurveTreeCallback(Fl_Tree* tree, void* p) {
	Fl_Tree_Item *item = tree->callback_item();

	// Only process leaf nodes.
	if (item->children()) {
		return;
	}

	// Determine how to change selection state.
	switch (tree->callback_reason()) {
	case FL_TREE_REASON_SELECTED:
		ModelerUserInterface::getInstance()->pickCurve((int)item->user_data(), true);
		break;
	case FL_TREE_REASON_DESELECTED:
		ModelerUserInterface::getInstance()->pickCurve((int)item->user_data(), false);
		break;
	}
}
// TODO: populate the curve list once we actually have a list of curves.
void ModelerUserInterface::populateCurveList(Property* prop, Fl_Tree_Item* parent) {
	// Create a tree node for this property
	Fl_Tree_Item* item;
	if (parent == NULL) {
		// HACK: We have to add and remove a fake list item so that the tree
		// control will create a root node to put it under.
		curvesTree->remove(curvesTree->add("You shouldn't see this."));

		item = curvesTree->root();
		item->label(prop->getName());
	} else {
		item = curvesTree->add(parent, prop->getName());
	}
	item->labelfont(FL_HELVETICA_BOLD);
	if (GroupProperty* g = dynamic_cast<GroupProperty*>(prop)) {
		if (g->getCollapsed()) {
			item->close();
		}
	} else if (dynamic_cast<RGBProperty*>(prop)) {
		item->close();
	}

	// Examine the list of properties.
	PropertyList* controls = prop->getProperties();
	for (PropertyList::iterator iter = controls->begin();
		 iter != controls->end();
		 iter++) {
        // For now, only RangeProperty is supported by the Curve interface.
		// The RGBProperty is also indirectly supported because it can provide
	    // RangeProperties when its getProperties() method is called.
		// TODO: make this work with more property types (using a new
		// plotting widget?)
		if (RangeProperty* range = dynamic_cast<RangeProperty*>(*iter)) {
			// TODO: connect to Curve object instead of Property object.
			Fl_Tree_Item* childNode = curvesTree->add(item, range->getName());
			curveProps.push_back(range);
			childNode->user_data((void*)(curveProps.size() - 1));
			range->setCurveIndex(curveProps.size() - 1);
			graph->addCurve(range->getValue(), range->getMin(),
				range->getMax());
		} else if ((*iter)->getProperties() != NULL) {
			// Try to get a list of GroupProperties out of it.
			populateCurveList(*iter, item);
		}
	}
}
Beispiel #12
0
Fl_Tree_Item *movebookmark(const char *name) {

	static Fl_Double_Window *bookmove_win=(Fl_Double_Window *)0;
	static Fl_Box *bookmove_lbl=(Fl_Box *)0;
	static Fl_Tree *bookmove_tree = NULL;

	if (!bookmove_win) {
		bookmove_win = new Fl_Double_Window(430, 330, _("Move to directory"));
		{ bookmove_lbl = new Fl_Box(17, 10, 395, 30, _("Moving \"\""));
		} // Fl_Box* bookmove_lbl
		{ bookmove_tree = new Fl_Tree(17, 40, 395, 240);
		} // Fl_Input* bookmove_tree
		{ Fl_Button *o = new Fl_Button(45, 290, 130, 30, _("OK"));
			o->callback(bookmoveok_cb);
		} // Fl_Button* o
		{ Fl_Button *o = new Fl_Button(250, 290, 130, 30, _("Cancel"));
			o->callback(bookmovecancel_cb);
		} // Fl_Button* o
		bookmove_win->end();
	} // Fl_Double_Window* bookmove_win

	bookmove_win->user_data(NULL);

	char tmp[320];
	snprintf(tmp, 320, "Moving \"%s\"", name);
	tmp[319] = '\0';

	g->v->listdirs(bookmove_tree);
	bookmove_lbl->copy_label(tmp);

	bookmove_win->show();

	while (bookmove_win->shown())
		Fl::wait();

	if (!bookmove_win->user_data())
		return NULL;

	Fl_Tree_Item *picked = bookmove_tree->first_selected_item();
	if (!picked)
		return NULL;
	return (Fl_Tree_Item *) picked->user_data();
}
Beispiel #13
0
static void scan_object(EdbusConnection *conn, EdbusMessage &msg, const char *service, const char *path, ObjectTree *self) {
	EdbusMessage reply;
	msg.create_method_call(service, path, INTROSPECTABLE_INTERFACE, INTROSPECTABLE_METHOD);

	if(!conn->send_with_reply_and_block(msg, 1000, reply)) {
		E_WARNING(E_STRLOC ": Did not get reply from service bus. Skipping introspection of '%s' service (object path: '%s')\n", service, path);
		return;
	}

	/* reply must be single element and string, which is xml */
	if(reply.size() != 1) {
		E_WARNING(E_STRLOC ": Expected only one element, but got '%i'\n", reply.size());
		return;
	}

	EdbusMessage::const_iterator it = reply.begin();
	if(!it->is_string()) {
		E_WARNING(E_STRLOC ": Expected string in reply, but got some junk\n");
		return;
	}

	TiXmlDocument doc;
	char buf[128];
	Fl_Tree_Item *titem;

	doc.Parse(it->to_string());
	TiXmlNode *el = doc.FirstChild("node");
	if(!el) return;

	for(el = el->FirstChildElement(); el; el = el->NextSibling()) {
		/* we have subobjects */
		if(STR_CMP_VALUE(el, "node")) {
			const char *name = el->ToElement()->Attribute("name");
			if(!name) {
				E_DEBUG(E_STRLOC ": <node> is expected to have 'name' attribute\n");
				continue;
			}

			/* TODO: maybe use EdbusObjectPath? */
			if(strcmp(path, "/") == 0)
				snprintf(buf, sizeof(buf), "/%s", name);
			else
				snprintf(buf, sizeof(buf), "%s/%s", path, name);

			titem = self->add(buf);
			self->close(titem);
			titem->usericon(&image_package);

			/* recurse */
			scan_object(conn, msg, service, buf, self);
		} else if(STR_CMP_VALUE(el, "interface")) {
			/* full interface: get methods and properties */
			const char *interface_name, *name = el->ToElement()->Attribute("name");
			/* remember it for Entity */
			interface_name = name;
			if(!name) {
				E_DEBUG(E_STRLOC ": <interface> is expected to have 'name' attribute\n");
				continue;
			}

			/* append interface to tree */
			snprintf(buf, sizeof(buf), "%s/%s", path, name);
			titem = self->add(buf);
			self->close(titem);
			titem->usericon(&image_interface);

			/* append methods, signals and properties */
			TiXmlNode *sel;
			char buf2[256];
			Fl_Pixmap *icon;
			EntityType et;

			for(sel = el->FirstChildElement(); sel; sel = sel->NextSibling()) {
				if(STR_CMP_VALUE(sel, "method")) {
					icon = &image_method;
					et = ENTITY_METHOD;
				} else if(STR_CMP_VALUE(sel, "signal")) {
					icon = &image_signal;
					et = ENTITY_SIGNAL;
				} else if(STR_CMP_VALUE(sel, "property")) {
					icon = &image_property;
					et = ENTITY_PROPERTY;
				} else {
					E_WARNING(E_STRLOC ": Got unknown node '%s'. Skipping...\n", sel->Value());
					continue;
				}

				/* everything else are common elements between different types */
				name = sel->ToElement()->Attribute("name");
				snprintf(buf2, sizeof(buf2), "%s/%s", buf, name);
				titem = self->add(buf2);
				titem->usericon(icon);
				self->close(titem);

				/* fill our metadata */
				Entity *en = new Entity();
				en->set_type(et);
				en->set_name(name);
				en->set_interface(interface_name);
				en->set_path(path);

				/* TODO: this doesn't have to be copied */
				en->set_service(service);

				if(et == ENTITY_PROPERTY) {
					const char *argstype, *argsname, *argsaccess;
					argstype = sel->ToElement()->Attribute("type");
					argsname = sel->ToElement()->Attribute("name");
					argsaccess = sel->ToElement()->Attribute("access");

					en->append_arg(argsname, argstype, DIRECTION_NONE, argsaccess);
				} else {
					TiXmlNode *argsnode;
					for(argsnode = sel->FirstChildElement(); argsnode; argsnode = argsnode->NextSibling()) {
						if(STR_CMP_VALUE(argsnode, "arg")) {
							/* arguments */
							const char *argstype, *argsname, *argsdirection;
							ArgDirection dir = DIRECTION_NONE;

							argstype = argsnode->ToElement()->Attribute("type");
							if(!argstype) continue;

							argsname = argsnode->ToElement()->Attribute("name");
							if(!argsname) continue;

							/* it is fine to not have direction, which means it is only a method */
							argsdirection = argsnode->ToElement()->Attribute("direction");
							if(argsdirection) {
								if(STR_CMP(argsdirection, "in"))
									dir = DIRECTION_IN;
								else if(STR_CMP(argsdirection, "out"))
									dir = DIRECTION_OUT;
							}

							en->append_arg(argsname, argstype, dir);
						} else if(STR_CMP_VALUE(argsnode, "annotation")) {
							const char *annoname, *argsval;

							annoname = argsnode->ToElement()->Attribute("name");
							/* allow whatever annotation name ending with '.DocString' to be supported (e.g. org.gtk.GDBus.DocString or org.equinoxproject.DBus.DocString) */
							if(!str_ends(annoname, ".DocString")) {
								E_WARNING(E_STRLOC ": We are supporting now only DocString annotations. Skipping '%s'...\n", annoname);
								continue;
							}

							argsval = argsnode->ToElement()->Attribute("value");
							if(argsval) en->set_doc(argsval);
						}
					}
				}

				/* put it inside our tree so we can manage it */
				self->append_entity(en);
				/* add also inside Fl_Tree_Item */
				titem->user_data(en);
			}
		}
	}
}
Beispiel #14
0
int ResourceWindow::handle( int event )
{
	int ret = Fl_Group::handle(event);
	std::string dndText;
	switch ( event ) {
		case FL_DND_RELEASE:
			//LOG("DND Release");
			ret = 1;
			break;
		case FL_DND_ENTER:          // return(1) for these events to 'accept' dnd
			//LOG("DND Enter");
			//Fl::belowmouse(this); // send the leave events first
			//Fl::focus(this);
			//handle(FL_FOCUS);		
			ret = 1;
			break;
		case FL_DND_DRAG:			
			ret = 1;
			break;
		case FL_DND_LEAVE:
			//LOG("DND Leave");
			ret = 1;
			break;	  
		case FL_PASTE:              // handle actual drop (paste) operation		   
			{
				//label(Fl::event_text());
				//fprintf(stderr, "PASTE: %s\n", Fl::event_text());
				//LOG("PASTE: %s\n", Fl::event_text());
				dndText = Fl::event_text();
				bool hasAsset = processedDragAndDrop(dndText);
				ret = 1;				
			}
			break;	
		case FL_PUSH:  
		{// do 'copy/dnd' when someone clicks on box
			if (Fl::event_button() == 2)
			{
				LOG("press middle button");
				LOG("lastClickedItemPath = %s",lastClickedItemPath.c_str());
				Fl_Tree_Item* lastItem = resourceTree->find_item(lastClickedItemPath.c_str());	
				if (lastItem)
				{
					const char* itemType = (const char*)lastItem->user_data();
					bool sendDND = false;
					std::string dndMsg = "";
					if (strcmp(itemType, "skeleton") == 0)
					{
						std::string skName = lastItem->label();
						dndMsg = "SKELETON:";
						dndMsg += skName;
						sendDND = true;
					}
					else if (strcmp(itemType, "pawn") == 0)
					{
						dndMsg = "PAWN:dummy";
						sendDND = true;
					}
					
					//Fl::copy("message",7,0);
					if (sendDND)
					{
						Fl::copy(dndMsg.c_str(),dndMsg.length(),0);
						Fl::dnd();
					}					
					ret = 1;
				}			
			}			
			break;
		}
		case FL_KEYDOWN:  
		{
		  switch (Fl::event_key())
		  {
			case FL_Delete:
				{
					// check pawns and characters for selection
					Fl_Tree_Item* tree = getTreeFromName("pawn");
					int numChildren = tree->children();
					for (int c = 0; c < numChildren; c++)
					{
						Fl_Tree_Item* child = tree->child(c);
						if (child->is_selected())
						{
							const char* name = child->label();
							int confirm = fl_choice(vhcl::Format("Are you sure you want to delete '%s'?",name).c_str(), "No", "Yes", NULL);
							if (confirm == 0)
								return 0;
							SmartBody::SBScene::getScene()->removePawn(name);
							updateGUI();
							return 1;
						}
					}

					tree = getTreeFromName("character");
					numChildren = tree->children();
					for (int c = 0; c < numChildren; c++)
					{
						Fl_Tree_Item* child = tree->child(c);
						if (child->is_selected())
						{
							const char* name = child->label();
							int confirm = fl_choice(vhcl::Format("Are you sure you want to delete '%s'?",name).c_str(), "No", "Yes", NULL);
							if (confirm == 0)
								return 0;
							SmartBody::SBScene::getScene()->removeCharacter(name);
							updateGUI();
							return 1;
						}
					}
				
				}
				break;
			default:
				break;
		  }
		}
	}
	return ret;
}