void onRead() { XmlTree doc(loadFile(getHomeDirectory()+std::string("\\temp.xml"))); Vec2f pp[4]; int n = 0; for (XmlTree::Iter it = doc.begin("pos/frame/frame"); it != doc.end(); ++it) { app::console() << it->getValue() << std::endl; sscanf(it->getValue().c_str(), "%f %f", &pp[n].x, &pp[n].y); ++n; } distpoints[0][0][0] = pp[0].x; distpoints[0][0][1] = pp[0].y; distpoints[0][1][0] = pp[1].x; distpoints[0][1][1] = pp[1].y; distpoints[1][0][0] = pp[2].x; distpoints[1][0][1] = pp[2].y; distpoints[1][1][0] = pp[3].x; distpoints[1][1][1] = pp[3].y; n = 0; for (XmlTree::Iter it = doc.begin("pos/mag/mag"); it != doc.end(); ++it) { sscanf(it->getValue().c_str(), "%f %f", &mCtrlPoints[n].mag.x, &mCtrlPoints[n].mag.y); ++n; } }
void PlistReader::trace(XmlTree t){ for( XmlTree::Iter child = t.begin(); child != t.end(); ++child ){ console() << "Tag: " << child->getTag() << " Value: " << child->getValue() << endl; if(child->getTag().compare("dict")==0){ trace(*child); } } }
void DataManager::parseData( XmlTree d ){ XmlTree data = d.getChild( "QLT_Genome_Data" ); string dataPath = data.getChild( "datapath" ).getValue(); XmlTree sets = data.getChild( "datasets"); for( XmlTree::Iter dataset = sets.begin(); dataset != sets.end(); ++dataset ){ GenomeDataStructure gds; gds.id = dataset->getAttributeValue<int>("id"); gds.name = dataset->getChild("title").getValue(); gds.pathMap = dataPath+dataset->getChild("map").getValue(); gds.pathBases = dataPath+dataset->getChild("bases").getValue(); mDataStructure.push_back( gds ); console() << " GenomeDataStructure : " << gds.name << " " << gds.pathMap << " " << gds.pathBases << std::endl; } }
void XMLTestApp::setup() { XmlTree doc( loadFile( getAssetPath( "library.xml" ) ) ); XmlTree musicLibrary( doc.getChild( "library" ) ); for( XmlTree::ConstIter item = doc.begin("library/album"); item != doc.end(); ++item ) { console() << "Node: " << item->getTag() << " Value: " << item->getValue() << endl; } for( XmlTree::ConstIter track = doc.begin("library/album/track"); track != doc.end(); ++track ) console() << track->getValue() << endl; assert( (musicLibrary / "album")["musician"] == "John Coltrane" ); // test that /one/two is equivalent to one/two vector<string> noLeadingSeparator, leadingSeparator; for( XmlTree::ConstIter track = doc.begin("library/album/track"); track != doc.end(); ++track ) noLeadingSeparator.push_back( track->getValue() ); for( XmlTree::ConstIter track = doc.begin("/library/album/track"); track != doc.end(); ++track ) leadingSeparator.push_back( track->getValue() ); assert( noLeadingSeparator == leadingSeparator ); XmlTree firstAlbum = doc.getChild( "library/album" ); for( XmlTree::Iter child = firstAlbum.begin(); child != firstAlbum.end(); ++child ) { console() << "Tag: " << child->getTag() << " Value: " << child->getValue() << endl; } console() << doc.getChild( "library/owner/city" ); XmlTree ownerCity = doc.getChild( "///library/////owner/city" ); console() << "Path: " << ownerCity.getPath() << " Value: " << ownerCity.getValue() << std::endl; console() << doc; console() << findTrackNamed( doc.getChild( "library" ), "Wolf" ); // Whoops - assignment by value doesn't modifying the original XmlTree XmlTree firstTrackCopy = doc.getChild( "/library/album/track" ); firstTrackCopy.setValue( "Replacement name" ); console() << doc.getChild( "/library/album/track" ) << std::endl; XmlTree &firstTrackRef = doc.getChild( "/library/album/track" ); firstTrackRef.setValue( "Replacement name" ); console() << doc.getChild( "/library/album/track" ) << std::endl; XmlTree albumCopy = copyFirstAlbum( doc / "library" ); console() << ( albumCopy / "track" ).getPath() << std::endl; // should print 'newRoot/track' // This code only works in VC2010 /* std::for_each( doc.begin( "library/album" ), doc.end(), []( const XmlTree &child ) { app::console() << child.getChild( "title" ).getValue() << std::endl; } );*/ }
UserArea::UserArea(XmlTree area, PhidgetConnector *pc_) { // okay so if theres attributes aren't here, it bugs out it would seem? pos = Vec2f(area.getAttributeValue<float>( "centerX" ), area.getAttributeValue<float>( "centerY" )); angle = area.getAttributeValue<float>( "angle" ); key = area.getAttributeValue<char>( "key" ); // this should be loading from the XML. background = "area_background.png"; // there is some serious abstracting to be done here string activeArea_str = "active_area.png"; bg_img.load(background); activeArea_img.load(activeArea_str); // really, still? hmmm // mTexture = gl::Texture( loadImage( loadResource( background ) ) ); vector<string> videos; for( XmlTree::Iter child = area.begin(); child != area.end(); ++child) { if ( child->getTag() == "video" ) videos.push_back(child->getValue()); else if ( child->getTag() == "button" ) { XmlTree b = *child; //buttons.push_back(Button::Button(b/*, &UserArea::nextMovie*/)); buttons.push_back(TwoStateButton(b)); buttonStates.push_back(false); // void (UserArea::*func)() = &UserArea::nextMovie; /* void (*func)() = &printTest; func(); */ } } player = VideoPlayer ( Rectf(0, 0, 640, 480), videos); frameCount = rand() % 628; pc = pc_; }
void License::init( XmlTree &doc ) { if( doc.hasChild( "License" )) { XmlTree xmlLicense = doc.getChild( "License" ); string product = xmlLicense.getAttributeValue<string>( "Product", "" ); string key = xmlLicense.getAttributeValue<string>( "Key" , "" ); setProduct( product ); setKeyPath( getAssetPath( key )); for( XmlTree::Iter child = xmlLicense.begin(); child != xmlLicense.end(); ++child ) { if( child->getTag() == "Server" ) { string server = child->getAttributeValue<string>( "Name" ); addServer( server ); } } } }
TwoStateButton::TwoStateButton(XmlTree xml) { pos.x = xml.getAttributeValue<float>( "posX" ); pos.y = xml.getAttributeValue<float>( "posY" ); float angle = xml.getAttributeValue<float>( "angle" ); device = xml.getAttributeValue<int>( "device" ); sensor = xml.getAttributeValue<int>( "sensor" ); for( XmlTree::Iter img = xml.begin(); img != xml.end(); ++img) { if (img->getAttributeValue<string>( "id" ) == "active") { active = Image(img->getValue(), pos); } else if (img->getAttributeValue<string>( "id" ) == "inactive") { inactive = Image(img->getValue(), pos); } } active.setRotation(angle); inactive.setRotation(angle); }
bool BookAR::readAppConfig( const string& appXml ) { vector<string> mdl_files; vector<string> thumb_files; try { XmlTree doc(loadFile(appXml)); XmlTree firstConfig = doc.getChild("SDARConfig"); for( XmlTree::Iter item = firstConfig.begin(); item != firstConfig.end(); ++item ) { //key string name = item->getAttribute("name"); string thumb = item->getAttribute("thumb"); mdl_files.push_back(name); thumb_files.push_back(thumb); } } catch( ... ) { console() << "[ERROR] Failed to readAppConfig from " << appXml<<std::endl; return false; } _ar_tracker->setup(CAM_W, CAM_H, 10, 1000, static_cast<void*>(&mdl_files)); //thumbs int thumb_x = THUMB_X0; for (int i=0;i<thumb_files.size();i++) { Surface thumb_img = loadImage(getAppPath().generic_string()+thumb_files[i]); float ratio = thumb_img.getAspectRatio(); int thumb_w = static_cast<int>(THUMB_H*ratio); _thumbs.push_back(shared_ptr<UIElement>(new UIElement(THUMB_BASE + i, thumb_x, THUMB_Y0, thumb_w, THUMB_H, thumb_img))); thumb_x += thumb_w+THUMB_SPAC; } return true; }
void FlickrImageViewerApp::update() { // instead of in setup(), I download the feed here so it doesn't take so long for our window to show up if(mUrls.empty()) { // connect to Flickr and load a set of images. To view your own set, // find the "RSS feed" link on the Flickr page and copy the url. XmlTree doc( loadUrl("http://api.flickr.com/services/feeds/photoset.gne?set=726262&nsid=14684343@N00") ); XmlTree::Iter itr = doc.begin("feed/entry/link"); while(itr!=doc.end()) { // check if link contains an image (type == 'image/jpeg') if(itr->getAttributeValue<string>("type") == "image/jpeg") { // retrieve and store url if( itr->hasAttribute("href") ) mUrls.push_back( itr->getAttributeValue<string>("href") ); } ++itr; } // make sure we actually have something to show if(mUrls.empty()) return; } // calculate elapsed time in seconds (since last swap) double elapsed = ( getElapsedSeconds() - mTimeSwapped ); // if there is no front image yet, load it right away if(!mFront) { if(mAsynchronous) { // load the texture asynchronously using the TextureManager. The call // will return an empty texture if not ready yet. mFront = ph::fetchTexture( mUrls[mIndex] ); } else { // load the texture synchronously using the TextureManager. The call // will load and return the texture, but your application will have // to wait for it to finish. Returns empty texture if load did not succeed. mFront = ph::loadTexture( mUrls[mIndex] ); } // if texture was loaded... if(mFront) { // start fading in mTimeSwapped = getElapsedSeconds(); // proceed to next texture mIndex = (mIndex + 1) % mUrls.size(); } } else if(elapsed > mTimeFade) { if(mAsynchronous) { // as soon as the front image has been faded in, // start loading the back image asynchronously using the TextureManager. // The call will return an empty texture while not ready yet. mBack = ph::fetchTexture( mUrls[mIndex] ); } else { // load the texture synchronously using the TextureManager. The call // will load and return the texture, but your application will have // to wait for it to finish. Returns empty texture if load did not succeed. mBack = ph::loadTexture( mUrls[mIndex] ); } // if texture has been loaded and enough time has passed... if(mBack && elapsed > (mTimeFade + mTimeView)) { // swap the two textures gl::Texture temp = mFront; mFront = mBack; mBack = temp; // keep track of how long the previous image was shown, // so there will be no visual indication that we swapped the images mTimeDuration = elapsed; // start fading in mTimeSwapped = getElapsedSeconds(); // proceed to next texture mIndex = (mIndex + 1) % mUrls.size(); } } }
void Level::loadLevelFromFile(string pathToLevel) { // root id = pathToLevel; string realPath = "levels/" + pathToLevel; realPath = getAssetPath(realPath).string(); XmlTree doc((loadFile(realPath))); XmlTree root = doc.getChild("level"); // width + height width = root.getChild("width").getValue<int>(); height = root.getChild("height").getValue<int>(); Map.resize(width, vector<int>(height, -1)); // hero start position int hx = root.getChild("heroX").getValue<int>(); int hy = root.getChild("heroY").getValue<int>(); hero.position.set(hx * TILESIZE, hy * TILESIZE); // antenna int ax = root.getChild("antennaX").getValue<int>(); int ay = root.getChild("antennaY").getValue<int>(); antennaPosition.set(ax * TILESIZE, ay * TILESIZE); // level-data stringstream stream; stream << root.getChild("data").getValue(); int index = 0; while (stream.good() && index < width * height) { int tileId; stream >> tileId; setTileAtPosition(index, tileId); index++; } // attractors if (root.hasChild("attractors")) { XmlTree firstAttractor = root.getChild("attractors"); for (XmlTree::Iter child = firstAttractor.begin(); child != firstAttractor.end(); child++) { float x = child->getChild("x").getValue<float>(); float y = child->getChild("y").getValue<float>(); Attractor* attractor = new Attractor(x, y); attractor->autoConnectTime = child->getChild("autoConnectTime").getValue<float>(attractor->autoConnectTime); attractor->autoDisconnectTime = child->getChild("autoDisconnectTime").getValue<float>(); attractor->autoConnectRadius = child->getChild("autoConnectRadius").getValue<float>(); attractor->connectTimeout = child->getChild("connectTimeout").getValue<float>(); attractor->attractForce = child->getChild("attractForce").getValue<float>(attractor->attractForce); attractor->maxAttractForce = child->getChild("maxAttractForce").getValue<float>(attractor->maxAttractForce); addConnector(attractor); } } // detractors if (root.hasChild("detractors")) { XmlTree firstDetractor = root.getChild("detractors"); for (XmlTree::Iter child = firstDetractor.begin(); child != firstDetractor.end(); child++) { float x = child->getChild("x").getValue<float>(); float y = child->getChild("y").getValue<float>(); Detractor* detractor = new Detractor(x, y); detractor->autoConnectTime = child->getChild("autoConnectTime").getValue<float>(detractor->autoConnectTime); detractor->autoDisconnectTime = child->getChild("autoDisconnectTime").getValue<float>(); detractor->autoConnectRadius = child->getChild("autoConnectRadius").getValue<float>(); detractor->connectTimeout = child->getChild("connectTimeout").getValue<float>(); detractor->bounceForce = child->getChild("bounceForce").getValue<float>(detractor->bounceForce); detractor->maxBounceForce = child->getChild("maxBounceForce").getValue<float>(detractor->maxBounceForce); addConnector(detractor); } } }
void AppModel::parseSettings(XmlTree _root){ XmlTree t = _root.getChild("dict"); // is key background? // load background // is key user areas? // loop children // create userareamodel // set x, y, r // is it a button? UserAreaModel uam; TouchSensorModel tsm; string topLevelKey = ""; for( XmlTree::Iter child = t.begin(); child != t.end(); ++child ){ string tagType = child->getTag(); console() << "tag: " << tagType << endl; if(tagType.compare("key")==0){ topLevelKey = child->getValue(); console() << "topkey: " << topLevelKey << endl; } else { if(tagType.compare("string")==0 || tagType.compare("false")==0 || tagType.compare("true")==0){ if(topLevelKey.compare("background")==0){ backgroundPath = child->getValue(); } else if(topLevelKey.compare("button")==0){ console() << "Button Value::: " << tagType << "!!!!!" << endl; buttonPath = child->getValue(); } else if(topLevelKey.compare("fullscreen")==0){ console() << "FULLSCREEN VALUE:::: " << tagType << "!!!!!!!!!" << endl; if(tagType.compare("true")==0) isFullScreen = true; } } else if(tagType.compare("dict")==0){ // this is either the user areas, or the sensor boards // depending on the toplevelkey XmlTree t2 = *child; string midLevelKey = ""; for( XmlTree::Iter grandchild = t2.begin(); grandchild != t2.end(); ++grandchild ){ console() << grandchild->getTag() << " ::: " << grandchild->getValue() << endl; string gcTagType = grandchild->getTag(); if(gcTagType.compare("key")==0){ midLevelKey = grandchild->getValue(); } else { console() << "GRANCHILDLEVEL: " << grandchild->getValue() << " : " << midLevelKey << ", " << topLevelKey << endl; if(topLevelKey.compare("User Areas")==0){ uam = UserAreaModel(); } else if(topLevelKey.compare("Sensor Boards")==0){ tsm = TouchSensorModel(); } // this should always be a dict (either a list of nums and strings for user areas, or nums for sensor boards) XmlTree t3 = *grandchild; string bottomLevelKey = ""; for( XmlTree::Iter baby = t3.begin(); baby != t3.end(); ++baby ){ string babyTag = baby->getTag(); if(babyTag.compare("key")==0){ bottomLevelKey = baby->getValue(); } else if(babyTag.compare("dict")!=0){ // console() << "BABY LEVEL: " << baby->getValue() << " : " << bottomLevelKey << " : " << midLevelKey << ", " << topLevelKey << endl; if(topLevelKey.compare("User Areas")==0){ if(bottomLevelKey.compare("x")==0){ uam.x = atof(baby->getValue().c_str()); } else if(bottomLevelKey.compare("y")==0){ uam.y = atof(baby->getValue().c_str()); } else if(bottomLevelKey.compare("r")==0){ uam.r = atof(baby->getValue().c_str()); }else if(bottomLevelKey.compare("recipe")==0){ uam.recipe = baby->getValue(); } } else if(topLevelKey.compare("Sensor Boards")==0) { tsm.sensor = atoi(baby->getValue().c_str()); tsm.keymap = bottomLevelKey[0]; tsm.board = atoi(midLevelKey.c_str()); sensors.push_back(tsm); } } else { if(topLevelKey.compare("User Areas")==0){ uam.name = midLevelKey; } XmlTree t4 = *baby; string easyModeKey = ""; for( XmlTree::Iter zygote = t4.begin(); zygote != t4.end(); ++zygote ){ string zygoteTag = zygote->getTag(); if(zygoteTag.compare("key")==0){ easyModeKey = zygote->getValue(); } else { // console() << "ZYGOTE LEVEL: " << zygote->getValue() << ": " << easyModeKey << " : " << bottomLevelKey << " : " << midLevelKey << ", " << topLevelKey << endl; } } } } if(topLevelKey.compare("User Areas")==0){ areas.push_back(uam); } } } } } } }
void AppModel::parseRecipes(XmlTree _root){ XmlTree t = _root.getChild("dict/dict"); for( XmlTree::Iter child = t.begin(); child != t.end(); ++child ){ if(child->getTag().compare("key")==0){ // use this value as the name for a new Recipe object RecipeModel rm; rm.name = child->getValue(); recipes.push_back(rm); } else { XmlTree t2 = *child; string whichKey; for( XmlTree::Iter grandchild = t2.begin(); grandchild != t2.end(); ++grandchild ){ if(grandchild->getTag().compare("key")==0){ whichKey = grandchild->getValue(); } else if(grandchild->getTag().compare("dict")==0){ if(whichKey.compare("Steps")==0){ XmlTree t3 = *grandchild; CookStepModel sm; for( XmlTree::Iter greatChild = t3.begin(); greatChild != t3.end(); ++greatChild ){ XmlTree t4 = *greatChild; string stepKey; if(greatChild->getTag().compare("dict")==0){ for( XmlTree::Iter baby = t4.begin(); baby != t4.end(); ++baby ){ if(baby->getTag().compare("key")==0){ stepKey = baby->getValue(); } else { if(stepKey.compare("img")==0){ sm.img = baby->getValue(); } else if(stepKey.compare("video")==0){ sm.video = baby->getValue(); } else { console() << "I got a property of a cookstep that was unexpected: " << stepKey << ", " << baby->getValue(); } } } } else if(greatChild->getTag().compare("key")==0){ if(recipes.size()>0 && sm.name.compare("")!=0){ recipes.at(recipes.size()-1).steps.push_back(sm); } sm.name = sm.video = sm.img = ""; sm.name = greatChild->getValue(); } } if(sm.name.compare("")!=0){ recipes.at(recipes.size()-1).steps.push_back(sm); } } } else { // do nothing? } } } } }
void PlistReader::parseRecipes(){ XmlTree t = root.getChild("dict/dict"); for( XmlTree::Iter child = t.begin(); child != t.end(); ++child ){ console() << "Tag: " << child->getTag() << " Value: " << child->getValue() << endl; if(child->getTag().compare("key")==0){ // use this value as the name for a new Recipe object RecipeModel rm; rm.name = child->getValue(); recipeModels.push_back(rm); } else { console() << "check it out, this is probably a dict:::: " << child->getTag() << "." << endl; XmlTree t2 = *child; string whichKey; for( XmlTree::Iter grandchild = t2.begin(); grandchild != t2.end(); ++grandchild ){ console() << "\t Tag: " << grandchild->getTag() << " Value: " << grandchild->getValue() << endl; if(grandchild->getTag().compare("key")==0){ // its a key yo whichKey = grandchild->getValue(); console() << "\t\t right after, whichkey is: " << whichKey << endl; } else if(grandchild->getTag().compare("dict")==0){ // surely these are Steps?? if(whichKey.compare("Steps")==0){ console() << " I FOUND A DICT AND LO AND BEHOLD its a Steps child... "<< grandchild->getValue() << endl; // it must be time to dig through these bloomin STEPS. // loop through em. XmlTree t3 = *grandchild; StepModel sm; for( XmlTree::Iter greatChild = t3.begin(); greatChild != t3.end(); ++greatChild ){ XmlTree t4 = *greatChild; string stepKey; if(greatChild->getTag().compare("dict")==0){ for( XmlTree::Iter baby = t4.begin(); baby != t4.end(); ++baby ){ if(baby->getTag().compare("key")==0){ stepKey = baby->getValue(); } else { // then its likely a value console() << "\t\t\t\t\t\t\t\t " << stepKey << " Value: " << baby->getValue() << endl; if(stepKey.compare("start-image")==0){ sm.start_img = baby->getValue(); } else if(stepKey.compare("name")==0){ sm.name = baby->getValue(); } else if(stepKey.compare("video")==0){ sm.video = baby->getValue(); } else { console() << "I got a property of a cookstep that was unexpected: " << stepKey << ", " << baby->getValue(); } } } } else if(greatChild->getTag().compare("key")==0){ if(recipeModels.size()>0 && sm.name.compare("")!=0){ recipeModels.at(recipeModels.size()-1).steps.push_back(sm); } console() << " this should be the name of the step... "<< greatChild->getValue() << endl; sm.name = sm.video = sm.start_img = ""; sm.name = greatChild->getValue(); } } if(sm.name.compare("")!=0){ console() << "putting the stepmodel in the vector..." << endl; recipeModels.at(recipeModels.size()-1).steps.push_back(sm); } } } else { // its some kinda value, son console() << "\t\t\t whichkey is: " << whichKey << endl; if(whichKey.compare("menu-image")==0){ recipeModels.at(recipeModels.size()-1).menu_img = grandchild->getValue(); } else if( whichKey.compare("end-image")==0){ recipeModels.at(recipeModels.size()-1).end_img = grandchild->getValue(); } else{ // do nothing man console() << "doing nothing" << endl; } } } } } }