wxnviz.py 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522
  1. """!
  2. @package wxnviz.py
  3. @brief wxGUI 3D view mode
  4. This module implements 3D visualization mode for map display.
  5. List of classes:
  6. - Nviz
  7. (C) 2008-2010 by the GRASS Development Team
  8. This program is free software under the GNU General Public
  9. License (>=v2). Read the file COPYING that comes with GRASS
  10. for details.
  11. @author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  12. @author Pythonized by Glynn Clements
  13. """
  14. import sys
  15. from threading import Thread
  16. from ctypes import *
  17. from grass.lib.gis import *
  18. from grass.lib.g3d import *
  19. from grass.lib.ogsf import *
  20. from grass.lib.nviz import *
  21. from debug import Debug
  22. log = None
  23. progress = None
  24. def print_error(msg, type):
  25. """!Redirect stderr"""
  26. global log
  27. if log:
  28. log.write(msg)
  29. else:
  30. print msg
  31. return 0
  32. def print_progress(value):
  33. """!Redirect progress info"""
  34. global progress
  35. if progress:
  36. progress.SetValue(value)
  37. else:
  38. print value
  39. return 0
  40. errtype = CFUNCTYPE(UNCHECKED(c_int), String, c_int)
  41. errfunc = errtype(print_error)
  42. pertype = CFUNCTYPE(UNCHECKED(c_int), c_int)
  43. perfunc = pertype(print_progress)
  44. class Nviz(object):
  45. def __init__(self, glog, gprogress):
  46. """!Initialize Nviz class instance
  47. @param log logging area
  48. """
  49. global errfunc, perfunc, log, progress
  50. log = glog
  51. progress = gprogress
  52. G_gisinit("")
  53. G_set_error_routine(errfunc)
  54. G_set_percent_routine(perfunc)
  55. GS_libinit()
  56. GVL_libinit()
  57. self.data_obj = nv_data()
  58. self.data = pointer(self.data_obj)
  59. self.width = self.height = -1
  60. self.showLight = False
  61. Debug.msg(1, "Nviz::Nviz()")
  62. def __del__(self):
  63. """!Destroy Nviz class instance"""
  64. G_unset_error_routine()
  65. G_unset_percent_routine()
  66. del self.data
  67. del self.data_obj
  68. self.log = None
  69. def ResizeWindow(self, width, height):
  70. """!GL canvas resized
  71. @param width window width
  72. @param height window height
  73. @return 1 on success
  74. @return 0 on failure (window resized by default to 20x20 px)
  75. """
  76. self.width = width
  77. self.height = height
  78. Debug.msg(3, "Nviz::ResizeWindow(): width=%d height=%d",
  79. width, height)
  80. return Nviz_resize_window(width, height)
  81. def GetLongDim(self):
  82. """!Get longest dimension, used for initial size of north arrow"""
  83. return Nviz_get_longdim(self.data)
  84. def SetViewDefault(self):
  85. """!Set default view (based on loaded data)
  86. @return z-exag value, default, min and max height
  87. """
  88. # determine z-exag
  89. z_exag = Nviz_get_exag()
  90. Nviz_change_exag(self.data, z_exag)
  91. # determine height
  92. hdef = c_double()
  93. hmin = c_double()
  94. hmax = c_double()
  95. Nviz_get_exag_height(byref(hdef), byref(hmin), byref(hmax))
  96. Debug.msg(1, "Nviz::SetViewDefault(): hdef=%f, hmin=%f, hmax=%f",
  97. hdef.value, hmin.value, hmax.value)
  98. return (z_exag, hdef.value, hmin.value, hmax.value)
  99. def SetView(self, x, y, height, persp, twist):
  100. """!Change view settings
  101. @param x,y position
  102. @param height
  103. @param persp perpective
  104. @param twist
  105. """
  106. Nviz_set_viewpoint_height(height)
  107. Nviz_set_viewpoint_position(x, y)
  108. Nviz_set_viewpoint_twist(twist)
  109. Nviz_set_viewpoint_persp(persp)
  110. Debug.msg(3, "Nviz::SetView(): x=%f, y=%f, height=%f, persp=%f, twist=%f",
  111. x, y, height, persp, twist)
  112. def LookHere(self, x, y):
  113. """!Look here feature
  114. @param x,y screen coordinates
  115. """
  116. Nviz_look_here(x, y)
  117. Debug.msg(3, "Nviz::LookHere(): x=%f, y=%f", x, y)
  118. def LookAtCenter(self):
  119. """!Center view at center of displayed surface"""
  120. Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1)
  121. Debug.msg(3, "Nviz::LookAtCenter()")
  122. def GetFocus(self):
  123. """!Get focus"""
  124. Debug.msg(3, "Nviz::GetFocus()")
  125. if Nviz_has_focus(self.data):
  126. x = c_float()
  127. y = c_float()
  128. z = c_float()
  129. Nviz_get_focus(self.data, byref(x), byref(y), byref(z))
  130. return x.value, y.value, z.value
  131. else:
  132. return -1, -1, -1
  133. def SetFocus(self, x, y, z):
  134. """!Set focus"""
  135. Debug.msg(3, "Nviz::SetFocus()")
  136. Nviz_set_focus(self.data, x, y, z)
  137. def SetZExag(self, z_exag):
  138. """!Set z-exag value
  139. @param z_exag value
  140. @return 1
  141. """
  142. Debug.msg(3, "Nviz::SetZExag(): z_exag=%f", z_exag)
  143. return Nviz_change_exag(self.data, z_exag)
  144. def Draw(self, quick, quick_mode):
  145. """!Draw canvas
  146. Draw quick mode:
  147. - DRAW_QUICK_SURFACE
  148. - DRAW_QUICK_VLINES
  149. - DRAW_QUICK_VPOINTS
  150. - DRAW_QUICK_VOLUME
  151. @param quick if true draw in wiremode
  152. @param quick_mode quick mode
  153. """
  154. Debug.msg(3, "Nviz::Draw(): quick=%d", quick)
  155. Nviz_draw_cplane(self.data, -1, -1) # ?
  156. if quick:
  157. Nviz_draw_quick(self.data, quick_mode)
  158. else:
  159. Nviz_draw_all(self.data)
  160. def EraseMap(self):
  161. """!Erase map display (with background color)
  162. """
  163. Debug.msg(1, "Nviz::EraseMap()")
  164. GS_clear(Nviz_get_bgcolor(self.data))
  165. def InitView(self):
  166. """!Initialize view"""
  167. # initialize nviz data
  168. Nviz_init_data(self.data)
  169. # define default attributes for map objects
  170. Nviz_set_surface_attr_default()
  171. # set background color
  172. Nviz_set_bgcolor(self.data, Nviz_color_from_str("white"))
  173. GS_clear(Nviz_get_bgcolor(self.data))
  174. # initialize view, lights
  175. Nviz_init_view(self.data)
  176. Debug.msg(1, "Nviz::InitView()")
  177. def SetBgColor(self, color_str):
  178. """!Set background color
  179. @param color_str color string
  180. """
  181. Nviz_set_bgcolor(self.data, Nviz_color_from_str(color_str))
  182. def SetLight(self, x, y, z, color, bright, ambient, w = 0, lid = 1):
  183. """!Change lighting settings
  184. @param x,y,z position
  185. @param color light color (as string)
  186. @param bright light brightness
  187. @param ambient light ambient
  188. @param w local coordinate (default to 0)
  189. """
  190. Nviz_set_light_position(self.data, lid, x, y, z, w)
  191. Nviz_set_light_bright(self.data, lid, bright)
  192. Nviz_set_light_color(self.data, lid, int(color[0]), int(color[1]), int(color[2]))
  193. Nviz_set_light_ambient(self.data, lid, ambient)
  194. def LoadSurface(self, name, color_name, color_value):
  195. """!Load raster map (surface)
  196. @param name raster map name
  197. @param color_name raster map for color (None for color_value)
  198. @param color_value color string (named color or RGB triptet)
  199. @return object id
  200. @return -1 on failure
  201. """
  202. mapset = G_find_raster2(name, "")
  203. if mapset is None:
  204. G_warning(_("Raster map <%s> not found"), name)
  205. return -1
  206. # topography
  207. id = Nviz_new_map_obj(MAP_OBJ_SURF,
  208. G_fully_qualified_name(name, mapset), 0.0,
  209. self.data)
  210. if color_name: # check for color map
  211. mapset = G_find_raster2(color_name, "")
  212. if mapset is None:
  213. G_warning(_("Raster map <%s> not found"), color_name)
  214. GS_delete_surface(id)
  215. return -1
  216. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
  217. G_fully_qualified_name(color_name, mapset), -1.0,
  218. self.data)
  219. elif color_value: # check for color value
  220. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
  221. None, Nviz_color_from_str(color_value),
  222. self.data)
  223. else: # use by default elevation map for coloring
  224. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
  225. G_fully_qualified_name(name, mapset), -1.0,
  226. self.data)
  227. # if (i > 1)
  228. # set_default_wirecolors(self.data, i)
  229. # focus on loaded self.data
  230. Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1)
  231. Debug.msg(1, "Nviz::LoadRaster(): name=%s -> id=%d", name, id)
  232. return id
  233. def AddConstant(self, value, color):
  234. """!Add new constant surface"""
  235. id = Nviz_new_map_obj(MAP_OBJ_SURF, None, value, self.data)
  236. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
  237. None, Nviz_color_from_str(color),
  238. self.data)
  239. Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1)
  240. Debug.msg(1, "Nviz::AddConstant(): id=%d", id)
  241. return id
  242. def UnloadSurface(self, id):
  243. """!Unload surface
  244. @param id surface id
  245. @return 1 on success
  246. @return 0 on failure
  247. """
  248. if not GS_surf_exists(id):
  249. return 0
  250. Debug.msg(1, "Nviz::UnloadSurface(): id=%d", id)
  251. if GS_delete_surface(id) < 0:
  252. return 0
  253. return 1
  254. def LoadVector(self, name, points):
  255. """!Load vector map overlay
  256. @param name vector map name
  257. @param points if true load 2d points rather then 2d lines
  258. @return object id
  259. @return -1 on failure
  260. """
  261. if GS_num_surfs() == 0: # load base surface if no loaded
  262. Nviz_new_map_obj(MAP_OBJ_SURF, None, 0.0, self.data)
  263. nsurf = c_int()
  264. surf_list = GS_get_surf_list(byref(nsurf))
  265. GS_set_att_const(surf_list[0], ATT_TRANSP, 255)
  266. mapset = G_find_vector2 (name, "")
  267. if mapset is None:
  268. G_warning(_("Vector map <%s> not found"),
  269. name)
  270. if points:
  271. id = Nviz_new_map_obj(MAP_OBJ_SITE,
  272. G_fully_qualified_name(name, mapset), 0.0,
  273. self.data)
  274. else:
  275. id = Nviz_new_map_obj(MAP_OBJ_VECT,
  276. G_fully_qualified_name(name, mapset), 0.0,
  277. self.data)
  278. Debug.msg(1, "Nviz::LoadVector(): name=%s -> id=%d", name, id)
  279. return id
  280. def UnloadVector(self, id, points):
  281. """!Unload vector set
  282. @param id vector set id
  283. @param points vector points or lines set
  284. @return 1 on success
  285. @return 0 on failure
  286. """
  287. Debug.msg(1, "Nviz::UnloadVector(): id=%d", id)
  288. if points:
  289. if not GP_site_exists(id):
  290. return 0
  291. if GP_delete_site(id) < 0:
  292. return 0
  293. else:
  294. if not GV_vect_exists(id):
  295. return 0
  296. if GV_delete_vector(id) < 0:
  297. return 0
  298. return 1
  299. def VectorSurfaceSelected(self, vid, sid):
  300. """!Check if surface is selected (currently unused)
  301. @param vid vector id
  302. @param sid surface id
  303. @return True if selected
  304. @return False if not selected
  305. """
  306. selected = GV_surf_is_selected(vid, sid)
  307. Debug.msg(1, "Nviz::VectorSurfaceSelected(): vid=%s, sid=%d -> selected=%d", vid, sid, selected)
  308. return selected
  309. def LoadVolume(self, name, color_name, color_value):
  310. """!Load 3d raster map (volume)
  311. @param name 3d raster map name
  312. @param color_name 3d raster map for color (None for color_value)
  313. @param color_value color string (named color or RGB triptet)
  314. @return object id
  315. @return -1 on failure
  316. """
  317. mapset = G_find_grid3(name, "")
  318. if mapset is None:
  319. G_warning(_("3d raster map <%s> not found"),
  320. name)
  321. return -1
  322. # topography
  323. id = Nviz_new_map_obj(MAP_OBJ_VOL,
  324. G_fully_qualified_name(name, mapset), 0.0,
  325. self.data)
  326. if color_name: # check for color map
  327. mapset = G_find_grid3(color_name, "")
  328. if mapset is None:
  329. G_warning(_("3d raster map <%s> not found"),
  330. color_name)
  331. GVL_delete_vol(id)
  332. return -1
  333. Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
  334. G_fully_qualified_name(color_name, mapset), -1.0,
  335. self.data)
  336. elif color_value: # check for color value
  337. Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, CONST_ATT,
  338. None, Nviz_color_from_str(color_value),
  339. self.data)
  340. else: # use by default elevation map for coloring
  341. Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
  342. G_fully_qualified_name(name, mapset), -1.0,
  343. self.data)
  344. Debug.msg(1, "Nviz::LoadVolume(): name=%s -> id=%d", name, id)
  345. return id
  346. def UnloadVolume(self, id):
  347. """!Unload volume
  348. @param id volume id
  349. @return 1 on success
  350. @return 0 on failure
  351. """
  352. if not GVL_vol_exists(id):
  353. return 0
  354. Debug.msg(1, "Nviz::UnloadVolume(): id=%d", id)
  355. if GVL_delete_vol(id) < 0:
  356. return 0
  357. return 1
  358. def SetSurfaceTopo(self, id, map, value):
  359. """!Set surface topography
  360. @param id surface id
  361. @param map if true use map otherwise constant
  362. @param value map name of value
  363. @return 1 on success
  364. @return -1 surface not found
  365. @return -2 setting attributes failed
  366. """
  367. return self.SetSurfaceAttr(id, ATT_TOPO, map, value)
  368. def SetSurfaceColor(self, id, map, value):
  369. """!Set surface color
  370. @param id surface id
  371. @param map if true use map otherwise constant
  372. @param value map name or value
  373. @return 1 on success
  374. @return -1 surface not found
  375. @return -2 setting attributes failed
  376. """
  377. return self.SetSurfaceAttr(id, ATT_COLOR, map, value)
  378. def SetSurfaceMask(self, id, invert, value):
  379. """!Set surface mask
  380. @todo invert
  381. @param id surface id
  382. @param invert if true invert mask
  383. @param value map name of value
  384. @return 1 on success
  385. @return -1 surface not found
  386. @return -2 setting attributes failed
  387. """
  388. return self.SetSurfaceAttr(id, ATT_MASK, True, value)
  389. def SetSurfaceTransp(self, id, map, value):
  390. """!Set surface mask
  391. @todo invert
  392. @param id surface id
  393. @param map if true use map otherwise constant
  394. @param value map name of value
  395. @return 1 on success
  396. @return -1 surface not found
  397. @return -2 setting attributes failed
  398. """
  399. return self.SetSurfaceAttr(id, ATT_TRANSP, map, value)
  400. def SetSurfaceShine(self, id, map, value):
  401. """!Set surface shininess
  402. @param id surface id
  403. @param map if true use map otherwise constant
  404. @param value map name of value
  405. @return 1 on success
  406. @return -1 surface not found
  407. @return -2 setting attributes failed
  408. """
  409. return self.SetSurfaceAttr(id, ATT_SHINE, map, value)
  410. def SetSurfaceEmit(self, id, map, value):
  411. """!Set surface emission (currently unused)
  412. @param id surface id
  413. @param map if true use map otherwise constant
  414. @param value map name of value
  415. @return 1 on success
  416. @return -1 surface not found
  417. @return -2 setting attributes failed
  418. """
  419. return self.SetSurfaceAttr(id, ATT_EMIT, map, value)
  420. def SetSurfaceAttr(self, id, attr, map, value):
  421. """!Set surface attribute
  422. @param id surface id
  423. @param attr attribute desc
  424. @param map if true use map otherwise constant
  425. @param value map name of value
  426. @return 1 on success
  427. @return -1 surface not found
  428. @return -2 setting attributes failed
  429. """
  430. if not GS_surf_exists(id):
  431. return -1
  432. if map:
  433. ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, MAP_ATT,
  434. value, -1.0, self.data)
  435. else:
  436. if attr == ATT_COLOR:
  437. val = Nviz_color_from_str(value)
  438. else:
  439. val = float(value)
  440. ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, CONST_ATT,
  441. None, val, self.data)
  442. Debug.msg(3, "Nviz::SetSurfaceAttr(): id=%d, attr=%d, map=%d, value=%s",
  443. id, attr, map, value)
  444. if ret < 0:
  445. return -2
  446. return 1
  447. def UnsetSurfaceMask(self, id):
  448. """!Unset surface mask
  449. @param id surface id
  450. @return 1 on success
  451. @return -1 surface not found
  452. @return -2 setting attributes failed
  453. @return -1 on failure
  454. """
  455. return self.UnsetSurfaceAttr(id, ATT_MASK)
  456. def UnsetSurfaceTransp(self, id):
  457. """!Unset surface transparency
  458. @param id surface id
  459. @return 1 on success
  460. @return -1 surface not found
  461. @return -2 setting attributes failed
  462. """
  463. return self.UnsetSurfaceAttr(id, ATT_TRANSP)
  464. def UnsetSurfaceEmit(self, id):
  465. """!Unset surface emission (currently unused)
  466. @param id surface id
  467. @return 1 on success
  468. @return -1 surface not found
  469. @return -2 setting attributes failed
  470. """
  471. return self.UnsetSurfaceAttr(id, ATT_EMIT)
  472. def UnsetSurfaceAttr(self, id, attr):
  473. """!Unset surface attribute
  474. @param id surface id
  475. @param attr attribute descriptor
  476. @return 1 on success
  477. @return -1 surface not found
  478. @return -2 setting attributes failed
  479. """
  480. if not GS_surf_exists(id):
  481. return -1
  482. Debug.msg(3, "Nviz::UnsetSurfaceAttr(): id=%d, attr=%d",
  483. id, attr)
  484. ret = Nviz_unset_attr(id, MAP_OBJ_SURF, attr)
  485. if ret < 0:
  486. return -2
  487. return 1
  488. def SetSurfaceRes(self, id, fine, coarse):
  489. """!Set surface resolution
  490. @param id surface id
  491. @param fine x/y fine resolution
  492. @param coarse x/y coarse resolution
  493. @return 1 on success
  494. @return -1 surface not found
  495. @return -2 setting attributes failed
  496. """
  497. Debug.msg(3, "Nviz::SetSurfaceRes(): id=%d, fine=%d, coarse=%d",
  498. id, fine, coarse)
  499. if id > 0:
  500. if not GS_surf_exists(id):
  501. return -1
  502. if GS_set_drawres(id, fine, fine, coarse, coarse) < 0:
  503. return -2
  504. else:
  505. GS_setall_drawres(fine, fine, coarse, coarse)
  506. return 1
  507. def SetSurfaceStyle(self, id, style):
  508. """!Set draw style
  509. Draw styles:
  510. - DM_GOURAUD
  511. - DM_FLAT
  512. - DM_FRINGE
  513. - DM_WIRE
  514. - DM_COL_WIRE
  515. - DM_POLY
  516. - DM_WIRE_POLY
  517. - DM_GRID_WIRE
  518. - DM_GRID_SURF
  519. @param id surface id (<= 0 for all)
  520. @param style draw style
  521. @return 1 on success
  522. @return -1 surface not found
  523. @return -2 setting attributes failed
  524. """
  525. Debug.msg(3, "Nviz::SetSurfaceStyle(): id=%d, style=%d",
  526. id, style)
  527. if id > 0:
  528. if not GS_surf_exists(id):
  529. return -1
  530. if GS_set_drawmode(id, style) < 0:
  531. return -2
  532. return 1
  533. if GS_setall_drawmode(style) < 0:
  534. return -2
  535. return 1
  536. def SetWireColor(self, id, color_str):
  537. """!Set color of wire
  538. @todo all
  539. @param surface id (< 0 for all)
  540. @param color color string (R:G:B)
  541. @return 1 on success
  542. @return -1 surface not found
  543. @return -2 setting attributes failed
  544. @return 1 on success
  545. @return 0 on failure
  546. """
  547. Debug.msg(3, "Nviz::SetWireColor(): id=%d, color=%s",
  548. id, color_str)
  549. color = Nviz_color_from_str(color_str)
  550. if id > 0:
  551. if not GS_surf_exists(id):
  552. return -1
  553. GS_set_wire_color(id, color)
  554. else:
  555. nsurfs = c_int()
  556. surf_list = GS_get_surf_list(byref(nsurfs))
  557. for i in xrange(nsurfs.value):
  558. id = surf_list[i]
  559. GS_set_wire_color(id, color)
  560. G_free(surf_list)
  561. surf_list = None
  562. return 1
  563. def GetSurfacePosition(self, id):
  564. """!Get surface position
  565. @param id surface id
  566. @return x,y,z
  567. @return zero-length vector on error
  568. """
  569. if not GS_surf_exists(id):
  570. return []
  571. x, y, z = c_float(), c_float(), c_float()
  572. GS_get_trans(id, byref(x), byref(y), byref(z))
  573. Debug.msg(3, "Nviz::GetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
  574. id, x.value, y.value, z.value)
  575. return [x.value, y.value, z.value]
  576. def SetSurfacePosition(self, id, x, y, z):
  577. """!Set surface position
  578. @param id surface id
  579. @param x,y,z translation values
  580. @return 1 on success
  581. @return -1 surface not found
  582. @return -2 setting position failed
  583. """
  584. if not GS_surf_exists(id):
  585. return -1
  586. Debug.msg(3, "Nviz::SetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
  587. id, x, y, z)
  588. GS_set_trans(id, x, y, z)
  589. return 1
  590. def SetVectorLineMode(self, id, color_str, width, flat):
  591. """!Set mode of vector line overlay
  592. @param id vector id
  593. @param color_str color string
  594. @param width line width
  595. @param flat display flat or on surface
  596. @return -1 vector set not found
  597. @return -2 on failure
  598. @return 1 on success
  599. """
  600. if not GV_vect_exists(id):
  601. return -1
  602. Debug.msg(3, "Nviz::SetVectorMode(): id=%d, color=%s, width=%d, flat=%d",
  603. id, color_str, width, flat)
  604. color = Nviz_color_from_str(color_str)
  605. # use memory by default
  606. if GV_set_vectmode(id, 1, color, width, flat) < 0:
  607. return -2
  608. return 1
  609. def SetVectorLineHeight(self, id, height):
  610. """!Set vector height above surface (lines)
  611. @param id vector set id
  612. @param height
  613. @return -1 vector set not found
  614. @return 1 on success
  615. """
  616. if not GV_vect_exists(id):
  617. return -1
  618. Debug.msg(3, "Nviz::SetVectorLineHeight(): id=%d, height=%f",
  619. id, height)
  620. GV_set_trans(id, 0.0, 0.0, height)
  621. return 1
  622. def SetVectorLineSurface(self, id, surf_id):
  623. """!Set reference surface of vector set (lines)
  624. @param id vector set id
  625. @param surf_id surface id
  626. @return 1 on success
  627. @return -1 vector set not found
  628. @return -2 surface not found
  629. @return -3 on failure
  630. """
  631. if not GV_vect_exists(id):
  632. return -1
  633. if not GS_surf_exists(surf_id):
  634. return -2
  635. if GV_select_surf(id, surf_id) < 0:
  636. return -3
  637. return 1
  638. def UnsetVectorLineSurface(self, id, surf_id):
  639. """!Unset reference surface of vector set (lines)
  640. @param id vector set id
  641. @param surf_id surface id
  642. @return 1 on success
  643. @return -1 vector set not found
  644. @return -2 surface not found
  645. @return -3 on failure
  646. """
  647. if not GV_vect_exists(id):
  648. return -1
  649. if not GS_surf_exists(surf_id):
  650. return -2
  651. if GV_unselect_surf(id, surf_id) < 0:
  652. return -3
  653. return 1
  654. def SetVectorPointMode(self, id, color_str, width, size, marker):
  655. """!Set mode of vector point overlay
  656. @param id vector id
  657. @param color_str color string
  658. @param width line width
  659. @param flat
  660. @return -1 vector set not found
  661. """
  662. if not GP_site_exists(id):
  663. return -1
  664. Debug.msg(3, "Nviz::SetVectorPointMode(): id=%d, color=%s, "
  665. "width=%d, size=%f, marker=%d",
  666. id, color_str, width, size, marker)
  667. color = Nviz_color_from_str(color_str)
  668. if GP_set_style(id, color, width, size, marker) < 0:
  669. return -2
  670. return 1
  671. def SetVectorPointHeight(self, id, height):
  672. """!Set vector height above surface (points)
  673. @param id vector set id
  674. @param height
  675. @return -1 vector set not found
  676. @return 1 on success
  677. """
  678. if not GP_site_exists(id):
  679. return -1
  680. Debug.msg(3, "Nviz::SetVectorPointHeight(): id=%d, height=%f",
  681. id, height)
  682. GP_set_trans(id, 0.0, 0.0, height)
  683. return 1
  684. def SetVectorPointSurface(self, id, surf_id):
  685. """!Set reference surface of vector set (points)
  686. @param id vector set id
  687. @param surf_id surface id
  688. @return 1 on success
  689. @return -1 vector set not found
  690. @return -2 surface not found
  691. @return -3 on failure
  692. """
  693. if not GP_site_exists(id):
  694. return -1
  695. if not GS_surf_exists(surf_id):
  696. return -2
  697. if GP_select_surf(id, surf_id) < 0:
  698. return -3
  699. return 1
  700. def UnsetVectorPointSurface(self, id, surf_id):
  701. """!Unset reference surface of vector set (points)
  702. @param id vector set id
  703. @param surf_id surface id
  704. @return 1 on success
  705. @return -1 vector set not found
  706. @return -2 surface not found
  707. @return -3 on failure
  708. """
  709. if not GP_site_exists(id):
  710. return -1
  711. if not GS_surf_exists(surf_id):
  712. return -2
  713. if GP_unselect_surf(id, surf_id) < 0:
  714. return -3
  715. return 1
  716. def AddIsosurface(self, id, level, isosurf_id = None):
  717. """!Add new isosurface
  718. @param id volume id
  719. @param level isosurface level (topography)
  720. @return -1 on failure
  721. @return 1 on success
  722. """
  723. if not GVL_vol_exists(id):
  724. return -1
  725. if isosurf_id is not None:
  726. num = GVL_isosurf_num_isosurfs(id)
  727. if num < 0 or isosurf_id != num:
  728. return -1
  729. if GVL_isosurf_add(id) < 0:
  730. return -1
  731. # set topography level
  732. nisosurfs = GVL_isosurf_num_isosurfs(id)
  733. return GVL_isosurf_set_att_const(id, nisosurfs - 1, ATT_TOPO, level)
  734. def DeleteIsosurface(self, id, isosurf_id):
  735. """!Delete isosurface
  736. @param id volume id
  737. @param isosurf_id isosurface id
  738. @return 1 on success
  739. @return -1 volume not found
  740. @return -2 isosurface not found
  741. @return -3 on failure
  742. """
  743. if not GVL_vol_exists(id):
  744. return -1
  745. if isosurf_id > GVL_isosurf_num_isosurfs(id):
  746. return -2
  747. ret = GVL_isosurf_del(id, isosurf_id)
  748. if ret < 0:
  749. return -3
  750. return 1
  751. def MoveIsosurface(self, id, isosurf_id, up):
  752. """!Move isosurface up/down in the list
  753. @param id volume id
  754. @param isosurf_id isosurface id
  755. @param up if true move up otherwise down
  756. @return 1 on success
  757. @return -1 volume not found
  758. @return -2 isosurface not found
  759. @return -3 on failure
  760. """
  761. if not GVL_vol_exists(id):
  762. return -1
  763. if isosurf_id > GVL_isosurf_num_isosurfs(id):
  764. return -2
  765. if up:
  766. ret = GVL_isosurf_move_up(id, isosurf_id)
  767. else:
  768. ret = GVL_isosurf_move_down(id, isosurf_id)
  769. if ret < 0:
  770. return -3
  771. return 1
  772. def SetIsosurfaceTopo(self, id, isosurf_id, map, value):
  773. """!Set isosurface level
  774. @param id volume id
  775. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  776. @param map if true use map otherwise constant
  777. @param value map name of value
  778. @return 1 on success
  779. @return -1 volume not found
  780. @return -2 isosurface not found
  781. @return -3 on failure
  782. """
  783. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_TOPO, map, value)
  784. def SetIsosurfaceColor(self, id, isosurf_id, map, value):
  785. """!Set isosurface color
  786. @param id volume id
  787. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  788. @param map if true use map otherwise constant
  789. @param value map name of value
  790. @return 1 on success
  791. @return -1 volume not found
  792. @return -2 isosurface not found
  793. @return -3 on failure
  794. """
  795. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_COLOR, map, value)
  796. def SetIsosurfaceMask(self, id, isosurf_id, invert, value):
  797. """!Set isosurface mask
  798. @todo invert
  799. @param id volume id
  800. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  801. @param invert true for invert mask
  802. @param value map name to be used for mask
  803. @return 1 on success
  804. @return -1 volume not found
  805. @return -2 isosurface not found
  806. @return -3 on failure
  807. """
  808. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_MASK, True, value)
  809. def SetIsosurfaceTransp(self, id, isosurf_id, map, value):
  810. """!Set isosurface transparency
  811. @param id volume id
  812. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  813. @param map if true use map otherwise constant
  814. @param value map name of value
  815. @return 1 on success
  816. @return -1 volume not found
  817. @return -2 isosurface not found
  818. @return -3 on failure
  819. """
  820. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_TRANSP, map, value)
  821. def SetIsosurfaceShine(self, id, isosurf_id, map, value):
  822. """!Set isosurface shininess
  823. @param id volume id
  824. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  825. @param map if true use map otherwise constant
  826. @param value map name of value
  827. @return 1 on success
  828. @return -1 volume not found
  829. @return -2 isosurface not found
  830. @return -3 on failure
  831. """
  832. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_SHINE, map, value)
  833. def SetIsosurfaceEmit(self, id, isosurf_id, map, value):
  834. """!Set isosurface emission (currently unused)
  835. @param id volume id
  836. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  837. @param map if true use map otherwise constant
  838. @param value map name of value
  839. @return 1 on success
  840. @return -1 volume not found
  841. @return -2 isosurface not found
  842. @return -3 on failure
  843. """
  844. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_EMIT, map, value)
  845. def SetIsosurfaceAttr(self, id, isosurf_id, attr, map, value):
  846. """!Set isosurface attribute
  847. @param id volume id
  848. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  849. @param attr attribute desc
  850. @param map if true use map otherwise constant
  851. @param value map name of value
  852. @return 1 on success
  853. @return -1 volume not found
  854. @return -2 isosurface not found
  855. @return -3 setting attributes failed
  856. """
  857. if not GVL_vol_exists(id):
  858. return -1
  859. if isosurf_id > GVL_isosurf_num_isosurfs(id) - 1:
  860. return -2
  861. if map:
  862. ret = GVL_isosurf_set_att_map(id, isosurf_id, attr, value)
  863. else:
  864. if attr == ATT_COLOR:
  865. val = Nviz_color_from_str(value)
  866. else:
  867. val = float(value)
  868. ret = GVL_isosurf_set_att_const(id, isosurf_id, attr, val)
  869. Debug.msg(3, "Nviz::SetIsosurfaceAttr(): id=%d, isosurf=%d, "
  870. "attr=%d, map=%d, value=%s",
  871. id, isosurf_id, attr, map, value)
  872. if ret < 0:
  873. return -2
  874. return 1
  875. def UnsetIsosurfaceMask(self, id, isosurf_id):
  876. """!Unset isosurface mask
  877. @param id volume id
  878. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  879. @return 1 on success
  880. @return -1 volume not found
  881. @return -2 isosurface not found
  882. @return -3 setting attributes failed
  883. """
  884. return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_MASK)
  885. def UnsetIsosurfaceTransp(self, id, isosurf_id):
  886. """!Unset isosurface transparency
  887. @param id volume id
  888. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  889. @return 1 on success
  890. @return -1 volume not found
  891. @return -2 isosurface not found
  892. @return -3 setting attributes failed
  893. """
  894. return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_TRANSP)
  895. def UnsetIsosurfaceEmit(self, id, isosurf_id):
  896. """!Unset isosurface emission (currently unused)
  897. @param id volume id
  898. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  899. @return 1 on success
  900. @return -1 volume not found
  901. @return -2 isosurface not found
  902. @return -3 setting attributes failed
  903. """
  904. return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_EMIT)
  905. def UnsetIsosurfaceAttr(self, id, isosurf_id, attr):
  906. """!Unset surface attribute
  907. @param id surface id
  908. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  909. @param attr attribute descriptor
  910. @return 1 on success
  911. @return -1 volume not found
  912. @return -2 isosurface not found
  913. @return -2 on failure
  914. """
  915. if not GVL_vol_exists(id):
  916. return -1
  917. if isosurf_id > GVL_isosurf_num_isosurfs(id) - 1:
  918. return -2
  919. Debug.msg(3, "Nviz::UnsetSurfaceAttr(): id=%d, isosurf_id=%d, attr=%d",
  920. id, isosurf_id, attr)
  921. ret = GVL_isosurf_unset_att(id, isosurf_id, attr)
  922. if ret < 0:
  923. return -2
  924. return 1
  925. def SetIsosurfaceMode(self, id, mode):
  926. """!Set draw mode for isosurfaces
  927. @param mode
  928. @return 1 on success
  929. @return -1 volume set not found
  930. @return -2 on failure
  931. """
  932. if not GVL_vol_exists(id):
  933. return -1
  934. ret = GVL_isosurf_set_drawmode(id, mode)
  935. if ret < 0:
  936. return -2
  937. return 1
  938. def SetIsosurfaceRes(self, id, res):
  939. """!Set draw resolution for isosurfaces
  940. @param res resolution value
  941. @return 1 on success
  942. @return -1 volume set not found
  943. @return -2 on failure
  944. """
  945. if not GVL_vol_exists(id):
  946. return -1
  947. ret = GVL_isosurf_set_drawres(id, res, res, res)
  948. if ret < 0:
  949. return -2
  950. return 1
  951. def SetIsosurfaceInOut(self, id, isosurf_id, inout):
  952. """!Set inout mode
  953. @param inout mode true/false
  954. @return 1 on success
  955. @return -1 volume set not found
  956. @return -2 isosurface not found
  957. @return -3 on failure
  958. """
  959. if not GVL_vol_exists(id):
  960. return -1
  961. if isosurf_id > GVL_isosurf_num_isosurfs(id) - 1:
  962. return -2
  963. ret = GVL_isosurf_set_flags(id, isosurf_id, inout)
  964. if ret < 0:
  965. return -3
  966. return 1
  967. def GetVolumePosition(self, id):
  968. """!Get volume position
  969. @param id volume id
  970. @return x,y,z
  971. @return zero-length vector on error
  972. """
  973. if not GVL_vol_exists(id):
  974. return []
  975. x, y, z = c_float(), c_float(), c_float()
  976. GVL_get_trans(id, byref(x), byref(y), byref(z))
  977. Debug.msg(3, "Nviz::GetVolumePosition(): id=%d, x=%f, y=%f, z=%f",
  978. id, x.value, y.value, z.value)
  979. return [x.value, y.value, z.value]
  980. def SetVolumePosition(self, id, x, y, z):
  981. """!Set volume position
  982. @param id volume id
  983. @param x,y,z translation values
  984. @return 1 on success
  985. @return -1 volume not found
  986. @return -2 setting position failed
  987. """
  988. if not GVL_vol_exists(id):
  989. return -1
  990. Debug.msg(3, "Nviz::SetVolumePosition(): id=%d, x=%f, y=%f, z=%f",
  991. id, x, y, z)
  992. GVL_set_trans(id, x, y, z)
  993. return 1
  994. def GetCPlaneCurrent(self):
  995. return Nviz_get_current_cplane(self.data)
  996. def GetCPlanesCount(self):
  997. """!Returns number of cutting planes"""
  998. return Nviz_num_cplanes(self.data)
  999. def GetCPlaneRotation(self):
  1000. """!Returns rotation parameters of current cutting plane"""
  1001. x, y, z = c_float(), c_float(), c_float()
  1002. current = Nviz_get_current_cplane(self.data)
  1003. Nviz_get_cplane_rotation(self.data, current, byref(x), byref(y), byref(z))
  1004. return x.value, y.value, z.value
  1005. def GetCPlaneTranslation(self):
  1006. """!Returns translation parameters of current cutting plane"""
  1007. x, y, z = c_float(), c_float(), c_float()
  1008. current = Nviz_get_current_cplane(self.data)
  1009. Nviz_get_cplane_translation(self.data, current, byref(x), byref(y), byref(z))
  1010. return x.value, y.value, z.value
  1011. def SetCPlaneRotation(self, x, y, z):
  1012. """!Set current clip plane rotation
  1013. @param x,y,z rotation parameters
  1014. """
  1015. current = Nviz_get_current_cplane(self.data)
  1016. Nviz_set_cplane_rotation(self.data, current, x, y, z)
  1017. Nviz_draw_cplane(self.data, -1, -1)
  1018. def SetCPlaneTranslation(self, x, y, z):
  1019. """!Set current clip plane translation
  1020. @param x,y,z translation parameters
  1021. """
  1022. current = Nviz_get_current_cplane(self.data)
  1023. Nviz_set_cplane_translation(self.data, current, x, y, z)
  1024. Nviz_draw_cplane(self.data, -1, -1)
  1025. Debug.msg(3, "Nviz::SetCPlaneTranslation(): id=%d, x=%f, y=%f, z=%f",
  1026. current, x, y, z)
  1027. def SetCPlaneInteractively(self, x, y):
  1028. current = Nviz_get_current_cplane(self.data)
  1029. ret = Nviz_set_cplane_here(self.data, current, x, y)
  1030. if ret:
  1031. Nviz_draw_cplane(self.data, -1, -1)
  1032. x, y, z = self.GetCPlaneTranslation()
  1033. return x, y, z
  1034. else:
  1035. return None, None, None
  1036. def SelectCPlane(self, index):
  1037. """!Select cutting plane
  1038. @param index index of cutting plane
  1039. """
  1040. Nviz_on_cplane(self.data, index)
  1041. def UnselectCPlane(self, index):
  1042. """!Unselect cutting plane
  1043. @param index index of cutting plane
  1044. """
  1045. Nviz_off_cplane(self.data, index)
  1046. def SetFenceColor(self, index):
  1047. """!Select current cutting plane
  1048. @param index type of fence - from 0 (off) to 4
  1049. """
  1050. Nviz_set_fence_color(self.data, index)
  1051. def GetXYRange(self):
  1052. """!Get xy range"""
  1053. return Nviz_get_xyrange(self.data)
  1054. def GetZRange(self):
  1055. """!Get z range"""
  1056. min, max = c_float(), c_float()
  1057. Nviz_get_zrange(self.data, byref(min), byref(max))
  1058. return min.value, max.value
  1059. def SaveToFile(self, filename, width = 20, height = 20, itype = 'ppm'):
  1060. """!Save current GL screen to ppm/tif file
  1061. @param filename file name
  1062. @param width image width
  1063. @param height image height
  1064. @param itype image type ('ppm' or 'tif')
  1065. """
  1066. widthOrig = self.width
  1067. heightOrig = self.height
  1068. self.ResizeWindow(width, height)
  1069. GS_clear(Nviz_get_bgcolor(self.data))
  1070. self.Draw(False, -1)
  1071. if itype == 'ppm':
  1072. GS_write_ppm(filename)
  1073. else:
  1074. GS_write_tif(filename)
  1075. self.ResizeWindow(widthOrig, heightOrig)
  1076. def DrawLightingModel(self):
  1077. """!Draw lighting model"""
  1078. if self.showLight:
  1079. Nviz_draw_model(self.data)
  1080. def DrawFringe(self):
  1081. """!Draw fringe"""
  1082. Nviz_draw_fringe(self.data)
  1083. def SetFringe(self, sid, color, elev, nw = False, ne = False, sw = False, se = False):
  1084. """!Set fringe
  1085. @param sid surface id
  1086. @param color color
  1087. @param elev elevation (height)
  1088. @param nw,ne,sw,se fringe edges (turn on/off)
  1089. """
  1090. scolor = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1091. Nviz_set_fringe(self.data,
  1092. sid, Nviz_color_from_str(scolor),
  1093. elev, int(nw), int(ne), int(sw), int(se))
  1094. def DrawArrow(self):
  1095. """!Draw north arrow
  1096. """
  1097. return Nviz_draw_arrow(self.data)
  1098. def SetArrow(self, sx, sy, size, color):
  1099. """!Set north arrow from canvas coordinates
  1100. @param sx,sy canvas coordinates
  1101. @param size arrow length
  1102. @param color arrow color
  1103. """
  1104. return Nviz_set_arrow(self.data, sx, sy, size, Nviz_color_from_str(color))
  1105. def DeleteArrow(self):
  1106. """!Delete draw north arrow
  1107. """
  1108. Nviz_delete_arrow(self.data)
  1109. def GetPointOnSurface(self, sx, sy):
  1110. """!Get point on surface
  1111. @param sx,sy canvas coordinates (LL)
  1112. """
  1113. sid = c_int()
  1114. x = c_float()
  1115. y = c_float()
  1116. z = c_float()
  1117. Debug.msg(5, "Nviz::GetPointOnSurface(): sx=%d sy=%d" % (sx, sy))
  1118. num = GS_get_selected_point_on_surface(sx, sy, byref(sid), byref(x), byref(y), byref(z))
  1119. if num == 0:
  1120. return (None, None, None, None)
  1121. return (sid.value, x.value, y.value, z.value)
  1122. def QueryMap(self, sx, sy):
  1123. """!Query surface map
  1124. @param sx,sy canvas coordinates (LL)
  1125. """
  1126. sid, x, y, z = self.GetPointOnSurface(sx, sy)
  1127. if not sid:
  1128. return None
  1129. catstr = create_string_buffer(256)
  1130. valstr = create_string_buffer(256)
  1131. GS_get_cat_at_xy(sid, ATT_TOPO, catstr, x, y)
  1132. GS_get_val_at_xy(sid, ATT_COLOR, valstr, x, y)
  1133. return { 'id' : sid,
  1134. 'x' : x,
  1135. 'y' : y,
  1136. 'z' : z,
  1137. 'elevation' : catstr.value.replace('(', '').replace(')', ''),
  1138. 'color' : valstr.value }
  1139. def GetDistanceAlongSurface(self, sid, p1, p2, useExag = True):
  1140. """!Get distance measured along surface"""
  1141. d = c_float()
  1142. GS_get_distance_alongsurf(sid, p1[0], p1[1], p2[0], p2[1],
  1143. byref(d), int(useExag))
  1144. return d.value