* Adaptation to new classes Rule/RuleSet.
authorspixx <spixx>
Sat, 11 Nov 2006 13:08:34 +0000 (13:08 +0000)
committerspixx <spixx>
Sat, 11 Nov 2006 13:08:34 +0000 (13:08 +0000)
src/lsystemparameters.cpp

index bdd16eb000e3d619781860d5fc1fdc1b62c4e295..0cccb1a3fe049d745e67884fdf4a843c12787649 100644 (file)
@@ -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
 #include <iostream>
 #include <string>
 
+#include <glibmm/stringutils.h>
+
 #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<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);