-
Notifications
You must be signed in to change notification settings - Fork 0
/
aeroCADFileIO.m
87 lines (68 loc) · 1.64 KB
/
aeroCADFileIO.m
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
//
// aeroCADFileIO.m
// aeroCAD
//
// Created by Jeff Glaum on 7/10/10.
// Copyright 2010 Jeff Glaum. All rights reserved.
//
#import "aeroCADFileIO.h"
#import "aeroCADTypes.h"
@implementation aeroCADFileIO
-(NSString *) getFileName
{
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseFiles:YES];
[openDlg setCanChooseDirectories:NO];
if ([openDlg runModal] == NSModalResponseOK)
{
for(NSURL* URL in [openDlg URLs])
{
return [URL path];
}
}
return NULL;
}
- (aeroCADCurve *) readCurveDataFile:(NSString *) fileName
{
BOOL setStartPoint = FALSE;
FILE *fp;
char line[FILE_MAX_LINE_LEN];
aeroCADCurve *curve = NULL;
POINT3D pt = {0.0f, 0.0f, 0.0f, 1.0f};
// Open the curve pointset data file
//
if (NULL == (fp = fopen([fileName UTF8String], "rt")))
return NULL;
// Skip the first line - airfoil/curve name
//
fgets(line, FILE_MAX_LINE_LEN, fp);
// Allocate a new curve object
//
curve = [[aeroCADCurve alloc] init: CURVE_TYPE_LINE];
while ((fgets(line, FILE_MAX_LINE_LEN, fp)) != NULL)
{
// Skip comments
//
if('#' == line[0])
continue;
// Extract the curve's X and Y points (floats)
//
sscanf(line, " %f %f\n", &pt.pt.x, &pt.pt.y);
// Add the point/segment to the curve
//
if (FALSE == setStartPoint)
{
[curve setStartPoint: pt];
setStartPoint = TRUE;
}
else
{
[curve appendSegment: pt];
}
}
// Close the curve file
//
fclose(fp);
return curve;
}
@end