From: spixx Date: Sat, 11 Nov 2006 13:08:34 +0000 (+0000) Subject: * Adaptation to new classes Rule/RuleSet. X-Git-Url: https://git.piment-noir.org/?p=lsystem3d.git;a=commitdiff_plain;h=7cd25edcaf23a014139d25e2b0474a3eb3f81646 * Adaptation to new classes Rule/RuleSet. --- diff --git a/src/lsystemparameters.cpp b/src/lsystemparameters.cpp index bdd16eb..0cccb1a 100644 --- a/src/lsystemparameters.cpp +++ b/src/lsystemparameters.cpp @@ -1,6 +1,6 @@ // 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 @@ -22,7 +22,11 @@ #include #include +#include + #include "lsystemparameters.h" +#include "rule.h" +#include "ruleset.h" using namespace std; @@ -62,14 +66,21 @@ void LSystemParameters::load(LindenmayerSystem *lsystem, string path) // 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()); } @@ -77,9 +88,9 @@ void LSystemParameters::load(LindenmayerSystem *lsystem, string path) findChild("angle"); lsystem->setAngle(getNumber()); - // iterations - findChild("iterations"); - lsystem->setNumIterations((int)getNumber()); + // depth + findChild("depth"); + lsystem->setDepth((int)getNumber()); } catch (xmlpp::exception e) { @@ -101,32 +112,37 @@ void LSystemParameters::load(LindenmayerSystem *lsystem, string path) */ 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 rules = lsystem->getRules(); - map::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);