Save and load segment dimeter and factor.
authorspixx <spixx>
Sun, 26 Nov 2006 14:20:28 +0000 (14:20 +0000)
committerspixx <spixx>
Sun, 26 Nov 2006 14:20:28 +0000 (14:20 +0000)
Removed glibmm dependency.

src/lsystemparameters.cpp

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