-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataList.h
411 lines (360 loc) · 12 KB
/
DataList.h
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/** @file DataList.h
*
* @author marco corvi
* @date apr 2009
*
* @brief topolinux measurements data
* --------------------------------------------------------
* Copyright This sowftare is distributed under GPL-3.0 or later
* See the file COPYING.
*/
#ifndef DATA_LIST_H
#define DATA_LIST_H
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include <map>
#include <string>
#include "DBlock.h"
#include "DistoX.h"
#include "CenterlineInfo.h"
#include "Units.h"
#include "PlotDrawer.h"
#include "PlotStatus.h"
#include "Num.h"
/** list of logical shots (= blocks)
*/
class DataList
{
private:
DBlock * head; //!< head of the list
DBlock * base_block; //!< base shot for centerline numerics
int list_size; //!< number of logical shots on the list
int shot; //!< number of logical shots w. more than one measure
std::map< std::string, std::string > station_comment;
bool need_num; //!< whether needs to do num
int num_measures; //!< number of shots in num
Num num; //!< centerline numerics
public:
DataList()
: head( NULL )
, base_block( NULL )
, list_size( 0 )
, shot( 0 )
, need_num( false ) // empty data list does not need num
, num_measures( 0 )
{ }
~DataList()
{
clear();
}
/** get the head of the list of data
* @return the head block
*/
DBlock * listHead() { return head; }
/** get the number of shots
* @return the size of the list
*/
int listSize() const { return list_size; }
/** get the number of centerline shots
* @return the number of shots with more than one measure
*/
int centerlineSize() const { return shot; }
/** check if a block is the base block
* @param block block to check
* @return true if the the block is the base block
*/
bool isBaseBlock( DBlock * block ) const { return block == base_block; }
/** get the base block
* @return the base block (or NULL if not set)
*/
DBlock * getBaseBlock() { return base_block; }
/** set the base block
* @param block new base block (use NULL to unset)
*/
void setBaseBlock( DBlock * block )
{
base_block = block;
}
/** get a reference to the numerical engine
* @return a const ref to the numerical engine
*/
const Num & getNum() const { return num; }
/** set the flag that indicates the need to recompute the survey
*/
void resetNum() { need_num = true; }
/** compute the survey
* @force force recomputing the centerline [default false]
* @return the number of measures (= centerline shots)
*/
int doNum( bool force = false );
/** check if the list has a shot with given stations
* @param from FROM station name
* @param to TO station name
* @return true if the list has a shot from-to,
*/
bool hasBlock( const char * from, const char * to )
{
DBlock * b = head;
while ( b != NULL ) {
if ( b->fromStation() == from && b->toStation() == to ) return true;
if ( b->fromStation() == to && b->toStation() == from ) return true;
b = b->next_block;
}
return false;
}
/** drop and delete a block
* @param block block to delete
*/
void dropBlock( DBlock * block )
{
if ( block != NULL ) {
if ( head == block ) {
head = block->next_block;
-- list_size;
if ( block->count > 1 ) --shot;
} else {
DBlock * b = head;
while ( b && b->next_block != block ) b=b->next_block;
if ( b != NULL ) {
b->next_block = block->next_block;
-- list_size;
if ( block->count > 1 ) --shot;
}
}
if ( block == base_block ) { // don't leave base_block dangling
base_block = NULL;
}
delete block;
need_num = true;
}
}
/** accessor: get the i-th block
* @param pos index of the block
* @return pointer to the block
*/
DBlock * getBlock( size_t pos );
/** clear the list of blocks (and delete them)
*/
void clear();
/** write the data to a file (TopoLinux format)
* @param c_info centerline info
* @return true if successful
*/
bool saveTlx( CenterlineInfo & c_info );
/** insert a block before or after another block
* @param blk the block where to insert
* @param d distance
* @param b conmpass
* @param c clino
* @param r roll
* @param before whether to insert before blk
*
* Used by QTshotWidget to insert a block before or after another.
*/
void insertBlock( DBlock * blk, double d, double b, double c, double r, bool before );
/** load the data from a file
* @param drawer plot drawer object
* @param filename name of the file
* @param append whether to append the data to the list
* @param info centerline info
* @return error code:
* - 0 ok
* - 1 failed open
* - 2 failed read raw file
* - 3 failed read tlx file
* - 4 unsupported file type
*
* @note Supported formats:
* - TopoLinux (v.1 and v.2),
* - raw (memory_dump),
* - PocketTopo (v.3)
*/
int loadFile( PlotDrawer * drawer, const char * filename, bool append, CenterlineInfo * info = NULL );
/** load the data directly from the DistoX class
* @param disto DistoX class
* @param append whether to append the data to the list
* @param smart whether to use smart station assignment
* @param splay which station to assign splay shots (1: FROM, 2: TO)
* @param backward whether shots are backward
* @return true if successful
*/
bool loadDisto( DistoX & disto, bool append, bool smart, int splay, bool backward );
private:
/** initialize the "from" and "to" values and the pointer to the
* last block of the list
* @param from "from" index [output]
* @param to "to"index [output]
* @param append whether to append the data to the list
* @return last block of the l;ist, or NULL if the list is empty
*
* @note "from" and "to" are always initialized so that to > from
* (usually, to = from+1); whether the shot is taken backward
* or is a splay-shot is taken care by the method createBlock()
*/
DBlock * initFromTo( int & from, int & to, bool append );
/** load the data from a TopoLinux file
* @param fp file stream
* @param append whether to append the data to the list
* @param info centerline info
* @param version TLX file version
* @return true if successful
*/
bool loadTlx( FILE * fp, bool append, CenterlineInfo * info, int version );
/** load the data from a PocketTopo file
* @param drawer plot drawer object
* @param fp file stream
* @return true if successful
*/
bool loadPocketTopo( PlotDrawer * drawer, FILE * fp, CenterlineInfo * info );
/** load the data from a raw file downloaded from DistoX
* @param fp file stream
* @param append whether to append the data to the list
* @param smart whether to use smart station assignment
* @param splay which station to attach splay shots (1: FROM, 2: TO)
* @param backward whether shots are backward
* @return true if successful
*/
bool loadRaw( FILE * fp, bool append, bool smart, int splay, bool backward );
public:
/** update the info in a block
* @param r row index (block index)
* @param c column index (0: From, 1: To, 2-3-4 illegal, 5: extend, 6: flag, 7: comment
* @param txt text (new value of the modified item)
*/
void updateBlock( int r, int c, const char * txt );
/** compute the extended flag for a splay shot
* @param b splay shot
* @note this method requires that the extended flags have been
* already computed for the centerline shots
*/
void evalSplayExtended( DBlock * b );
/** compute the the extended flag for all splay shots
*
void evalSplayExtended()
{
// fprintf(stderr, "evalSplayExtended()\n");
for ( DBlock * b = head; b != NULL; b=b->Next() ) {
if ( b->hasFromStation() && ! b->hasToStation() ) {
evalSplayExtended( b );
}
}
}
*/
void dump();
/** update the "extend" value of a block
* @param blk block
* @param extend new extend value
*/
void updateExtend( DBlock * blk, int extend )
{
if ( ! blk ) return;
// fprintf(stderr, "updateExtend() Block %s-%s extend %d\n",
// blk->from.c_str(), blk->to.c_str(), extend );
blk->extend = extend;
need_num = true;
}
private:
void computeAverage( double * d0, double * b0, double * c0, double * r0, int cnt,
double & dave, double & bave, double & cave, double & rave );
/** construct a block from a set of shots
* @param from first station
* @param to second station
* @param d0 array of shots distances
* ...
* @param r0 roll(s)
* @param cnt number of shots
* @return new block
*/
DBlock * shotToBlock( int from, int to,
double * d0, double * b0, double * c0, double * r0, int cnt );
/** check if two shots are close
* @param d1 first shot distance
* @param b1 first shot compass
* ...
* @return true if te two shots are close
*/
bool shotIsClose( double d1, double b1, double c1, double d2, double b2, double c2 );
/** create and insert a block
* @param from FROM index
* @param to TO index
* @param d0 distance(s)
* @param b0 compass(es)
* @param c0 clino(s)
* @param r0 roll(s)
* @param cnt number of shots of the block
* @param splay which station to attach if splay shot
* @param backward whether shot is backward
* @param last last block
* @param start first block
*
* @note this method handles the forward/backward of the shots (in the
* "backward" case the "from" and "to" are swapped), and when the
* shot is splay. Notice that with backward sighting a play shot
* at "to" means a splay at the sighting station, while a splay
* at "from" is a splay at the sighted station.
*/
void createBlock( int from, int to,
double * d0, double * b0, double * c0, double * r0, int cnt,
int splay, bool backward,
DBlock ** last, DBlock ** start );
void insertBlock( DBlock * bb, DBlock ** last, DBlock ** start )
{
if ( (*last) == NULL ) {
assert( head == NULL );
head = bb;
} else {
(*last)->next_block = bb;
}
if ( (*start) == NULL ) (*start) = bb;
(*last) = bb;
++ list_size;
if ( bb->count > 1) ++shot;
need_num = true;
}
public:
/** split a block into its blocklets
* @param bb block to split
*/
bool splitBlock( DBlock * bb );
/** merge a block with its following block
* @param bb block to merge with its following block
*/
bool mergeBlock( DBlock * bb );
/** check if there is a comment with a point
* @param name station name
* @return true if the point has a comment
*/
bool hasStationComment( const char * name ) const
{
return station_comment.find( name ) != station_comment.end();
}
/** get the comment of a point
* @param name station name
* @return the point comment
*/
const char * getStationComment( const char * name )
{
return station_comment[name].c_str();
}
/** set a point comment
* @param name station name
* @param c comment
*/
void setStationComment( const char * name, const char * c )
{
if ( strlen(c) == 0 ) {
std::map<std::string, std::string>::iterator it = station_comment.find( name );
if ( it != station_comment.end() )
station_comment.erase( it );
} else {
station_comment[name] = c;
}
}
/** recompute the values for the multimeasure blocks
* @param start where to start to recompute
*/
void recomputeMultimeasureBlocks( DBlock * start );
};
#endif