-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataSvxExport.cpp
178 lines (163 loc) · 4.61 KB
/
DataSvxExport.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
176
177
178
/** @file DataSvxExport.cpp
*
* @author marco corvi
* @date april 2010
*
* @brief Centerline data export in Survex format
* --------------------------------------------------------
* Copyright This sowftare is distributed under GPL-3.0 or later
* See the file COPYING.
*/
#include <stdio.h>
#include <sstream>
#include <QFileInfo>
#include <QFile>
#include "shorthands.h"
#include "DataSvxExport.h"
#include "Flags.h"
/** Survex export
* The following format is used to export the centerline data in survex
*
* *begin survey_name
* *units tape feet|metres
* *units compass clino grad|degrees
* *calibrate declination ...
* *date yyyy.mm.dd
* *data normal from to tape compass clino
* ...
* *flags surface|not surface
* *flags duplicate|not duplicate
* *flags splay|not splay
* ...
* ; shot_comment
* ...
* (optional survey commands)
* *end
*/
bool
saveAsSurvex( DataList & data,
const CenterlineInfo & c_info,
const Units & units )
{
const SurveyInfo & info = c_info.surveyInfo;
int extra_cnt = 0;
QFile file( info.exportName );
if ( ! file.open( QIODevice::WriteOnly ) ) {
DBG_CHECK("Failed to open file \"%s\"\n", info.exportName.TO_CHAR() );
return false;
}
// int day, month, year;
// GetDate( &day, &month, &year);
std::ostringstream oss;
oss.setf( std::ios::fixed );
oss.precision(2);
oss << "*begin " << info.name.TO_CHAR() << "\n\n";
if ( ! info.title.isEmpty() ) {
oss << " *title \"" << info.title.TO_CHAR() << "\"\n";
}
// TODO survey title ect.
double ls = units.length_factor;
double as = units.angle_factor;
if ( units.length_units == LENGTH_FEET ) {
oss << " *units tape feet\n";
} else {
oss << " *units tape metres\n";
}
if ( units.angle_units == ANGLE_GRAD ) {
oss << " *units compass clino grads\n";
} else {
oss << " *units compass clino degrees\n";
}
if ( info.declination != DECLINATION_UNDEF ) {
oss << " *calibrate declination " <<info.declination << "\n\n";
}
oss << " *date ";
oss.fill( '0' );
oss.width( 4 ); oss << c_info.year << ".";
oss.width( 2 ); oss << c_info.month << ".";
oss.width( 2 ); oss << c_info.day << "\n";
oss.fill( ' ');
if ( info.therionCenterlineCommand.size() > 0 ) {
oss << info.therionCenterlineCommand << "\n";
}
oss << " *data normal from to tape compass clino\n";
DBlock * b;
bool in_splay = false;
bool in_surface = false;
bool in_duplicate = false;
for ( b = data.listHead(); b; b=b->next() ) {
if ( ! b->hasFromStation() && ! b->hasToStation() ) {
// skip data with neither From nor To
continue;
}
if ( b->Flag() == FLAG_SURFACE ) { // surface
if ( ! in_surface ) {
oss << " *flags surface\n";
in_surface = true;
}
} else {
if ( in_surface ) {
oss << " *flags not surface\n";
in_surface = false;
}
}
if ( b->Flag() == FLAG_DUPLICATE || ! b->hasToStation() ) { // duplicate
if ( ! in_surface ) {
oss << " *flags duplicate\n";
in_duplicate = true;
}
} else {
if ( in_duplicate ) {
oss << " *flags not duplicate\n";
in_duplicate = false;
}
}
oss.fill( '0' );
if ( ! b->hasFromStation() ) {
if ( ! in_splay ) {
oss << " *flags splay\n";
in_splay = true;
}
++extra_cnt;
if ( b->hasToStation() ) {
oss << " " << b->toStation() << "_";
oss.width( 4 ); oss << extra_cnt << " ";
oss << b->toStation();
} else {
oss << " f_";
oss.width( 4 ); oss << extra_cnt << " t_";
oss.width( 4 ); oss << extra_cnt;
}
} else {
if ( ! b->hasToStation() ) {
if ( ! in_splay ) {
oss << " *flags splay\n";
in_splay = true;
}
++extra_cnt;
oss << " " << b->fromStation() << " " << b->fromStation() << "_";
oss.width( 4 ); oss << extra_cnt;
} else {
if ( in_splay ) {
oss << " *flags not splay\n";
in_splay = false;
}
oss << " " << b->fromStation() << " " << b->toStation();
}
}
oss.fill( ' ' );
oss << " " << ls*b->Tape()
<< " " << as*b->Compass()
<< " " << as*b->Clino() << "\n";
if ( b->hasComment() ) {
oss << " ; " << b->getComment() << "\n";
}
}
if ( info.therionSurveyCommand.size() > 0 ) {
oss << info.therionSurveyCommand << "\n";
}
oss << "*end\n";
file.write( oss.str().c_str() );
file.close();
return true;
}