OGS
CoordinateSystem.cpp
Go to the documentation of this file.
1
10#include "CoordinateSystem.h"
11
12#include <boost/algorithm/string/trim.hpp>
13#include <boost/tokenizer.hpp>
14#include <iostream>
15
16#include "BaseLib/Logging.h"
17
18namespace FileIO
19{
20namespace Gocad
21{
22std::string parseName(std::string const& str)
23{
24 std::string name;
25 std::size_t const start = str.find_first_of('\"');
26 if (start != std::string::npos)
27 {
28 std::size_t const end = str.find_last_of('\"');
29 name = str.substr(start + 1, end - start - 1);
30 }
31 else
32 {
33 name = str.substr(str.find_first_of(' '), str.length());
34 }
35 boost::algorithm::trim(name);
36 return name;
37}
38
39bool CoordinateSystem::parse(std::istream& in)
40{
41 std::string line; // string used for reading a line
42 boost::char_separator<char> sep("-;| \"");
43
44 std::getline(in, line); // NAME name
45 boost::tokenizer<boost::char_separator<char>> tok(line, sep);
46 auto it(tok.begin());
47 if (*it != "NAME")
48 {
49 return false;
50 }
51 name = parseName(line);
52 projection = "";
53 datum = "";
54
55 while (std::getline(in, line))
56 {
57 tok.assign(line);
58 it = tok.begin();
59 if (*it == "AXIS_NAME")
60 {
61 ++it;
62 axis_name_u = *it;
63 ++it;
64 axis_name_v = *it;
65 ++it;
66 axis_name_w = *it;
67 }
68 else if (*it == "AXIS_UNIT")
69 {
70 ++it;
71 axis_unit_u = *it;
72 ++it;
73 axis_unit_v = *it;
74 ++it;
75 axis_unit_w = *it;
76 }
77 else if (*it == "ZPOSITIVE")
78 {
79 ++it;
80 if (*it == "Depth")
81 {
83 }
84 else
85 {
87 }
88 }
89 else if (*it == "PROJECTION")
90 {
91 projection = parseName(line);
92 }
93 else if (*it == "DATUM")
94 {
95 datum = parseName(line);
96 }
97 else if (*it == "END_ORIGINAL_COORDINATE_SYSTEM")
98 {
99 return true;
100 }
101 else
102 {
103 WARN("CoordinateSystem::parse() - Unknown keyword found: {:s}",
104 line);
105 }
106 }
107 ERR("Error: Unexpected end of file.");
108 return false;
109}
110
111std::ostream& operator<<(std::ostream& os, CoordinateSystem const& c)
112{
113 os << "Gocad CoordinateSystem " << c.name
114 << "\nAxis names: " << c.axis_name_u << ", " << c.axis_name_v << ", "
115 << c.axis_name_w << "\nAxis units: " << c.axis_unit_u << ", "
116 << c.axis_unit_v << ", " << c.axis_unit_w << "\nZ-orientation: ";
118 {
119 os << "downwards";
120 }
121 else
122 {
123 os << "upwards";
124 }
125 os << "\n";
126 return os;
127}
128
129} // end namespace Gocad
130} // end namespace FileIO
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::ostream & operator<<(std::ostream &os, CoordinateSystem const &c)
std::string parseName(std::string const &str)