File: CustomRule.cpp

package info (click to toggle)
structure-synth 1.5.0-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,268 kB
  • ctags: 1,966
  • sloc: cpp: 10,209; python: 164; makefile: 71; sh: 15
file content (70 lines) | stat: -rw-r--r-- 1,565 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "CustomRule.h"

#include "../../SyntopiaCore/Logging/Logging.h"
#include "Builder.h"

using namespace SyntopiaCore::Logging;

namespace StructureSynth {
	namespace Model {	

		CustomRule::CustomRule(QString name) : Rule(name) {
			weight = 1.0;
			retirementRule = 0;
		}

		CustomRule::~CustomRule() {
			//delete (retirementRule);
		}

		void CustomRule::apply(Builder* b) const {

			int newDepth = -1;
			/// If there is a maxdepth set for this object check it.
			if (getMaxDepth() != -1) {
				if (!b->getState().maxDepths.contains(this)) {
					/// We will add a new maxdepth for this rule to the state.
					newDepth = getMaxDepth()-1;
					
				} else {
					int depth = b->getState().maxDepths[this];
					if (depth <= 0) {
						/// This rule is retired.
						if (retirementRule) {
							b->getState().maxDepths[this] = maxDepth;
							retirementRule->rule()->apply(b);
							
						} 
						return;
					} else {
						/// Decrease depth.
						newDepth = depth-1;
					}
				}
			}

			/// Apply all actions.
			for (int i = 0; i < actions.size(); i++) {
				if (getMaxDepth() != -1) {
					actions[i].apply(b, this, newDepth);
				} else {
					actions[i].apply(b, 0 ,0);
				}
			}
		}

		QList<RuleRef*> CustomRule::getRuleRefs() const {
			QList<RuleRef*>  list;
			for (int i = 0; i < actions.size(); i++) {
				RuleRef* a = actions[i].getRuleRef();
				if (a) list.append(a);
			}
			if (retirementRule) list.append(retirementRule);

			return list;
		}
	

	}
}