/
WallsWpjFile.ts
311 lines (286 loc) · 8.84 KB
/
WallsWpjFile.ts
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
import { UnitizedNumber, Length, Angle, Unit } from '@speleotica/unitized'
import { WallsSrvFile } from '../srv/WallsSrvFile'
export enum DisplayLatLongFormat {
Degrees,
DegreesMinutes,
DegreesMinutesSeconds,
}
// Georeference flags
// (from Walls source code: enum e_ref {REF_FMTDM=1,REF_FMTDMS=2,REF_FMTMASK=3,REF_LONDIR=4,REF_LATDIR=8})
export const FormatDegreesMinutes = 1 << 0
export const FormatDegreesMinutesSeconds = 1 << 1
export const WesternHemisphere = 1 << 2
export const SouthernHemisphere = 1 << 3
export type Georeference = {
displayLatLongFormat: DisplayLatLongFormat
utmZone: number
utmNorthing: UnitizedNumber<Length>
utmEasting: UnitizedNumber<Length>
utmConvergenceAngle: UnitizedNumber<Angle>
elevation: UnitizedNumber<Length>
latitude: UnitizedNumber<Angle>
longitude: UnitizedNumber<Angle>
wallsDatumIndex: number
datum: string
}
export function getGeoreferenceFlags({
displayLatLongFormat,
latitude,
longitude,
}: Georeference): number {
let flags = 0
if (displayLatLongFormat === DisplayLatLongFormat.DegreesMinutes)
flags |= FormatDegreesMinutes
else if (displayLatLongFormat === DisplayLatLongFormat.DegreesMinutesSeconds)
flags |= FormatDegreesMinutesSeconds
if (latitude.isNegative) flags |= SouthernHemisphere
if (longitude.isNegative) flags |= WesternHemisphere
return flags
}
export enum LaunchAction {
Properties,
Edit,
Open,
}
export enum View {
NorthOrEast,
NorthOrWest,
North,
East,
West,
}
// Suspiciously, the rightmost bit in the Walls source code (prjhier.h) is name
// defines segment. I guess the rightmost 3 bits get inserted by something else.
// status BITS
// 2^0 : Type = Book
// 2^1 : detached
// 2^2 : ?
// 2^3 : name defines segment
// 2^4 : 1 = Feet, 0 = Meters
// 2^5 : ? (FLG_WESTWARD in Walls source code, not sure if it's still used?)
// Use Georeference:
// 2^6 : 1 = no
// 2^7 : 1 = yes
// Derive decl from date:
// 2^8 : 1 = no
// 2^9 : 1 = yes
// UTM/GPS Grid-relative:
// 2^10: 1 = no
// 2^11: 1 = yes
// Preserve vertical shot orientation:
// 2^12: 1 = no
// 2^13: 1 = yes
// Preserve vertical shot length:
// 2^14: 1 = no
// 2^15: 1 = yes
// Other type
// 2^16: 1 = type is other (FLG_SURVEYNOT in Walls source code)
// 2^17: edit on launch
// 2^18: open on launch
// Default view after compilation (bits 21-19):
// 1: North or East
// 10: North or West
// 11: North
// 100: East
// 101: West
//
// 2^22: Process source SVG if one is attached
export const BookBit = 1 << 0
export const DetachedBit = 1 << 1
export const NameDefinesSegmentBit = 1 << 3
export const FeetBit = 1 << 4
export const DontUseGeoreferenceBit = 1 << 6
export const UseGeoreferenceBit = 1 << 7
export const DontDeriveDeclBit = 1 << 8
export const DeriveDeclBit = 1 << 9
export const NotGridRelativeBit = 1 << 10
export const GridRelativeBit = 1 << 11
export const DontPreserveVertShotOrientationBit = 1 << 12
export const PreserveVertShotOrientationBit = 1 << 13
export const DontPreserveVertShotLengthBit = 1 << 14
export const PreserveVertShotLengthBit = 1 << 15
export const OtherTypeBit = 1 << 16
export const EditOnLaunchBit = 1 << 17
export const OpenOnLaunchBit = 1 << 18
export const DefaultViewAfterCompilationMask = 7 << 19
export const NorthOrEastViewBits = 1 << 19
export const NorthOrWestViewBits = 2 << 19
export const NorthViewBits = 3 << 19
export const EastViewBits = 4 << 19
export const WestViewBits = 5 << 19
export const ProcessSvgIfAttachedBit = 1 << 22
export enum WallsProjectEntryType {
Book,
Survey,
Other,
}
interface WallsProjectEntryBase {
title: string
name?: string | null
path?: string | null
options?: string | null
georeference?: Georeference | null
detached: boolean
nameDefinesSegment: boolean
reviewDistanceUnit: Unit<Length>
useGeoreference?: boolean | null
deriveMagneticDeclination?: boolean | null
gridRelative?: boolean | null
preserveVertShotOrientation?: boolean | null
preserveVertShotLength?: boolean | null
launchAction: LaunchAction
defaultViewAfterCompilation?: View | null
processSvgIfAttached: boolean
}
export function getStatus(entry: WallsProjectEntry): number {
let result = 0
if (entry.type === WallsProjectEntryType.Book) result |= BookBit
if (entry.detached) result |= DetachedBit
if (entry.nameDefinesSegment) result |= NameDefinesSegmentBit
if (entry.reviewDistanceUnit === Length.feet) result |= FeetBit
if (entry.useGeoreference === false) result |= DontUseGeoreferenceBit
if (entry.useGeoreference === true) result |= UseGeoreferenceBit
if (entry.deriveMagneticDeclination === false) result |= DontDeriveDeclBit
if (entry.deriveMagneticDeclination === true) result |= DeriveDeclBit
if (entry.gridRelative === false) result |= NotGridRelativeBit
if (entry.gridRelative === true) result |= GridRelativeBit
if (entry.preserveVertShotOrientation === false)
result |= DontPreserveVertShotOrientationBit
if (entry.preserveVertShotOrientation === true)
result |= PreserveVertShotOrientationBit
if (entry.preserveVertShotLength === false)
result |= DontPreserveVertShotLengthBit
if (entry.preserveVertShotLength === true) result |= PreserveVertShotLengthBit
if (entry.type === WallsProjectEntryType.Other) result |= OtherTypeBit
if (entry.launchAction === LaunchAction.Edit) result |= EditOnLaunchBit
else if (entry.launchAction === LaunchAction.Open) result |= OpenOnLaunchBit
switch (entry.defaultViewAfterCompilation) {
case View.NorthOrEast:
result |= NorthOrEastViewBits
break
case View.NorthOrWest:
result |= NorthOrWestViewBits
break
case View.North:
result |= NorthViewBits
break
case View.East:
result |= EastViewBits
break
case View.West:
result |= WestViewBits
break
}
if (entry.processSvgIfAttached) result |= ProcessSvgIfAttachedBit
return result
}
type WallsProjectEntryRestOptions = {
options?: string | null
georeference?: Georeference | null
detached?: boolean | null
nameDefinesSegment?: boolean | null
reviewDistanceUnit?: Unit<Length> | null
useGeoreference?: boolean | null
deriveMagneticDeclination?: boolean | null
gridRelative?: boolean | null
preserveVertShotOrientation?: boolean | null
preserveVertShotLength?: boolean | null
launchAction?: LaunchAction | null
defaultViewAfterCompilation?: View | null
processSvgIfAttached?: boolean | null
}
type WallsProjectSurveyRestOptions = WallsProjectEntryRestOptions & {
content?: WallsSrvFile | null
}
export interface WallsProjectSurvey extends WallsProjectEntryBase {
type: WallsProjectEntryType.Survey
content?: WallsSrvFile | null
}
export const wallsProjectSurvey = (
title: string,
name?: string | null,
path?: string | null,
{
detached,
nameDefinesSegment,
reviewDistanceUnit,
launchAction,
processSvgIfAttached,
...rest
}: WallsProjectSurveyRestOptions = {}
): WallsProjectSurvey => ({
type: WallsProjectEntryType.Survey,
title,
name,
path,
...rest,
detached: detached || false,
nameDefinesSegment: nameDefinesSegment || false,
reviewDistanceUnit: reviewDistanceUnit || Length.meters,
launchAction: launchAction || LaunchAction.Properties,
processSvgIfAttached: processSvgIfAttached || false,
})
export interface WallsProjectOtherEntry extends WallsProjectEntryBase {
type: WallsProjectEntryType.Other
}
export const wallsProjectOtherEntry = (
title: string,
name?: string | null,
path?: string | null,
{
detached,
nameDefinesSegment,
reviewDistanceUnit,
launchAction,
processSvgIfAttached,
...rest
}: WallsProjectEntryRestOptions = {}
): WallsProjectOtherEntry => ({
type: WallsProjectEntryType.Other,
title,
name,
path,
...rest,
detached: detached || false,
nameDefinesSegment: nameDefinesSegment || false,
reviewDistanceUnit: reviewDistanceUnit || Length.meters,
launchAction: launchAction || LaunchAction.Properties,
processSvgIfAttached: processSvgIfAttached || false,
})
export interface WallsProjectBook extends WallsProjectEntryBase {
type: WallsProjectEntryType.Book
children: WallsProjectEntry[]
}
export const wallsProjectBook = (
title: string,
name?: string | null,
path?: string | null,
children: WallsProjectEntry[] = [],
{
detached,
nameDefinesSegment,
reviewDistanceUnit,
launchAction,
processSvgIfAttached,
...rest
}: WallsProjectEntryRestOptions = {}
): WallsProjectBook => ({
type: WallsProjectEntryType.Book,
title,
name,
path,
children,
...rest,
detached: detached || false,
nameDefinesSegment: nameDefinesSegment || false,
reviewDistanceUnit: reviewDistanceUnit || Length.meters,
launchAction: launchAction || LaunchAction.Properties,
processSvgIfAttached: processSvgIfAttached || false,
})
export type WallsProjectEntry =
| WallsProjectSurvey
| WallsProjectOtherEntry
| WallsProjectBook
export type WallsWpjFile = {
root: WallsProjectBook
}