// Copyright (C) 2006 Erik Dahlberg
//
-// This file is part of LSystem3d.
+// This file is part of LSystem3D.
//
// LSystem3D is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
#include <iostream>
#include <string>
+#include <glibmm/stringutils.h>
+
#include "lsystemparameters.h"
+#include "rule.h"
+#include "ruleset.h"
using namespace std;
// axiom
findChild("axiom");
- lsystem->setAxiom(getString());
+ Rule axiom("axiom", getString(), 1.0);
+ lsystem->setAxiom(axiom);
// rules
if (findChild("rule"))
{
do
{
- lsystem->setRule(getAttribute("name"), getString());
+ // construct the rule
+ string name = getAttribute("name");
+ string content = getString();
+ double probability = Glib::Ascii::strtod(getAttribute("probability"));
+ Rule completeRule(name, content, probability);
+
+ lsystem->setRule(completeRule);
} while (findNextChild());
}
findChild("angle");
lsystem->setAngle(getNumber());
- // iterations
- findChild("iterations");
- lsystem->setNumIterations((int)getNumber());
+ // depth
+ findChild("depth");
+ lsystem->setDepth((int)getNumber());
}
catch (xmlpp::exception e)
{
*/
void LSystemParameters::save(LindenmayerSystem *lsystem, string path)
{
- if (lsystem && !lsystem->getAxiom().empty() && !lsystem->getRules().empty())
+ if (lsystem &&
+ lsystem->getAxiom().getProbability() != 0.0 &&
+ !lsystem->getRules().getRules().empty())
{
// new document with root node
createDocumentWithRoot("lsystem");
// axiom
addChildToRoot("axiom");
- addString(lsystem->getAxiom());
+ addString(lsystem->getAxiom().getContent());
// rules
- map<string,string> rules = lsystem->getRules();
- map<string,string>::iterator currentRule;
- for (currentRule = rules.begin(); currentRule != rules.end(); currentRule++)
+ rulemap rules = lsystem->getRules().getRules();
+ for (rulemap::iterator it = rules.begin(); it != rules.end(); ++it)
{
addChildToRoot("rule");
- addString(currentRule->second);
- addAttribute("name", currentRule->first);
+ addString(it->second.getContent());
+
+ addAttribute("name", it->second.getName());
+
+ string probabilityString = Glib::Ascii::dtostr(it->second.getProbability());
+ addAttribute("probability", probabilityString);
}
// angle
addChildToRoot("angle");
addNumber(lsystem->getAngle());
- // iterations
- addChildToRoot("iterations");
- addNumber(lsystem->getNumIterations());
+ // depth
+ addChildToRoot("depth");
+ addNumber(lsystem->getDepth());
// save
saveToDisk(path);