From: spixx Date: Sun, 26 Nov 2006 14:20:28 +0000 (+0000) Subject: Save and load segment dimeter and factor. X-Git-Url: https://git.piment-noir.org/?p=lsystem3d.git;a=commitdiff_plain;h=b983918b252749f97e0fe2a85dd86bb3306921cc Save and load segment dimeter and factor. Removed glibmm dependency. --- diff --git a/src/lsystemparameters.cpp b/src/lsystemparameters.cpp index 0cccb1a..1571bc6 100644 --- a/src/lsystemparameters.cpp +++ b/src/lsystemparameters.cpp @@ -19,11 +19,11 @@ +#include + #include #include -#include - #include "lsystemparameters.h" #include "rule.h" #include "ruleset.h" @@ -59,6 +59,8 @@ void LSystemParameters::load(LindenmayerSystem *lsystem, string path) { if (lsystem) { + lsystem->clear(); + try { // load @@ -77,7 +79,7 @@ void LSystemParameters::load(LindenmayerSystem *lsystem, string path) // construct the rule string name = getAttribute("name"); string content = getString(); - double probability = Glib::Ascii::strtod(getAttribute("probability")); + double probability = strtod(getAttribute("probability").c_str(), NULL); Rule completeRule(name, content, probability); lsystem->setRule(completeRule); @@ -91,6 +93,15 @@ void LSystemParameters::load(LindenmayerSystem *lsystem, string path) // depth findChild("depth"); lsystem->setDepth((int)getNumber()); + + // initial segment diameter + findChild("diameter"); + lsystem->setDiameter(getNumber()); + + // segment diameter factor + double diameterFactor = strtod(getAttribute("factor").c_str(), NULL); + lsystem->setDiameterFactor(diameterFactor); + } catch (xmlpp::exception e) { @@ -131,8 +142,8 @@ void LSystemParameters::save(LindenmayerSystem *lsystem, string path) addString(it->second.getContent()); addAttribute("name", it->second.getName()); - - string probabilityString = Glib::Ascii::dtostr(it->second.getProbability()); + + string probabilityString = doubleToString(it->second.getProbability()); addAttribute("probability", probabilityString); } @@ -144,6 +155,14 @@ void LSystemParameters::save(LindenmayerSystem *lsystem, string path) addChildToRoot("depth"); addNumber(lsystem->getDepth()); + // initial segment diameter + addChildToRoot("diameter"); + addNumber(lsystem->getDiameter()); + + // segment diameter factor + string diameterFactor = doubleToString(lsystem->getDiameterFactor()); + addAttribute("factor", diameterFactor); + // save saveToDisk(path); }