-
Notifications
You must be signed in to change notification settings - Fork 1
/
visualsettingsitem.cpp
175 lines (163 loc) · 7.2 KB
/
visualsettingsitem.cpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*!
* \file visualsettingsitem.cpp
* \author Simon Coakley
* \date 2012
* \copyright Copyright (c) 2012 University of Sheffield
* \brief Implementation of visual settings item
*/
#include "./visualsettingsitem.h"
VisualSettingsItem::VisualSettingsItem() {
colourColor = QColor(128, 128, 128, 255);
boolEnabled = true;
}
VisualSettingsItem::VisualSettingsItem(QString agentType, Condition condition,
Position x, Position y, Position z, Shape shape,
QColor colour, bool enabled) {
setAgentType(agentType);
setCondition(condition);
setX(x);
setY(y);
setZ(z);
setShape(shape);
setColour(colour);
setEnabled(enabled);
}
bool VisualSettingsItem::passAgentCondition(Agent *agent) {
bool pass = true;
// If condition is enabled
if (conditionCondition.enable) {
pass = false;
// For each agent variable
for (int k = 0; k < agent->tags.count(); k++) {
// If the variable is used in the condition
if (QString::compare(conditionCondition.variable,
agent->tags.at(k)) == 0) {
// Check each possible operator and its outcome
if (conditionCondition.op == "==" &&
agent->values.at(k).toDouble() ==
conditionCondition.value) pass = true;
else if (conditionCondition.op == "!=" &&
agent->values.at(k).toDouble() !=
conditionCondition.value) pass = true;
else if (conditionCondition.op == ">" &&
agent->values.at(k).toDouble() >
conditionCondition.value) pass = true;
else if (conditionCondition.op == "<" &&
agent->values.at(k).toDouble() <
conditionCondition.value) pass = true;
else if (conditionCondition.op == ">=" &&
agent->values.at(k).toDouble() >=
conditionCondition.value) pass = true;
else if (conditionCondition.op == "<=" &&
agent->values.at(k).toDouble() <=
conditionCondition.value) pass = true;
}
}
}
return pass;
}
void VisualSettingsItem::populate(QList<Agent *> *a) {
for (int j = 0; j < agents.size(); j++)
// Free memory of ruleagent data
delete agents.at(j);
agents.clear();
// If the rule is enabled
if (boolEnabled) {
// If the agent corresponds to the rule agent
for (int i = 0; i < a->size(); i++) {
if (a->at(i)->agentType == agentTypeString) {
// If the agent passes any condition
if (passAgentCondition(a->at(i))) {
// Change agent drawing variables for this rule
// Then add a copy of this agent to the agent list of
// the drawing rule.
// Create a new rule agent to handle drawing this agent
// under this rule
agents.append(new RuleAgent(a->at(i)));
}
}
}
}
}
void VisualSettingsItem::applyOffset(
double xoffset, double yoffset, double zoffset) {
for (int j = 0; j < agents.size(); j++) {
agents.at(j)->x += xoffset;
agents.at(j)->y += yoffset;
agents.at(j)->z += zoffset;
}
}
void VisualSettingsItem::applyRatio(double ratio) {
for (int j = 0; j < agents.size(); j++) {
agents.at(j)->x *= ratio;
agents.at(j)->y *= ratio;
agents.at(j)->z *= ratio;
/* Point size does not need to be ratioed */
if (shapeShape.getShape() != "point") {
agents.at(j)->shapeDimension *= ratio;
agents.at(j)->shapeDimensionY *= ratio;
agents.at(j)->shapeDimensionZ *= ratio;
}
}
}
void VisualSettingsItem::copyAgentDrawDataToRuleAgentDrawData(
Dimension * agentDimension) {
for (int j = 0; j < agents.size(); j++) {
RuleAgent * ruleagent = agents.at(j);
Agent * agent = ruleagent->agent;
ruleagent->x = xPosition.opValue;
ruleagent->y = yPosition.opValue;
ruleagent->z = zPosition.opValue;
ruleagent->shapeDimension = shapeShape.getDimension();
ruleagent->shapeDimensionY = shapeShape.getDimensionY();
ruleagent->shapeDimensionZ = shapeShape.getDimensionZ();
for (int k = 0; k < agent->tags.count(); k++) {
if (xPosition.useVariable)
if (QString::compare(xPosition.positionVariable,
agent->tags.at(k)) == 0)
ruleagent->x += agent->values.at(k).toDouble();
if (yPosition.useVariable)
if (QString::compare(yPosition.positionVariable,
agent->tags.at(k)) == 0)
ruleagent->y += agent->values.at(k).toDouble();
if (zPosition.useVariable)
if (QString::compare(zPosition.positionVariable,
agent->tags.at(k)) == 0)
ruleagent->z += agent->values.at(k).toDouble();
if (shapeShape.getUseVariable())
if (QString::compare(
shapeShape.getDimensionVariable(),
agent->tags.at(k)) == 0)
ruleagent->shapeDimension +=
agent->values.at(k).toDouble();
if (shapeShape.getUseVariableY())
if (QString::compare(
shapeShape.getDimensionVariableY(),
agent->tags.at(k)) == 0)
ruleagent->shapeDimensionY +=
agent->values.at(k).toDouble();
if (shapeShape.getUseVariableZ())
if (QString::compare(
shapeShape.getDimensionVariableZ(),
agent->tags.at(k)) == 0)
ruleagent->shapeDimensionZ +=
agent->values.at(k).toDouble();
}
if (shapeShape.getFromCentreX()) ruleagent->shapeDimension *= 2.0;
if (shapeShape.getFromCentreY()) ruleagent->shapeDimensionY *= 2.0;
if (shapeShape.getFromCentreZ()) ruleagent->shapeDimensionZ *= 2.0;
/* Calc agent scene dimension */
if (agentDimension->xmin > ruleagent->x + ruleagent->shapeDimension)
agentDimension->xmin = ruleagent->x + ruleagent->shapeDimension;
if (agentDimension->xmax < ruleagent->x + ruleagent->shapeDimension)
agentDimension->xmax = ruleagent->x + ruleagent->shapeDimension;
if (agentDimension->ymin > ruleagent->y + ruleagent->shapeDimensionY)
agentDimension->ymin = ruleagent->y + ruleagent->shapeDimensionY;
if (agentDimension->ymax < ruleagent->y + ruleagent->shapeDimensionY)
agentDimension->ymax = ruleagent->y + ruleagent->shapeDimensionY;
if (agentDimension->zmin > ruleagent->z + ruleagent->shapeDimensionZ)
agentDimension->zmin = ruleagent->z + ruleagent->shapeDimensionZ;
if (agentDimension->zmax < ruleagent->z + ruleagent->shapeDimensionZ)
agentDimension->zmax = ruleagent->z + ruleagent->shapeDimensionZ;
}
}