Example #1
0
bool xmlgui::Gui::loadFromXml(string file) {
    if(root!=NULL) {
        removeChild(root);
        delete root;
        root = NULL;
    }

    if(file=="") file = fileName;
    else fileName = file;

    TiXmlDocument doc(ofToDataPath(file));
    if(!doc.LoadFile()) return false;
    TiXmlElement* rootElement = doc.FirstChildElement()->ToElement();

    // find out what the root tag is
    string firstTagName = rootElement->Value();


    root = (Container*)INSTANTIATE(firstTagName);



    // this should recurse, calling createControl as it goes.
    root->loadFromXmlObject(rootElement);

    addChild(root);
    setup(root);
    return true;
}
Example #2
0
xmlgui::Control *xmlgui::Control::clone() {

	Control *c = INSTANTIATE(type);

	c->name = name;
	c->id = id;
	c->x = x;
	c->y = y;
	c->width = width;
	c->height = height;


	// parentInfo and parameterInfo will be identical except
	// for the pointers

	vector<ParameterInfo> parameterInfo;
	c->getParameterInfo(parameterInfo);


	vector<ParameterInfo> parentInfo;
	getParameterInfo(parentInfo);

	// this is the parameter info for the cloned control
	for(int i = 0; i < parameterInfo.size(); i++) {

		// this writer writes to the pointer pointing into the
		// attribute of the cloned control
		Control *writer = INSTANTIATE(parameterInfo[i].type);
		writer->pointToValue(parameterInfo[i].value);


		Control *reader = INSTANTIATE(parentInfo[i].type);
		reader->pointToValue(parentInfo[i].value);

		writer->valueFromString(reader->valueToString());
		delete reader;
		delete writer;
	}
	c->load();
	return c;
}
Example #3
0
void gui::Editor::controlChanged(Control *c) {
	string n = c->id.c_str();
	if(n.find("new ")==0) {
		string ctrlType = n.substr(4);
		Control *ctrl = INSTANTIATE(ctrlType);
		ctrl->x = 100;
		ctrl->y = 100;
		Control *con = root->getControlById("root");
		if(con!=NULL) {
			((Container*)con)->addChild(ctrl);
		} else {
			root->addChild(ctrl);
		}
		
	} else if(n=="Save") {
		root->saveToXml("gui.xml");
	} else if(n=="Save As...") {
		ofFileDialogResult result = ofSystemSaveDialog("default.xml", "Save As...");
		if(result.bSuccess) {
			root->saveToXml(result.filePath);
		}
		
	} else if(n=="Delete") {
		
		if(focusedControl != NULL && focusedControl->parent!=NULL) {
			focusedControl->parent->removeChild(focusedControl);
			if(focusedControl==rolledOverControl) {
				rolledOverControl = NULL;
			}
			
			// let the inspector know we're deleting a control in case
			// its gui is pointing to it.
			inspector.setControl(NULL);
			delete focusedControl;
			focusedControl = NULL;
		}
	} else if(n=="Duplicate") {
		if(focusedControl != NULL && focusedControl->parent!=NULL) {
			Control *newControl = focusedControl->clone();
			newControl->x += 10;
			newControl->y += 10;
			newControl->id += "1";
			focusedControl->parent->addChild(newControl);
			focusedControl = newControl;
		}
	}
}
/*
void gui::Editor::setupInspector() {
	inspector = new Inspector();
	addChild(inspector);
}*/
void xmlgui::Editor::setupMenus() {
	menuBar = (MenuBar*)INSTANTIATE("menubar");

	menuBar->addMenu("File");
	menuBar->addItem("File", "Save");
	menuBar->addItem("File", "Save As...");
	menuBar->addMenu("Edit");
	//menuBar->addItem("Edit", "Duplicate");
	menuBar->addItem("Edit", "Delete");
	menuBar->addItem("Edit", "Duplicate");

	menuBar->addMenu("Create");

	for(int i = 0; i < Instantiator::getInstance()->size(); i++) {
		menuBar->addItem("Create", string("new ") + Instantiator::getInstance()->at(i));
	}


	addChild(menuBar);
}
Example #5
0
void xmlgui::Container::loadFromXmlObject(TiXmlElement *xml) {
	Control::loadFromXmlObject(xml);

	const char *_bgImageUrl = xml->Attribute("bgImage");
	if(_bgImageUrl!=NULL) {
		printf("Loading image\n");
		bgImageUrl = _bgImageUrl;
		bgImage = xmlgui::Resources::getImage(bgImageUrl);
		if(bgImage==NULL) printf("Image couldn't be loaded\n");
	}
	// now we've loaded this container, load the children
	TiXmlNode *childNode = xml->FirstChild();
	if(childNode!=NULL) {
		TiXmlElement *child = childNode->ToElement();
		for(child; child; child = child->NextSiblingElement()) {
			string tagName = child->ValueStr();
			Control *ctrl = INSTANTIATE(tagName);
			ctrl->loadFromXmlObject(child);
			addChild(ctrl);
		}
	}
}
void xmlgui::Editor::controlChanged(Event *e) {
	string n = e->control->id.c_str();
	if(n.find("new ")==0) {
		string ctrlType = n.substr(4);
		Control *ctrl = INSTANTIATE(ctrlType);
		ctrl->x = 100;
		ctrl->y = 100;
		Control *con = root->getRoot();
		if(con!=NULL) {
			((Container*)con)->addChild(ctrl);
		} else {
			root->addChild(ctrl);
		}

	} else if(n=="Save") {
		root->getRoot()->saveToXml("gui.xml");
	} else if(n=="Save As...") {
		ofFileDialogResult result = ofSystemSaveDialog("default.xml", "Save As...");
		if(result.bSuccess) {
			root->getRoot()->saveToXml(result.filePath);
		}

	} else if(n=="Delete") {

		deleteFocusedControl();


	} else if(n=="Duplicate") {
		if(focusedControl != NULL && focusedControl->parent!=NULL) {
			Control *newControl = focusedControl->clone();
			newControl->x += 10;
			newControl->y += 10;
			newControl->id += "1";
			focusedControl->parent->addChild(newControl);
			focusedControl = newControl;
		}
	}
}
Example #7
0
void xmlgui::Control::saveToXmlObject(ofxXmlSettings &xml) {

	// create tag,
	xml.addTag(type);

	// know which tag we are in case there's multiples
	int which = xml.getNumTags(type) - 1;
	xml.addAttribute(type, "name", name, which);
	xml.addAttribute(type, "id", id, which);
	xml.addAttribute(type, "x", x, which);
	xml.addAttribute(type, "y", y, which);
	xml.addAttribute(type, "width", width, which);
	xml.addAttribute(type, "height", height, which);

	vector<ParameterInfo> parameterInfo;
	getParameterInfo(parameterInfo);
	for(int i = 0; i < parameterInfo.size(); i++) {
		Control *c = INSTANTIATE(parameterInfo[i].type);
		c->pointToValue(parameterInfo[i].value);
		xml.addAttribute(type, parameterInfo[i].xmlName, c->valueToString(), which);
		delete c;
	}
}
Example #8
0
void xmlgui::Control::loadFromXmlObject(TiXmlElement *xml) {
	
	// take all the base settings from this element
	name = xml->Attribute("name");
	id = xml->Attribute("id");
	xml->QueryFloatAttribute("x", &x);
	xml->QueryFloatAttribute("y", &y);
	xml->QueryFloatAttribute("width", &width);
	xml->QueryFloatAttribute("height", &height);
	// then take all the "parameterinfo" from it
	
	vector<ParameterInfo> parameterInfo;
	getParameterInfo(parameterInfo);
	for(int i = 0; i < parameterInfo.size(); i++) {
		Control *c = INSTANTIATE(parameterInfo[i].type);
		c->pointToValue(parameterInfo[i].value);
		c->valueFromString(string(xml->Attribute(parameterInfo[i].xmlName.c_str())));
		delete c;
	}
	
	load();

}
Example #9
0
void xmlgui::Control::loadFromXmlObject(TiXmlElement *xml) {

	// take all the base settings from this element
	name = xml->Attribute("name");
	id = xml->Attribute("id");
	xml->QueryFloatAttribute("x", &x);
	xml->QueryFloatAttribute("y", &y);
	xml->QueryFloatAttribute("width", &width);
	xml->QueryFloatAttribute("height", &height);
	// then take all the "parameterinfo" from it

	vector<ParameterInfo> parameterInfo;
	getParameterInfo(parameterInfo);

	//printf("Got %d params in %s\n", parameterInfo.size(), name.c_str());
	for(int i = 0; i < parameterInfo.size(); i++) {
		//printf("Param: %s\n", parameterInfo[i].name.c_str());
		//printf("Type: %s\n", parameterInfo[i].type.c_str());
		Control *c = INSTANTIATE(parameterInfo[i].type);
		c->pointToValue(parameterInfo[i].value);


		const char *vv = xml->Attribute(parameterInfo[i].xmlName.c_str());
		if(vv!=NULL) {
			string val = string(vv);
//			printf("val: %s\n", val.c_str());
			c->valueFromString(string(xml->Attribute(parameterInfo[i].xmlName.c_str())));
		} else {
			ofLogError() <<"No default value for "<<parameterInfo[i].name<<" in "<<name;
		}
		delete c;
	}

	load();

}
    // MoblizedBodyImpl::createRigidBodyNode() definitions //
    /////////////////////////////////////////////////////////


// These probably don't belong here.

#include "MobilizedBodyImpl.h"

RigidBodyNode* MobilizedBody::PinImpl::createRigidBodyNode(
    UIndex&        nextUSlot,
    USquaredIndex& nextUSqSlot,
    QIndex&        nextQSlot) const
{
    INSTANTIATE(RBNodeTorsion,
        getDefaultRigidBodyMassProperties(),
        getDefaultInboardFrame(),getDefaultOutboardFrame(),
        isReversed(),
        nextUSlot,nextUSqSlot,nextQSlot)
}


RigidBodyNode* MobilizedBody::SliderImpl::createRigidBodyNode(
    UIndex&        nextUSlot,
    USquaredIndex& nextUSqSlot,
    QIndex&        nextQSlot) const
{
    INSTANTIATE(RBNodeSlider,
        getDefaultRigidBodyMassProperties(),
        getDefaultInboardFrame(),getDefaultOutboardFrame(),
        isReversed(),
        nextUSlot,nextUSqSlot,nextQSlot)