repositories
/
lsystem3d.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
1a372e9
)
* Adaptation to new classes Rule/RuleSet.
author
spixx
<spixx>
Sat, 11 Nov 2006 13:08:34 +0000
(13:08 +0000)
committer
spixx
<spixx>
Sat, 11 Nov 2006 13:08:34 +0000
(13:08 +0000)
src/lsystemparameters.cpp
patch
|
blob
|
blame
|
history
diff --git
a/src/lsystemparameters.cpp
b/src/lsystemparameters.cpp
index bdd16eb000e3d619781860d5fc1fdc1b62c4e295..0cccb1a3fe049d745e67884fdf4a843c12787649 100644
(file)
--- a/
src/lsystemparameters.cpp
+++ b/
src/lsystemparameters.cpp
@@
-1,6
+1,6
@@
// Copyright (C) 2006 Erik Dahlberg
//
// Copyright (C) 2006 Erik Dahlberg
//
-// This file is part of LSystem3
d
.
+// This file is part of LSystem3
D
.
//
// LSystem3D is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
//
// 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 <iostream>
#include <string>
#include <iostream>
#include <string>
+#include <glibmm/stringutils.h>
+
#include "lsystemparameters.h"
#include "lsystemparameters.h"
+#include "rule.h"
+#include "ruleset.h"
using namespace std;
using namespace std;
@@
-62,14
+66,21
@@
void LSystemParameters::load(LindenmayerSystem *lsystem, string path)
// axiom
findChild("axiom");
// axiom
findChild("axiom");
- lsystem->setAxiom(getString());
+ Rule axiom("axiom", getString(), 1.0);
+ lsystem->setAxiom(axiom);
// rules
if (findChild("rule"))
{
do
{
// 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());
}
} while (findNextChild());
}
@@
-77,9
+88,9
@@
void LSystemParameters::load(LindenmayerSystem *lsystem, string path)
findChild("angle");
lsystem->setAngle(getNumber());
findChild("angle");
lsystem->setAngle(getNumber());
- //
iterations
- findChild("
iterations
");
- lsystem->set
NumIterations
((int)getNumber());
+ //
depth
+ findChild("
depth
");
+ lsystem->set
Depth
((int)getNumber());
}
catch (xmlpp::exception e)
{
}
catch (xmlpp::exception e)
{
@@
-101,32
+112,37
@@
void LSystemParameters::load(LindenmayerSystem *lsystem, string path)
*/
void LSystemParameters::save(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");
{
// new document with root node
createDocumentWithRoot("lsystem");
// axiom
addChildToRoot("axiom");
- addString(lsystem->getAxiom());
+ addString(lsystem->getAxiom()
.getContent()
);
// rules
// 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");
{
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());
}
// angle
addChildToRoot("angle");
addNumber(lsystem->getAngle());
- //
iterations
- addChildToRoot("
iterations
");
- addNumber(lsystem->get
NumIterations
());
+ //
depth
+ addChildToRoot("
depth
");
+ addNumber(lsystem->get
Depth
());
// save
saveToDisk(path);
// save
saveToDisk(path);