-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoil.cpp
More file actions
72 lines (65 loc) · 1.74 KB
/
Copy pathCoil.cpp
File metadata and controls
72 lines (65 loc) · 1.74 KB
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
#include "Coil.h"
Coil::Coil() : points({}), current_start_point(points.begin()) {}
Coil::Coil(std::filesystem::path coil_file_path) : points({})
{
if (std::filesystem::exists(coil_file_path))
{
std::ifstream coil_file_stream(coil_file_path);
if (coil_file_stream.is_open())
{
double x, y, z;
bool more_then_one_point = false;
while (coil_file_stream >> x >> y >> z)
{
points.push_back(Point(x, y, z));
if (!more_then_one_point && points.size() == 2)
{
more_then_one_point = true;
}
}
if (more_then_one_point)
{
current_start_point = points.begin();
}
else
{
std::cerr << "\nWrong Coil file format\n";
}
coil_file_stream.close();
}
else
{
std::cerr << "\nOpening file error\n";
//There must be an error_of_opening_file throwing code
}
}
else
{
std::cerr << "\nFinding file error\n";
//There must be an error_of_finding_file throwing code
//throw new std::FileNotFoundException("I couldn't find your file!");
}
}
Segment Coil::getCurrentSegment(bool& end)
{
//static size_t segment_num = 0;
auto preend = std::prev(points.end());
if (current_start_point != preend)
{
std::list<Point>::iterator segment_start(current_start_point++);
if (current_start_point == preend)
end = true;
//end = segment_num++ < points.size() - 2;
//std::cerr << "Start: " << (*segment_start).x << " " << (*segment_start).y << " " << (*segment_start).z << '\n'
// << "End: " << (*current_start_point).x << " " << (*current_start_point).y << " " << (*current_start_point).z << "\n\n";
return Segment(*segment_start, *current_start_point);
}
else
{
return Segment(Point(0, 0, 0), Point(0, 0, 0));
}
}
void Coil::resetSegmentIterator()
{
current_start_point = points.begin();
}