2006-03-22 20:25:58 +00:00
|
|
|
|
2006-03-16 16:24:52 +00:00
|
|
|
# maximum speed -----------------------------------------------------------------------------------
|
2006-03-15 14:27:47 +00:00
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
|
2006-03-15 00:29:53 +00:00
|
|
|
var maxspeed = props.globals.getNode("engines/engine/speed-max-mps");
|
2007-02-26 17:57:55 +00:00
|
|
|
var speed = [10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000];
|
2006-03-15 00:29:53 +00:00
|
|
|
var current = 7;
|
|
|
|
|
|
|
|
|
|
|
|
controls.flapsDown = func(x) {
|
|
|
|
if (!x) {
|
|
|
|
return;
|
|
|
|
} elsif (x < 0 and current > 0) {
|
|
|
|
current -= 1;
|
|
|
|
} elsif (x > 0 and current < size(speed) - 1) {
|
|
|
|
current += 1;
|
|
|
|
}
|
|
|
|
var s = speed[current];
|
|
|
|
maxspeed.setDoubleValue(s);
|
2006-03-22 20:25:58 +00:00
|
|
|
gui.popupTip("Max. Speed " ~ s ~ " m/s");
|
2006-03-15 00:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-03-16 16:24:52 +00:00
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
|
|
|
|
# library stuff -----------------------------------------------------------------------------------
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var EPSILON = 0.0000000000001;
|
2006-04-24 20:34:59 +00:00
|
|
|
var ERAD = 6378138.12; # Earth radius (m)
|
2006-03-22 20:25:58 +00:00
|
|
|
var D2R = math.pi / 180;
|
|
|
|
var R2D = 180 / math.pi;
|
2007-02-26 17:57:55 +00:00
|
|
|
var FT2M = 0.3048;
|
|
|
|
var M2FT = 3.28083989501312335958;
|
2006-03-16 16:24:52 +00:00
|
|
|
|
2006-03-15 00:29:53 +00:00
|
|
|
|
2007-02-24 19:48:02 +00:00
|
|
|
var printf = func(_...) { print(call(sprintf, _)) }
|
|
|
|
var floor = func(v) { v < 0.0 ? -int(-v) - 1 : int(v) }
|
|
|
|
var ceil = func(v) { -floor(-v) }
|
|
|
|
var pow = func(v, w) { v < 0 ? nil : v ? math.exp(math.ln(v) * w) : 0 }
|
|
|
|
var pow2 = func(e) { e ? 2 * pow2(e - 1) : 1 }
|
|
|
|
var sin = math.sin;
|
|
|
|
var cos = math.cos;
|
|
|
|
var atan2 = math.atan2;
|
|
|
|
var sqrt = math.sqrt;
|
|
|
|
var asin = func(v) { math.atan2(v, math.sqrt(1 - v * v)) }
|
|
|
|
var acos = func(v) { math.atan2(math.sqrt(1 - v * v), v) }
|
|
|
|
var mod = func(v, w) {
|
|
|
|
var x = v - w * int(v / w);
|
|
|
|
return x < 0 ? x + abs(w) : x;
|
|
|
|
}
|
2006-03-22 20:25:58 +00:00
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
# class that maintains one set of geographical coordinates and provides
|
|
|
|
# simple conversion methods that assume a spherical Earth
|
2006-03-22 20:25:58 +00:00
|
|
|
#
|
2007-02-26 17:57:55 +00:00
|
|
|
var Coord = {
|
|
|
|
new : func(copy = nil) {
|
|
|
|
var m = { parents: [Coord] };
|
|
|
|
m._pdirty = 1; # polar
|
|
|
|
m._cdirty = 1; # cartesian
|
|
|
|
m._lon = nil; # in radian
|
|
|
|
m._lat = nil;
|
|
|
|
m._alt = nil; # ASL
|
|
|
|
m._x = nil; # in m
|
|
|
|
m._y = nil;
|
|
|
|
m._z = nil;
|
|
|
|
if (copy != nil) {
|
|
|
|
m.set(copy);
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
},
|
|
|
|
_cupdate : func {
|
|
|
|
me._cdirty or return;
|
|
|
|
var rad = ERAD + me._alt;
|
|
|
|
var cosphi = cos(me._lat) * rad;
|
|
|
|
me._x = cosphi * cos(me._lon);
|
|
|
|
me._y = cosphi * sin(me._lon);
|
|
|
|
me._z = sin(me._lat) * rad;
|
|
|
|
me._cdirty = 0;
|
|
|
|
},
|
|
|
|
_pupdate : func {
|
|
|
|
me._pdirty or return;
|
|
|
|
me._lat = atan2(me._z, sqrt(me._x * me._x + me._y * me._y));
|
|
|
|
me._lon = atan2(me._y, me._x);
|
|
|
|
me._alt = sqrt(me._x * me._x + me._y * me._y + me._z * me._z) - ERAD;
|
|
|
|
me._pdirty = 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
x : func { me._cupdate(); me._x },
|
|
|
|
y : func { me._cupdate(); me._y },
|
|
|
|
z : func { me._cupdate(); me._z },
|
|
|
|
xyz : func { me._cupdate(); [me._x, me._y, me._z] },
|
|
|
|
|
|
|
|
lon : func { me._pupdate(); me._lon * R2D }, # return in degree
|
|
|
|
lat : func { me._pupdate(); me._lat * R2D },
|
|
|
|
alt : func { me._pupdate(); me._alt },
|
|
|
|
lonlat : func { me._pupdate(); [me._lon, me._lat, me._alt] },
|
|
|
|
|
|
|
|
set_x : func(x) { me._pupdate(); me._pdirty = 1; me._x = x; me },
|
|
|
|
set_y : func(y) { me._pupdate(); me._pdirty = 1; me._y = y; me },
|
|
|
|
set_z : func(z) { me._pupdate(); me._pdirty = 1; me._z = z; me },
|
|
|
|
|
|
|
|
set_lon : func(lon) { me._cupdate(); me._cdirty = 1; me._lon = lon * D2R; me },
|
|
|
|
set_lat : func(lat) { me._cupdate(); me._cdirty = 1; me._lat = lat * D2R; me },
|
|
|
|
set_alt : func(alt) { me._cupdate(); me._cdirty = 1; me._alt = alt; me },
|
|
|
|
|
|
|
|
set : func(c) {
|
2007-02-27 15:39:49 +00:00
|
|
|
c._pupdate();
|
|
|
|
me._lon = c._lon;
|
|
|
|
me._lat = c._lat;
|
|
|
|
me._alt = c._alt;
|
2007-02-26 17:57:55 +00:00
|
|
|
me._cdirty = 1;
|
|
|
|
me._pdirty = 0;
|
|
|
|
me;
|
|
|
|
},
|
|
|
|
set_lonlat : func(lon, lat, alt = 0) {
|
|
|
|
me._lon = lon * D2R;
|
|
|
|
me._lat = lat * D2R;
|
|
|
|
me._alt = alt;
|
|
|
|
me._cdirty = 1;
|
|
|
|
me._pdirty = 0;
|
|
|
|
me;
|
|
|
|
},
|
|
|
|
set_xyz : func(x, y, z) {
|
|
|
|
me._x = x;
|
|
|
|
me._y = y;
|
|
|
|
me._z = z;
|
|
|
|
me._pdirty = 1;
|
|
|
|
me._cdirty = 0;
|
|
|
|
me;
|
|
|
|
},
|
|
|
|
apply_course_distance : func(course, dist) {
|
|
|
|
me._pupdate();
|
|
|
|
course *= D2R;
|
|
|
|
dist /= ERAD;
|
|
|
|
me._lat = asin(sin(me._lat) * cos(dist) + cos(me._lat) * sin(dist) * cos(course));
|
|
|
|
|
|
|
|
if (cos(me._lat) > EPSILON) {
|
|
|
|
me._lon = math.pi - mod(math.pi - me._lon - asin(sin(course) * sin(dist)
|
|
|
|
/ cos(me._lat)), 2 * math.pi);
|
|
|
|
}
|
|
|
|
me._cdirty = 1;
|
|
|
|
me;
|
|
|
|
},
|
|
|
|
course_to : func(dest) {
|
|
|
|
me._pupdate();
|
|
|
|
dest._pupdate();
|
2006-03-22 20:25:58 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
if (me._lon == dest._lon and me._lat == dest._lat) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
var dlon = dest._lon - me._lon;
|
|
|
|
return mod(atan2(sin(dlon) * cos(dest._lat), cos(me._lat) * sin(dest._lat)
|
|
|
|
- sin(me._lat) * cos(dest._lat) * cos(dlon)), 2 * math.pi) * R2D;
|
|
|
|
},
|
|
|
|
# arc distance on an earth sphere; doesn't consider altitude
|
|
|
|
distance_to : func(dest) {
|
|
|
|
me._pupdate();
|
|
|
|
dest._pupdate();
|
2006-03-22 20:25:58 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
if (me._lon == dest._lon and me._lat == dest._lat) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
var o = sin((me._lon - dest._lon) * 0.5);
|
|
|
|
var a = sin((me._lat - dest._lat) * 0.5);
|
|
|
|
return 2.0 * ERAD * asin(sqrt(a * a + cos(me._lat) * cos(dest._lat) * o * o));
|
|
|
|
},
|
|
|
|
direct_distance_to : func(dest) {
|
|
|
|
me._cupdate();
|
|
|
|
dest._cupdate();
|
|
|
|
var dx = dest._x - me._x;
|
|
|
|
var dy = dest._y - me._y;
|
|
|
|
var dz = dest._z - me._z;
|
|
|
|
return sqrt(dx * dx + dy * dy + dz * dz);
|
|
|
|
},
|
|
|
|
dump : func {
|
|
|
|
if (me._cdirty and me._pdirty) {
|
|
|
|
print("Coord.print(): coord undefined");
|
|
|
|
}
|
|
|
|
me._cupdate();
|
|
|
|
me._pupdate();
|
|
|
|
printf("x=%f y=%f z=%f lon=%f lat=%f alt=%f",
|
|
|
|
me.x(), me.y(), me.z(), me.lon(), me.lat(), me.alt());
|
|
|
|
},
|
|
|
|
};
|
2006-03-22 20:25:58 +00:00
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
|
|
|
|
var init_prop = func(prop, value) {
|
|
|
|
if (prop.getValue() != nil) {
|
|
|
|
value = prop.getValue();
|
|
|
|
}
|
|
|
|
prop.setDoubleValue(value);
|
|
|
|
return value;
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# sort vector of strings (bubblesort)
|
|
|
|
#
|
2007-02-26 17:57:55 +00:00
|
|
|
var sort = func(l) {
|
2006-03-22 20:25:58 +00:00
|
|
|
while (1) {
|
|
|
|
var n = 0;
|
|
|
|
for (var i = 0; i < size(l) - 1; i += 1) {
|
|
|
|
if (cmp(l[i], l[i + 1]) > 0) {
|
|
|
|
var t = l[i + 1];
|
|
|
|
l[i + 1] = l[i];
|
|
|
|
l[i] = t;
|
|
|
|
n += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!n) {
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-24 00:20:22 +00:00
|
|
|
# binary search of string in sorted vector; returns index or -1 if not found
|
|
|
|
#
|
2007-02-26 17:57:55 +00:00
|
|
|
var search = func(list, which) {
|
2006-03-24 00:20:22 +00:00
|
|
|
var left = 0;
|
|
|
|
var right = size(list);
|
|
|
|
var middle = nil;
|
|
|
|
while (1) {
|
|
|
|
middle = int((left + right) / 2);
|
|
|
|
var c = cmp(list[middle], which);
|
|
|
|
if (!c) {
|
|
|
|
return middle;
|
|
|
|
} elsif (left == middle) {
|
|
|
|
return -1;
|
|
|
|
} elsif (c > 0) {
|
|
|
|
right = middle;
|
2006-04-12 00:00:59 +00:00
|
|
|
} else {
|
2006-03-24 00:20:22 +00:00
|
|
|
left = middle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-31 17:12:32 +00:00
|
|
|
# scan all objects in subdir of $FG_ROOT. (Prefer *.xml files to *.ac files
|
|
|
|
# if both exist)
|
2006-03-22 20:25:58 +00:00
|
|
|
#
|
2007-02-26 17:57:55 +00:00
|
|
|
var scan_models = func(base) {
|
2006-03-22 20:25:58 +00:00
|
|
|
var result = [];
|
|
|
|
var list = directory(getprop("/sim/fg-root") ~ "/" ~ base);
|
|
|
|
if (list == nil) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
var xml = {};
|
|
|
|
var ac = {};
|
|
|
|
foreach (var d; list) {
|
|
|
|
if (d[0] != `.` and d != "CVS") {
|
|
|
|
if (substr(d, size(d) - 4) == ".xml") {
|
|
|
|
xml[base ~ "/" ~ d] = 1;
|
|
|
|
} elsif (substr(d, size(d) - 3) == ".ac") {
|
|
|
|
ac[base ~ "/" ~ d] = 1;
|
|
|
|
} else {
|
|
|
|
foreach (var s; scan_models(base ~ "/" ~ d)) {
|
|
|
|
append(result, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (var m; keys(xml)) {
|
|
|
|
append(result, m);
|
2006-04-24 20:34:59 +00:00
|
|
|
delete(ac, substr(m, 0, size(m) - 3) ~ "ac");
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
foreach (var m; keys(ac)) {
|
|
|
|
append(result, m);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2006-03-15 00:29:53 +00:00
|
|
|
|
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
# normalize degree to 0 <= angle < 360
|
|
|
|
#
|
2007-02-26 17:57:55 +00:00
|
|
|
var normdeg = func(angle) {
|
2006-03-15 00:29:53 +00:00
|
|
|
while (angle < 0) {
|
|
|
|
angle += 360;
|
|
|
|
}
|
|
|
|
while (angle >= 360) {
|
|
|
|
angle -= 360;
|
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
return angle;
|
2006-03-15 00:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var bucket_span = func(lat) {
|
2006-03-15 14:27:47 +00:00
|
|
|
if (lat >= 89.0 ) {
|
|
|
|
360.0;
|
|
|
|
} elsif (lat >= 88.0 ) {
|
|
|
|
8.0;
|
|
|
|
} elsif (lat >= 86.0 ) {
|
|
|
|
4.0;
|
|
|
|
} elsif (lat >= 83.0 ) {
|
|
|
|
2.0;
|
|
|
|
} elsif (lat >= 76.0 ) {
|
|
|
|
1.0;
|
|
|
|
} elsif (lat >= 62.0 ) {
|
|
|
|
0.5;
|
|
|
|
} elsif (lat >= 22.0 ) {
|
|
|
|
0.25;
|
|
|
|
} elsif (lat >= -22.0 ) {
|
|
|
|
0.125;
|
|
|
|
} elsif (lat >= -62.0 ) {
|
|
|
|
0.25;
|
|
|
|
} elsif (lat >= -76.0 ) {
|
|
|
|
0.5;
|
|
|
|
} elsif (lat >= -83.0 ) {
|
|
|
|
1.0;
|
|
|
|
} elsif (lat >= -86.0 ) {
|
|
|
|
2.0;
|
|
|
|
} elsif (lat >= -88.0 ) {
|
|
|
|
4.0;
|
|
|
|
} elsif (lat >= -89.0 ) {
|
|
|
|
8.0;
|
|
|
|
} else {
|
|
|
|
360.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var tile_index = func(lon, lat) {
|
2006-03-23 16:16:44 +00:00
|
|
|
var lon_floor = floor(lon);
|
|
|
|
var lat_floor = floor(lat);
|
|
|
|
var span = bucket_span(lat);
|
|
|
|
var x = 0;
|
2006-03-15 14:27:47 +00:00
|
|
|
|
|
|
|
if (span < 0.0000001) {
|
|
|
|
lon = 0;
|
|
|
|
} elsif (span <= 1.0) {
|
|
|
|
x = int((lon - lon_floor) / span);
|
|
|
|
} else {
|
|
|
|
if (lon >= 0) {
|
|
|
|
lon = int(int(lon / span) * span);
|
|
|
|
} else {
|
|
|
|
lon = int(int((lon + 1) / span) * span - span);
|
|
|
|
if (lon < -180) {
|
|
|
|
lon = -180;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-23 16:16:44 +00:00
|
|
|
var y = int((lat - lat_floor) * 8);
|
2006-03-15 14:27:47 +00:00
|
|
|
(lon_floor + 180) * 16384 + (lat_floor + 90) * 64 + y * 8 + x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var format = func(lon, lat) {
|
2006-03-23 16:16:44 +00:00
|
|
|
sprintf("%s%03d%s%02d", lon < 0 ? "w" : "e", abs(lon), lat < 0 ? "s" : "n", abs(lat));
|
2006-03-15 14:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var tile_path = func(lon, lat) {
|
2006-03-23 16:16:44 +00:00
|
|
|
var p = format(floor(lon / 10.0) * 10, floor(lat / 10.0) * 10);
|
|
|
|
p ~= "/" ~ format(floor(lon), floor(lat));
|
|
|
|
p ~= "/" ~ tile_index(lon, lat) ~ ".stg";
|
|
|
|
}
|
2006-03-22 20:25:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
# -------------------------------------------------------------------------------------------------
|
2006-03-22 20:25:58 +00:00
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
# loop that generates the model flashing pulse
|
2006-04-16 08:09:28 +00:00
|
|
|
#
|
2007-02-26 17:57:55 +00:00
|
|
|
var clock = 0;
|
|
|
|
var clock_loop = func {
|
|
|
|
clock = !clock;
|
|
|
|
settimer(clock_loop, 0.3);
|
|
|
|
}
|
|
|
|
clock_loop();
|
2006-03-15 14:27:47 +00:00
|
|
|
|
|
|
|
|
2007-02-27 15:39:49 +00:00
|
|
|
var ufo_position = func {
|
|
|
|
var lon = getprop("/position/longitude-deg");
|
|
|
|
var lat = getprop("/position/latitude-deg");
|
|
|
|
var alt = getprop("/position/altitude-ft") * FT2M;
|
|
|
|
Coord.new().set_lonlat(lon, lat, alt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
# class that maintains one adjustable model property (see src/Model/modelmgr.cxx)
|
|
|
|
#
|
|
|
|
var ModelValue = {
|
|
|
|
new : func(base, name, value) {
|
|
|
|
var m = { parents: [ModelValue] };
|
|
|
|
m.propN = base.getNode(name, 1);
|
|
|
|
m.propN.setDoubleValue(value);
|
|
|
|
base.getNode(name ~ "-prop", 1).setValue(m.propN.getPath());
|
2006-03-15 14:27:47 +00:00
|
|
|
return m;
|
|
|
|
},
|
|
|
|
set : func(v) {
|
2007-02-26 17:57:55 +00:00
|
|
|
me.propN.setDoubleValue(v);
|
2006-03-15 14:27:47 +00:00
|
|
|
},
|
|
|
|
get : func {
|
2007-02-26 17:57:55 +00:00
|
|
|
me.propN.getValue();
|
2006-03-15 14:27:47 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
# class that maintains one scenery object (see src/Model/modelmgr.cxx)
|
2006-04-16 08:09:28 +00:00
|
|
|
#
|
2007-02-26 17:57:55 +00:00
|
|
|
var Model = {
|
|
|
|
new : func(path, pos, data = nil) {
|
|
|
|
var m = { parents: [Model] };
|
|
|
|
m.pos = pos;
|
|
|
|
m.path = path;
|
|
|
|
m.selected = 1;
|
|
|
|
m.visible = 1;
|
|
|
|
m.flash_until = 0;
|
|
|
|
m.loopid = 0;
|
|
|
|
m.elapsedN = props.globals.getNode("/sim/time/elapsed-sec", 1);
|
|
|
|
|
|
|
|
var models = props.globals.getNode("/models", 1);
|
|
|
|
for (var i = 0; 1; i += 1) {
|
|
|
|
if (models.getChild("model", i, 0) == nil) {
|
|
|
|
m.node = models.getChild("model", i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m.node.getNode("legend", 1).setValue("");
|
|
|
|
if (isa(data, props.Node)) {
|
|
|
|
props.copy(data, m.node); # import node
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
var hdg = init_prop(m.node.getNode("heading-deg", 1), 0);
|
|
|
|
var pitch = init_prop(m.node.getNode("pitch-deg", 1), 0);
|
|
|
|
var roll = init_prop(m.node.getNode("roll-deg", 1), 0);
|
|
|
|
|
|
|
|
m.node.getNode("path", 1).setValue(path);
|
|
|
|
m.lon = ModelValue.new(m.node, "longitude-deg", pos.lon());
|
|
|
|
m.lat = ModelValue.new(m.node, "latitude-deg", pos.lat());
|
|
|
|
m.alt = ModelValue.new(m.node, "elevation-ft", pos.alt() * M2FT);
|
|
|
|
m.hdg = ModelValue.new(m.node, "heading-deg", hdg);
|
|
|
|
m.pitch = ModelValue.new(m.node, "pitch-deg", pitch);
|
|
|
|
m.roll = ModelValue.new(m.node, "roll-deg", roll);
|
|
|
|
|
|
|
|
m.node.getNode("load", 1).setValue(1);
|
|
|
|
m.node.removeChildren("load");
|
|
|
|
return m;
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
remove : func {
|
|
|
|
props.globals.getNode("/models", 1).removeChild("model", me.node.getIndex());
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
clone : func(path) {
|
|
|
|
Model.new(path, me.pos, me.node);
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-27 15:39:49 +00:00
|
|
|
move : func(pos) {
|
|
|
|
var v = me.visible;
|
|
|
|
me.unhide();
|
|
|
|
me.pos.set(pos);
|
|
|
|
me.lon.set(me.pos.lon());
|
|
|
|
me.lat.set(me.pos.lat());
|
|
|
|
me.alt.set(me.pos.alt() * M2FT);
|
|
|
|
v or me.hide();
|
|
|
|
},
|
|
|
|
raise : func (dist) {
|
|
|
|
var v = me.visible;
|
|
|
|
me.unhide();
|
|
|
|
me.pos.set_alt(me.pos.alt() + dist);
|
|
|
|
me.alt.set(me.pos.alt() * M2FT);
|
|
|
|
v or me.hide();
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
apply_course_distance : func(course, dist) {
|
|
|
|
me.pos.apply_course_distance(course, dist);
|
|
|
|
me.lon.set(me.pos.lon());
|
|
|
|
me.lat.set(me.pos.lat());
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-27 15:39:49 +00:00
|
|
|
direct_distance_to : func(dest) {
|
|
|
|
me.pos.direct_distance_to(dest);
|
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
flash : func(v) {
|
|
|
|
me.loopid += 1;
|
|
|
|
if (v) {
|
|
|
|
me.flash_until = me.elapsedN.getValue() + 2;
|
|
|
|
me._flash_(me.loopid);
|
|
|
|
} else {
|
|
|
|
me.unhide();
|
2006-03-24 15:33:06 +00:00
|
|
|
}
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
_flash_ : func(id) {
|
|
|
|
id == me.loopid or return;
|
|
|
|
if (me.elapsedN.getValue() > me.flash_until) {
|
|
|
|
return me.unhide();
|
|
|
|
} elsif (clock) {
|
|
|
|
me.hide();
|
|
|
|
} else {
|
|
|
|
me.unhide();
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
settimer(func { me._flash_(id) }, 0);
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
hide : func {
|
|
|
|
me.visible or return;
|
|
|
|
me.alt.set(me.alt.get() - ERAD);
|
|
|
|
me.visible = 0;
|
2006-03-15 14:27:47 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
unhide : func {
|
|
|
|
me.visible and return;
|
|
|
|
me.alt.set(me.alt.get() + ERAD);
|
|
|
|
me.visible = 1;
|
2006-03-24 15:33:06 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
get_data : func {
|
|
|
|
var n = props.Node.new();
|
|
|
|
props.copy(me.node, n);
|
|
|
|
me.add_derived_data(n);
|
|
|
|
return n;
|
2006-03-15 14:27:47 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
add_derived_data : func(node) {
|
|
|
|
node.removeChildren("longitude-deg-prop");
|
|
|
|
node.removeChildren("latitude-deg-prop");
|
|
|
|
node.removeChildren("elevation-ft-prop");
|
|
|
|
node.removeChildren("heading-deg-prop");
|
|
|
|
node.removeChildren("pitch-deg-prop");
|
|
|
|
node.removeChildren("roll-deg-prop");
|
2006-03-22 20:25:58 +00:00
|
|
|
|
|
|
|
var path = node.getNode("path").getValue();
|
|
|
|
var lon = node.getNode("longitude-deg").getValue();
|
|
|
|
var lat = node.getNode("latitude-deg").getValue();
|
|
|
|
var elev = node.getNode("elevation-ft").getValue();
|
|
|
|
var hdg = node.getNode("heading-deg").getValue();
|
2007-02-26 17:57:55 +00:00
|
|
|
var legend = node.getNode("legend").getValue();
|
2006-04-14 14:58:08 +00:00
|
|
|
var type = nil;
|
|
|
|
var spec = "";
|
|
|
|
|
|
|
|
if (path == "Aircraft/ufo/Models/sign.ac") {
|
|
|
|
type = "OBJECT_SIGN";
|
2007-02-26 17:57:55 +00:00
|
|
|
if (legend == "") {
|
|
|
|
legend = "{@size=10,@material=RedSign}NO_CONTENTS_" ~ int(10000 * rand());
|
|
|
|
}
|
2006-04-14 14:58:08 +00:00
|
|
|
foreach (var c; split('', legend)) {
|
2006-04-16 22:05:59 +00:00
|
|
|
if (c != ' ') {
|
|
|
|
spec ~= c;
|
|
|
|
}
|
2006-04-14 14:58:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
type = "OBJECT_SHARED";
|
|
|
|
spec = path;
|
|
|
|
}
|
2006-03-22 20:25:58 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var elev_m = elev * FT2M;
|
2006-03-22 20:25:58 +00:00
|
|
|
var stg_hdg = normdeg(360 - hdg);
|
|
|
|
var stg_path = tile_path(lon, lat);
|
|
|
|
var abs_path = getprop("/sim/fg-root") ~ "/" ~ path;
|
2006-04-24 20:34:59 +00:00
|
|
|
var obj_line = sprintf("%s %s %.8f %.8f %.4f %.1f", type, spec, lon, lat, elev_m, stg_hdg);
|
2006-03-22 20:25:58 +00:00
|
|
|
|
|
|
|
node.getNode("absolute-path", 1).setValue(abs_path);
|
2007-02-26 17:57:55 +00:00
|
|
|
node.getNode("legend", 1).setValue(legend);
|
2006-03-22 20:25:58 +00:00
|
|
|
node.getNode("stg-path", 1).setValue(stg_path);
|
|
|
|
node.getNode("stg-heading-deg", 1).setDoubleValue(stg_hdg);
|
2006-04-24 20:34:59 +00:00
|
|
|
node.getNode("elevation-m", 1).setDoubleValue(elev_m);
|
2007-02-26 17:57:55 +00:00
|
|
|
node.getNode("object-line", 1).setValue(obj_line);
|
|
|
|
return node;
|
2006-04-15 20:21:41 +00:00
|
|
|
},
|
2006-03-15 14:27:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var ModelMgr = {
|
2006-03-22 20:25:58 +00:00
|
|
|
new : func(path) {
|
|
|
|
var m = { parents: [ModelMgr] };
|
2007-02-26 17:57:55 +00:00
|
|
|
m.active = nil;
|
|
|
|
m.models = [];
|
|
|
|
m.legendN = props.globals.getNode("/sim/gui/dialogs/ufo-status/input", 1);
|
|
|
|
m.legendN.setValue("");
|
|
|
|
m.mouse_coord = ufo_position();
|
|
|
|
m.import();
|
2007-02-27 22:56:22 +00:00
|
|
|
m.marker = Model.new("Aircraft/ufo/Models/marker.ac", Coord.new().set_xyz(0, 0, 0));
|
|
|
|
m.marker.hide();
|
2006-03-22 20:25:58 +00:00
|
|
|
m.modelpath = path;
|
2006-03-15 14:27:47 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
if (path != "Aircraft/ufo/Models/cursor.ac") {
|
|
|
|
status_dialog.open();
|
|
|
|
}
|
2006-03-22 20:25:58 +00:00
|
|
|
return m;
|
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
click : func(mouse_coord) {
|
|
|
|
me.mouse_coord = mouse_coord;
|
2007-02-24 19:48:02 +00:00
|
|
|
status_dialog.open();
|
2007-02-26 17:57:55 +00:00
|
|
|
adjust_dialog.center_sliders();
|
|
|
|
|
|
|
|
if (KbdAlt.getBoolValue()) { # move active object here (and other selected ones along with it)
|
|
|
|
(me.active == nil) and return;
|
|
|
|
var course = me.active.pos.course_to(me.mouse_coord);
|
|
|
|
var distance = me.active.pos.distance_to(me.mouse_coord);
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
m.pos.set_alt(me.mouse_coord.alt());
|
|
|
|
m.selected and m.apply_course_distance(course, distance);
|
|
|
|
}
|
2007-02-27 22:56:22 +00:00
|
|
|
me.marker.move(me.active.pos);
|
2007-02-26 17:57:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-06-05 16:33:39 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
if (!KbdShift.getBoolValue()) {
|
|
|
|
me.deselect_all();
|
|
|
|
}
|
2006-06-05 16:33:39 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
if (KbdCtrl.getBoolValue()) { # select existing object
|
|
|
|
me.select();
|
|
|
|
} else { # add one new object
|
|
|
|
me.active = Model.new(me.modelpath, mouse_coord, me.sticky_data());
|
|
|
|
append(me.models, me.active);
|
|
|
|
me.display_status(me.modelpath);
|
2007-02-27 22:56:22 +00:00
|
|
|
me.marker.move(me.active.pos);
|
2007-02-26 17:57:55 +00:00
|
|
|
|
|
|
|
if (KbdShift.getBoolValue()) {
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
m.flash(m.selected);
|
|
|
|
}
|
|
|
|
}
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
select : func() {
|
|
|
|
if (!size(me.models)) {
|
|
|
|
me.active = nil;
|
2007-02-27 22:56:22 +00:00
|
|
|
me.marker.move(Coord.new().set_xyz(0, 0, 0));
|
2007-02-26 17:57:55 +00:00
|
|
|
return;
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
var min_dist = 10 * ERAD;
|
2006-03-22 20:25:58 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
forindex (var i; me.models) {
|
|
|
|
var dist = me.models[i].direct_distance_to(me.mouse_coord);
|
2006-03-22 20:25:58 +00:00
|
|
|
if (dist < min_dist) {
|
|
|
|
min_dist = dist;
|
2007-02-26 17:57:55 +00:00
|
|
|
me.active = me.models[i];
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
me.active.selected = 1;
|
2007-02-27 22:56:22 +00:00
|
|
|
me.marker.move(me.active.pos);
|
2007-02-26 17:57:55 +00:00
|
|
|
foreach (var m; me.models) {
|
|
|
|
m.flash(m.selected);
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
me.display_status(me.modelpath = me.active.path);
|
|
|
|
},
|
|
|
|
deselect_all : func {
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
m.flash(m.selected = 0);
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
remove_selected : func {
|
2007-02-26 17:57:55 +00:00
|
|
|
var models = [];
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
if (m.selected) {
|
|
|
|
m.remove();
|
|
|
|
} else {
|
|
|
|
append(models, m);
|
|
|
|
}
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
me.models = models;
|
|
|
|
me.select();
|
|
|
|
me.display_status(me.modelpath);
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
set_modelpath : func(path) {
|
2006-03-22 20:25:58 +00:00
|
|
|
me.modelpath = path;
|
2006-03-25 18:30:32 +00:00
|
|
|
me.display_status(path);
|
|
|
|
},
|
2007-02-26 17:57:55 +00:00
|
|
|
update_legend : func {
|
|
|
|
if (me.active != nil) {
|
|
|
|
me.active.node.getNode("legend", 1).setValue(me.legendN.getValue());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
display_status : func(path) {
|
|
|
|
var legend = me.active == nil ? "" : me.active.node.getNode("legend", 1).getValue();
|
|
|
|
me.legendN.setValue(legend);
|
|
|
|
setprop("/sim/model/ufo/status", "(" ~ size(me.models) ~ ") " ~ path);
|
2006-03-22 20:25:58 +00:00
|
|
|
},
|
|
|
|
get_data : func {
|
|
|
|
var n = props.Node.new();
|
2007-02-26 17:57:55 +00:00
|
|
|
forindex (var i; me.models) {
|
|
|
|
props.copy(me.models[i].get_data(), n.getChild("model", i, 1));
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
return n;
|
|
|
|
},
|
2006-03-24 00:20:22 +00:00
|
|
|
cycle : func(up) {
|
|
|
|
var i = search(modellist, me.modelpath) + up;
|
|
|
|
if (i < 0) {
|
|
|
|
i = size(modellist) - 1;
|
|
|
|
} elsif (i >= size(modellist)) {
|
|
|
|
i = 0;
|
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
me.set_modelpath(modellist[i]);
|
|
|
|
|
|
|
|
var models = [];
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
if (m.selected) {
|
|
|
|
append(models, m.clone(modellist[i]));
|
|
|
|
m.remove();
|
|
|
|
} else {
|
|
|
|
append(models, m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
me.models = models;
|
|
|
|
},
|
|
|
|
sticky_data : func {
|
|
|
|
var n = props.Node.new();
|
2007-02-27 15:39:49 +00:00
|
|
|
if (me.active == nil) {
|
|
|
|
return n;
|
|
|
|
}
|
2007-02-26 17:57:55 +00:00
|
|
|
var hdg = n.getNode("heading-deg", 1);
|
|
|
|
var pitch = n.getNode("pitch-deg", 1);
|
|
|
|
var roll = n.getNode("roll-deg", 1);
|
|
|
|
if (getprop("/models/adjust/sticky-heading")) {
|
|
|
|
hdg.setDoubleValue(me.active.node.getNode("heading-deg").getValue());
|
|
|
|
} else {
|
|
|
|
hdg.setDoubleValue(0);
|
|
|
|
}
|
|
|
|
if (getprop("/models/adjust/sticky-orientation")) {
|
|
|
|
pitch.setDoubleValue(me.active.node.getNode("pitch-deg").getValue());
|
|
|
|
roll.setDoubleValue(me.active.node.getNode("roll-deg").getValue());
|
|
|
|
} else {
|
|
|
|
pitch.setDoubleValue(0);
|
|
|
|
roll.setDoubleValue(0);
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
},
|
|
|
|
reset_heading : func {
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
if (m.selected) {
|
|
|
|
m.hdg.set(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
reset_orientation : func {
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
if (m.selected) {
|
|
|
|
m.pitch.set(0);
|
|
|
|
m.roll.set(0);
|
|
|
|
}
|
2006-03-24 00:20:22 +00:00
|
|
|
}
|
|
|
|
},
|
2006-04-13 22:01:53 +00:00
|
|
|
import : func {
|
2007-02-27 15:39:49 +00:00
|
|
|
me.active = nil;
|
2006-04-21 19:49:44 +00:00
|
|
|
var mandatory = ["path", "longitude-deg", "latitude-deg", "elevation-ft"];
|
|
|
|
foreach (var m; props.globals.getNode("models", 1).getChildren("model")) {
|
|
|
|
var ok = 1;
|
|
|
|
foreach (var a; mandatory) {
|
|
|
|
if (m.getNode(a) == nil or m.getNode(a).getType() == "NONE") {
|
|
|
|
ok = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ok) {
|
2007-02-27 15:39:49 +00:00
|
|
|
var tmp = props.Node.new({ legend:"", "heading-deg":0, "pitch-deg":0, "roll-deg":0 });
|
2006-04-21 19:59:51 +00:00
|
|
|
props.copy(m, tmp);
|
2006-04-21 19:49:44 +00:00
|
|
|
m.getParent().removeChild(m.getName(), m.getIndex());
|
2007-02-26 17:57:55 +00:00
|
|
|
var c = Coord.new().set_lonlat(
|
|
|
|
tmp.getNode("longitude-deg").getValue(),
|
|
|
|
tmp.getNode("latitude-deg").getValue(),
|
|
|
|
tmp.getNode("elevation-ft").getValue() * FT2M);
|
2007-02-27 15:39:49 +00:00
|
|
|
append(me.models, me.active = Model.new(tmp.getNode("path").getValue(), c, tmp));
|
2007-02-26 17:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
adjust : func(name, value, scale = 0) {
|
|
|
|
if (!size(me.models) or me.active == nil) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var ufo = ufo_position();
|
|
|
|
var dist = scale ? ufo.distance_to(me.active.pos) * 0.05 : 1;
|
|
|
|
if (name == "longitudinal") {
|
|
|
|
var dir = ufo.course_to(me.active.pos);
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
m.selected and m.apply_course_distance(dir, value * dist);
|
|
|
|
}
|
|
|
|
} elsif (name == "transversal") {
|
|
|
|
var dir = ufo.course_to(me.active.pos) + 90;
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
m.selected and m.apply_course_distance(dir, value * dist);
|
|
|
|
}
|
|
|
|
} elsif (name == "altitude") {
|
|
|
|
foreach (var m; me.models) {
|
2007-02-27 15:39:49 +00:00
|
|
|
m.selected and m.raise(value * dist * 0.4);
|
2007-02-26 17:57:55 +00:00
|
|
|
}
|
|
|
|
} elsif (name == "heading") {
|
|
|
|
foreach (var m; me.models) {
|
2007-02-26 19:15:26 +00:00
|
|
|
m.selected and m.hdg.set(m.hdg.get() + value * 4);
|
2007-02-26 17:57:55 +00:00
|
|
|
}
|
|
|
|
} elsif (name == "pitch") {
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
m.selected and m.pitch.set(m.pitch.get() + value * 6);
|
|
|
|
}
|
|
|
|
} elsif (name == "roll") {
|
|
|
|
foreach (var m; me.models) {
|
|
|
|
m.selected and m.roll.set(m.roll.get() + value * 6);
|
2006-04-21 19:49:44 +00:00
|
|
|
}
|
2006-04-13 22:01:53 +00:00
|
|
|
}
|
2007-02-27 22:56:22 +00:00
|
|
|
me.marker.move(me.active.pos);
|
2007-02-27 15:39:49 +00:00
|
|
|
},
|
2007-02-27 22:56:22 +00:00
|
|
|
toggle_marker : func {
|
|
|
|
me.marker.visible ? me.marker.hide() : me.marker.unhide();
|
2006-04-13 22:01:53 +00:00
|
|
|
},
|
2006-03-22 20:25:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var scan_dirs = func(csv) {
|
2006-04-24 20:34:59 +00:00
|
|
|
var list = ["Aircraft/ufo/Models/sign.ac"];
|
2006-03-22 20:25:58 +00:00
|
|
|
foreach(var dir; split(",", csv)) {
|
|
|
|
foreach(var m; scan_models(dir)) {
|
|
|
|
append(list, m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sort(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-23 16:16:44 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var print_ufo_data = func {
|
2006-03-27 13:13:57 +00:00
|
|
|
print("\n\n------------------------------ UFO -------------------------------\n");
|
|
|
|
|
|
|
|
var lon = getprop("/position/longitude-deg");
|
|
|
|
var lat = getprop("/position/latitude-deg");
|
|
|
|
var alt_ft = getprop("/position/altitude-ft");
|
|
|
|
var elev_m = getprop("/position/ground-elev-m");
|
|
|
|
var heading = getprop("/orientation/heading-deg");
|
2007-02-26 17:57:55 +00:00
|
|
|
var agl_ft = alt_ft - elev_m * M2FT;
|
2006-03-27 13:13:57 +00:00
|
|
|
|
2006-04-02 17:52:33 +00:00
|
|
|
printf("Longitude: %.8f deg", lon);
|
|
|
|
printf("Latitude: %.8f deg", lat);
|
2007-02-26 17:57:55 +00:00
|
|
|
printf("Altitude ASL: %.4f m (%.4f ft)", alt_ft * FT2M, alt_ft);
|
|
|
|
printf("Altitude AGL: %.4f m (%.4f ft)", agl_ft * FT2M, agl_ft);
|
2006-03-27 13:13:57 +00:00
|
|
|
printf("Heading: %.1f deg", normdeg(heading));
|
2007-02-26 17:57:55 +00:00
|
|
|
printf("Ground Elev: %.4f m (%.4f ft)", elev_m, elev_m * M2FT);
|
2006-03-27 13:13:57 +00:00
|
|
|
print();
|
|
|
|
print("# " ~ tile_path(lon, lat));
|
2006-04-02 17:52:33 +00:00
|
|
|
printf("OBJECT_STATIC %.8f %.8f %.4f %.1f", lon, lat, elev_m, normdeg(360 - heading));
|
2006-03-27 13:13:57 +00:00
|
|
|
print();
|
|
|
|
|
|
|
|
var hdg = normdeg(heading + getprop("/sim/current-view/goal-pitch-offset-deg"));
|
|
|
|
var fgfs = sprintf("$ fgfs --aircraft=ufo --lon=%.6f --lat=%.6f --altitude=%.2f --heading=%.1f",
|
|
|
|
lon, lat, agl_ft, hdg);
|
|
|
|
print(fgfs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var print_model_data = func(prop) {
|
2006-03-27 13:13:57 +00:00
|
|
|
print("\n\n------------------------ Selected Object -------------------------\n");
|
|
|
|
var elev = prop.getNode("elevation-ft").getValue();
|
|
|
|
printf("Path: %s", prop.getNode("path").getValue());
|
2006-04-02 17:52:33 +00:00
|
|
|
printf("Longitude: %.8f deg", prop.getNode("longitude-deg").getValue());
|
|
|
|
printf("Latitude: %.8f deg", prop.getNode("latitude-deg").getValue());
|
2007-02-26 17:57:55 +00:00
|
|
|
printf("Altitude ASL: %.4f m (%.4f ft)", elev * FT2M, elev);
|
2006-03-27 13:13:57 +00:00
|
|
|
printf("Heading: %.1f deg", prop.getNode("heading-deg").getValue());
|
|
|
|
printf("Pitch: %.1f deg", prop.getNode("pitch-deg").getValue());
|
|
|
|
printf("Roll: %.1f deg", prop.getNode("roll-deg").getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-03-23 16:16:44 +00:00
|
|
|
|
|
|
|
# interface functions -----------------------------------------------------------------------------
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var print_data = func {
|
2006-03-27 13:13:57 +00:00
|
|
|
var rule = "\n------------------------------------------------------------------\n";
|
|
|
|
print("\n\n");
|
2007-02-26 17:57:55 +00:00
|
|
|
print_ufo_data();
|
2006-03-27 13:13:57 +00:00
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
var data = modelmgr.get_data();
|
2006-03-27 13:13:57 +00:00
|
|
|
|
|
|
|
var selected = data.getChild("model", 0);
|
|
|
|
if (selected == nil) {
|
|
|
|
print(rule);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
print_model_data(selected);
|
2006-03-27 13:13:57 +00:00
|
|
|
print(rule);
|
|
|
|
|
2006-03-22 20:25:58 +00:00
|
|
|
# group all objects of a bucket
|
2006-03-27 13:13:57 +00:00
|
|
|
var bucket = {};
|
2006-03-22 20:25:58 +00:00
|
|
|
foreach (var m; data.getChildren("model")) {
|
|
|
|
var stg = m.getNode("stg-path").getValue();
|
|
|
|
var obj = m.getNode("object-line").getValue();
|
|
|
|
if (contains(bucket, stg)) {
|
|
|
|
append(bucket[stg], obj);
|
|
|
|
} else {
|
|
|
|
bucket[stg] = [obj];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (var key; keys(bucket)) {
|
|
|
|
print("\n# ", key);
|
|
|
|
foreach (var obj; bucket[key]) {
|
|
|
|
print(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print(rule);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
var export_data = func {
|
2006-03-22 20:25:58 +00:00
|
|
|
savexml = func(name, node) {
|
2007-02-27 15:39:49 +00:00
|
|
|
fgcommand("savexml", props.Node.new({ "filename": name, "sourcenode": node }));
|
2006-03-22 20:25:58 +00:00
|
|
|
}
|
|
|
|
var tmp = "save-ufo-data";
|
|
|
|
save = props.globals.getNode(tmp, 1);
|
2006-04-13 22:01:53 +00:00
|
|
|
props.copy(modelmgr.get_data(), save.getNode("models", 1));
|
2006-04-02 17:35:47 +00:00
|
|
|
var path = getprop("/sim/fg-home") ~ "/ufo-model-export.xml";
|
|
|
|
savexml(path, save.getPath());
|
|
|
|
print("model data exported to ", path);
|
2006-03-22 20:25:58 +00:00
|
|
|
props.globals.removeChild(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# dialogs -----------------------------------------------------------------------------------------
|
|
|
|
|
2007-02-24 19:48:02 +00:00
|
|
|
var status_dialog = gui.Dialog.new("/sim/gui/dialogs/ufo/status/dialog", "Aircraft/ufo/Dialogs/status.xml");
|
|
|
|
var select_dialog = gui.Dialog.new("/sim/gui/dialogs/ufo/select/dialog", "Aircraft/ufo/Dialogs/select.xml");
|
|
|
|
var adjust_dialog = gui.Dialog.new("/sim/gui/dialogs/ufo/adjust/dialog", "Aircraft/ufo/Dialogs/adjust.xml");
|
2006-03-22 20:25:58 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
adjust_dialog.center_sliders = func {
|
|
|
|
var ns = adjust_dialog.namespace();
|
|
|
|
if (ns != nil) {
|
|
|
|
ns.center();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# hide status line in screenshots
|
|
|
|
#
|
2007-02-24 19:48:02 +00:00
|
|
|
var status_restore = nil;
|
2006-07-01 06:02:31 +00:00
|
|
|
setlistener("/sim/signals/screenshot", func {
|
|
|
|
if (cmdarg().getBoolValue()) {
|
2007-02-24 19:48:02 +00:00
|
|
|
status_restore = status_dialog.is_open();
|
|
|
|
status_dialog.close();
|
2006-07-01 06:02:31 +00:00
|
|
|
} else {
|
2007-02-24 19:48:02 +00:00
|
|
|
status_restore and status_dialog.open();
|
2006-07-01 06:02:31 +00:00
|
|
|
}
|
|
|
|
});
|
2006-05-09 09:41:52 +00:00
|
|
|
|
2007-02-24 19:48:02 +00:00
|
|
|
|
2007-02-26 17:57:55 +00:00
|
|
|
|
|
|
|
# init --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
var KbdShift = props.globals.getNode("/devices/status/keyboard/shift");
|
|
|
|
var KbdCtrl = props.globals.getNode("/devices/status/keyboard/ctrl");
|
|
|
|
var KbdAlt = props.globals.getNode("/devices/status/keyboard/alt");
|
|
|
|
|
|
|
|
var click_lon = props.globals.getNode("/sim/input/click/longitude-deg", 1);
|
|
|
|
var click_lat = props.globals.getNode("/sim/input/click/latitude-deg", 1);
|
|
|
|
var click_elev = props.globals.getNode("/sim/input/click/elevation-m", 1);
|
|
|
|
|
|
|
|
var modellist = scan_dirs(getprop("/source"));
|
|
|
|
var modelmgr = ModelMgr.new(getprop("/cursor"));
|
|
|
|
|
|
|
|
setlistener("/sim/signals/click", func {
|
|
|
|
var lon = click_lon.getValue();
|
|
|
|
var lat = click_lat.getValue();
|
|
|
|
var elev = click_elev.getValue();
|
|
|
|
modelmgr.click(Coord.new().set_lonlat(lon, lat, elev));
|
|
|
|
});
|
|
|
|
|
|
|
|
|