예제 #1
0
	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;
		}
	}
예제 #2
0
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);
        }
        
    }
}
예제 #3
0
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?
                }
                
            }
        }
        
    }
}
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);
}
예제 #5
0
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;
	} );*/
}
예제 #6
0
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_;
}
예제 #7
0
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);
                        }
                    }
                }
            }
        }
    }
}
예제 #8
0
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;
                    }
                    
                }
                
            }
        }
        
    }
}