repositories
/
lsystem3d.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Save and load segment dimeter and factor.
[lsystem3d.git]
/
src
/
lsystemparameters.cpp
diff --git
a/src/lsystemparameters.cpp
b/src/lsystemparameters.cpp
index 0cccb1a3fe049d745e67884fdf4a843c12787649..1571bc6a46ee48f068f20abec81c608901355d60 100644
(file)
--- a/
src/lsystemparameters.cpp
+++ b/
src/lsystemparameters.cpp
@@
-19,11
+19,11
@@
+#include <cstdlib>
+
#include <iostream>
#include <string>
#include <iostream>
#include <string>
-#include <glibmm/stringutils.h>
-
#include "lsystemparameters.h"
#include "rule.h"
#include "ruleset.h"
#include "lsystemparameters.h"
#include "rule.h"
#include "ruleset.h"
@@
-59,6
+59,8
@@
void LSystemParameters::load(LindenmayerSystem *lsystem, string path)
{
if (lsystem)
{
{
if (lsystem)
{
+ lsystem->clear();
+
try
{
// load
try
{
// load
@@
-77,7
+79,7
@@
void LSystemParameters::load(LindenmayerSystem *lsystem, string path)
// construct the rule
string name = getAttribute("name");
string content = getString();
// 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);
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());
// 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)
{
}
catch (xmlpp::exception e)
{
@@
-131,8
+142,8
@@
void LSystemParameters::save(LindenmayerSystem *lsystem, string path)
addString(it->second.getContent());
addAttribute("name", it->second.getName());
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);
}
addAttribute("probability", probabilityString);
}
@@
-144,6
+155,14
@@
void LSystemParameters::save(LindenmayerSystem *lsystem, string path)
addChildToRoot("depth");
addNumber(lsystem->getDepth());
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);
}
// save
saveToDisk(path);
}