1 // Copyright (C) 2006 Erik Dahlberg
3 // This file is part of LSystem3d.
5 // LSystem3D is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // LSystem3D is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with LSystem3D; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "lsystemparameters.h"
34 LSystemParameters::LSystemParameters()
43 LSystemParameters::~LSystemParameters()
50 * Load parameters from xml file
51 * @param lsystem put parameters into this l-system
52 * @param path path to xml file
54 void LSystemParameters::load(LindenmayerSystem
*lsystem
, string path
)
65 lsystem
->setAxiom(getString());
68 if (findChild("rule"))
72 lsystem
->setRule(getAttribute("name"), getString());
73 } while (findNextChild());
78 lsystem
->setAngle(getNumber());
81 findChild("iterations");
82 lsystem
->setNumIterations((int)getNumber());
84 catch (xmlpp::exception e
)
86 cerr
<< "LSystemParameters::load(): " << e
.what() << endl
;
91 cerr
<< "invalid lsystem" << endl
;
98 * Save parameters to xml file
99 * @param lsystem get parameters from this l-system
100 * @param path path to xml file
102 void LSystemParameters::save(LindenmayerSystem
*lsystem
, string path
)
104 if (lsystem
&& !lsystem
->getAxiom().empty() && !lsystem
->getRules().empty())
106 // new document with root node
107 createDocumentWithRoot("lsystem");
110 addChildToRoot("axiom");
111 addString(lsystem
->getAxiom());
114 map
<string
,string
> rules
= lsystem
->getRules();
115 map
<string
,string
>::iterator currentRule
;
116 for (currentRule
= rules
.begin(); currentRule
!= rules
.end(); currentRule
++)
118 addChildToRoot("rule");
119 addString(currentRule
->second
);
120 addAttribute("name", currentRule
->first
);
124 addChildToRoot("angle");
125 addNumber(lsystem
->getAngle());
128 addChildToRoot("iterations");
129 addNumber(lsystem
->getNumIterations());
136 cerr
<< "invalid lsystem" << endl
;