~ubuntu-branches/ubuntu/oneiric/structure-synth/oneiric

« back to all changes in this revision

Viewing changes to StructureSynth/Model/CustomRule.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Miriam Ruiz
  • Date: 2009-04-13 13:28:45 UTC
  • Revision ID: james.westby@ubuntu.com-20090413132845-d7d42t4llxjxq0ez
Tags: upstream-0.9
ImportĀ upstreamĀ versionĀ 0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "CustomRule.h"
 
2
 
 
3
#include "../../SyntopiaCore/Logging/Logging.h"
 
4
#include "Builder.h"
 
5
 
 
6
using namespace SyntopiaCore::Logging;
 
7
 
 
8
namespace StructureSynth {
 
9
        namespace Model {       
 
10
 
 
11
                CustomRule::CustomRule(QString name) : Rule(name) {
 
12
                        weight = 1.0;
 
13
                        retirementRule = 0;
 
14
                }
 
15
 
 
16
                CustomRule::~CustomRule() {
 
17
                        delete (retirementRule);
 
18
                }
 
19
 
 
20
                void CustomRule::apply(Builder* b) const {
 
21
 
 
22
                        int newDepth = -1;
 
23
                        /// If there is a maxdepth set for this object check it.
 
24
                        if (getMaxDepth() != -1) {
 
25
                                if (!b->getState().maxDepths.contains(this)) {
 
26
                                        /// We will add a new maxdepth for this rule to the state.
 
27
                                        newDepth = getMaxDepth()-1;
 
28
                                        
 
29
                                } else {
 
30
                                        int depth = b->getState().maxDepths[this];
 
31
                                        if (depth <= 0) {
 
32
                                                /// This rule is retired.
 
33
                                                if (retirementRule) {
 
34
                                                        retirementRule->rule()->apply(b);
 
35
                                                } 
 
36
                                                return;
 
37
                                        } else {
 
38
                                                /// Decrease depth.
 
39
                                                newDepth = depth-1;
 
40
                                        }
 
41
                                }
 
42
                        }
 
43
 
 
44
                        /// Apply all actions.
 
45
                        for (int i = 0; i < actions.size(); i++) {
 
46
                                if (getMaxDepth() != -1) {
 
47
                                        actions[i].apply(b, this, newDepth);
 
48
                                } else {
 
49
                                        actions[i].apply(b, 0 ,0);
 
50
                                }
 
51
                        }
 
52
                }
 
53
 
 
54
                QList<RuleRef*> CustomRule::getRuleRefs() const {
 
55
                        QList<RuleRef*>  list;
 
56
                        for (int i = 0; i < actions.size(); i++) {
 
57
                                RuleRef* a = actions[i].getRuleRef();
 
58
                                if (a) list.append(a);
 
59
                        }
 
60
                        if (retirementRule) list.append(retirementRule);
 
61
 
 
62
                        return list;
 
63
                }
 
64
        
 
65
 
 
66
        }
 
67
}
 
68