-
Notifications
You must be signed in to change notification settings - Fork 0
/
geometry.cpp
120 lines (119 loc) · 3.6 KB
/
geometry.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
#include "geometry.h"
Geometry::Entity::Entity() {
Geometry::EntitiesCollector::count ++;
Geometry::EntitiesCollector::instances->append(this);
this->updateLabel();
this->updateHierarchy(this->label);
}
Geometry::Entity::~Entity() {
delete this->parents;
delete this->children;
Geometry::EntitiesCollector::count --;
int index = Geometry::EntitiesCollector::instances->indexOf(this);
Geometry::EntitiesCollector::instances->removeAt(index);
}
void Geometry::Entity::updateLabel() {
this->label = "Entity";
}
void Geometry::Entity::updateHierarchy(const char *label) {
this->hierarchy.append(label);
this->hierarchy.append("/");
}
QString Geometry::Entity::getName() {
return this->name;
}
void Geometry::Entity::setName(QString newName) {
this->name = newName;
}
QString Geometry::Entity::getHierarchy() {
return this->hierarchy;
}
QVector<Geometry::Entity*>* Geometry::Entity::getParents() {
return this->parents;
}
QVector<Geometry::Entity*>* Geometry::Entity::getChildren() {
return this->children;
}
int Geometry::EntitiesCollector::count = 0;
QVector<Geometry::Entity*>* Geometry::EntitiesCollector::instances =
new QVector<Geometry::Entity*>();
QVector<Geometry::Entity*>* Geometry::EntitiesCollector::getInstances() {
return Geometry::EntitiesCollector::instances;
}
void Geometry::EntitiesCollector::drawEntities(GLWidget* glWidget) {
QVector<Geometry::Entity*>* entitiesCollector = Geometry::EntitiesCollector::getInstances();
QVector<Geometry::Entity*>::iterator iterator = entitiesCollector->begin();
while (iterator != entitiesCollector->end()) {
qDebug()<<"value from collector: "<<*iterator;
(*iterator)->draw(glWidget);
iterator++;
}
}
Geometry::Point::Point(float x, float y, float z) :
Geometry::Entity() {
count ++;
instances->append(this);
this->updateLabel();
this->updateHierarchy(this->label);
this->name = QString(this->label)+QString("_")+QString("%1").arg(count);
this->coords[0] = x;
this->coords[1] = y;
this->coords[2] = z;
}
Geometry::Point::~Point() {
count --;
int index = instances->indexOf(this);
instances->removeAt(index);
}
void Geometry::Point::updateLabel() {
this->label = "Point";
}
float* Geometry::Point::getCoords() {
return this->coords;
}
void Geometry::Point::setCoords(float x, float y, float z) {
this->coords[0] = x;
this->coords[1] = y;
this->coords[2] = z;
}
void Geometry::Point::draw(GLWidget* glWidget) {
qDebug()<<"drawing point: ";
QVector<GLfloat> vertCoords = QVector<GLfloat>();
vertCoords.append(this->coords[0]);
vertCoords.append(this->coords[1]);
vertCoords.append(this->coords[2]);
glWidget->drawPoint(vertCoords);
qDebug()<<"finished drawing point.";
}
Geometry::Line::Line(Point* startP, Point* endP) {
count ++;
instances->append(this);
this->updateLabel();
this->updateHierarchy(this->label);
this->startPoint = startP;
this->endPoint = endP;
}
Geometry::Line::~Line() {
count --;
int index = instances->indexOf(this);
instances->removeAt(index);
}
void Geometry::Line::updateLabel() {
this->label = "Line";
}
Geometry::Point* Geometry::Line::getStartPoint() {
return this->startPoint;
}
void Geometry::Line::setStartPoint(Point* startP) {
this->startPoint = startP;
}
Geometry::Point* Geometry::Line::getEndPoint() {
return this->endPoint;
}
void Geometry::Line::setEndPoint(Point* endP) {
this->endPoint = endP;
}
void Geometry::Line::draw(GLWidget* glWidget) {
qDebug()<<"drawing line: ";
qDebug()<<"finished drawing line.";
}