vdigit.py 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834
  1. """
  2. @package vdigit
  3. @brief Vector digitizer extension
  4. Progress:
  5. (1) v.edit called on the background (class VEdit)
  6. (2) Reimplentation of v.digit (VDigit)
  7. Import:
  8. from vdigit import VDigit as VDigit
  9. Classes:
  10. - AbstractDigit
  11. - VEdit
  12. - VDigit
  13. - AbstractDisplayDriver
  14. - CDisplayDriver
  15. - VDigitSettingsDialog
  16. - VDigitCategoryDialog
  17. - VDigitZBulkDialog
  18. - VDigitDuplicatesDialog
  19. (C) 2007-2008 by the GRASS Development Team
  20. This program is free software under the GNU General Public
  21. License (>=v2). Read the file COPYING that comes with GRASS
  22. for details.
  23. @author Martin Landa <landa.martin gmail.com>
  24. """
  25. import os
  26. import sys
  27. import string
  28. import copy
  29. import wx
  30. import wx.lib.colourselect as csel
  31. import wx.lib.mixins.listctrl as listmix
  32. import gcmd
  33. import dbm
  34. from debug import Debug as Debug
  35. import gselect
  36. import globalvar
  37. from preferences import globalSettings as UserSettings
  38. try:
  39. digitPath = os.path.join(globalvar.ETCWXDIR, "vdigit")
  40. sys.path.append(digitPath)
  41. import grass7_wxvdigit as wxvdigit
  42. GV_LINES = wxvdigit.GV_LINES
  43. digitErr = ''
  44. except ImportError, err:
  45. GV_LINES = None
  46. digitErr = err
  47. # print >> sys.stderr, "%sWARNING: Digitization tool is disabled (%s). " \
  48. # "Detailed information in README file." % \
  49. # (os.linesep, err)
  50. # which interface to use?
  51. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit' and GV_LINES is not None:
  52. print >> sys.stderr, "%sWARNING: Digitization tool uses v.edit interface. " \
  53. "This can significantly slow down some operations especially for " \
  54. "middle-large vector maps. "\
  55. "You can change the digitization interface in 'User preferences' " \
  56. "(menu 'Config'->'Preferences')." % \
  57. os.linesep
  58. class AbstractDigit:
  59. """
  60. Abstract digitization class
  61. """
  62. def __init__(self, mapwindow):
  63. """Initialization
  64. @param mapwindow reference to mapwindow (MapFrame) instance
  65. @param settings initial settings of digitization tool
  66. """
  67. self.map = None
  68. self.mapWindow = mapwindow
  69. Debug.msg (3, "AbstractDigit.__init__(): map=%s" % \
  70. self.map)
  71. #self.SetCategory()
  72. self.driver = CDisplayDriver(self, mapwindow)
  73. def SetCategoryNextToUse(self):
  74. """Find maximum category number in the map layer
  75. and update Digit.settings['category']
  76. @return 'True' on success, 'False' on failure
  77. """
  78. # vector map layer without categories, reset to '1'
  79. UserSettings.Set(group='vdigit', key='category', subkey='value', value=1)
  80. if self.map:
  81. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':
  82. categoryCmd = gcmd.Command(cmd=["v.category", "-g", "--q",
  83. "input=%s" % self.map,
  84. "option=report"])
  85. if categoryCmd.returncode != 0:
  86. return False
  87. for line in categoryCmd.ReadStdOutput():
  88. if "all" in line:
  89. if UserSettings.Get(group='vdigit', key='layer', subkey='value') != int(line.split(' ')[0]):
  90. continue
  91. try:
  92. maxCat = int(line.split(' ')[-1]) + 1
  93. UserSettings.Set(group='vdigit', key='category', subkey='value', value=maxCat)
  94. except:
  95. return False
  96. return True
  97. else:
  98. cat = self.digit.GetCategory(UserSettings.Get(group='vdigit', key='layer', subkey='value'))
  99. UserSettings.Set(group='vdigit', key='category', subkey='value',
  100. value=cat + 1)
  101. def SetCategory(self):
  102. """Return category number to use (according Settings)"""
  103. if UserSettings.Get(group='vdigit', key="categoryMode", subkey='selection') == 0:
  104. self.SetCategoryNextToUse()
  105. return UserSettings.Get(group='vdigit', key="category", subkey='value')
  106. def SetMapName(self, map):
  107. """Set map name
  108. @param map map name to be set up or None (will close currently edited map)
  109. """
  110. Debug.msg (3, "AbstractDigit.SetMapName map=%s" % map)
  111. self.map = map
  112. try:
  113. ret = self.driver.Reset(self.map)
  114. except StandardError, e:
  115. raise gcmd.DigitError(parent=self.mapWindow.parent,
  116. message=_('Unable to initialize display driver, '
  117. 'see README file for more information.%s%s'
  118. 'Details: %s (%s)') % (os.linesep, os.linesep, e, digitErr))
  119. if map and ret == -1:
  120. raise gcmd.DigitError(parent=self.mapWindow.parent,
  121. message=_('Unable to open vector map <%s> for editing. '
  122. 'Data are probably corrupted, '
  123. 'try to run v.build for rebuilding the topology.') % map)
  124. if not map and ret != 0:
  125. raise gcmd.DigitError(parent=self.mapWindow.parent,
  126. message=_('Unable to open vector map <%s> for editing. '
  127. 'Data are probably corrupted, '
  128. 'try to run v.build for rebuilding the topology.') % map)
  129. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') != 'v.edit':
  130. try:
  131. self.digit.InitCats()
  132. except:
  133. pass
  134. # avoid using current vector map as background map
  135. if self.map == UserSettings.Get(group='vdigit', key='backgroundMap', subkey='value'):
  136. UserSettings.Set(group='vdigit', key='backgroundMap', subkey='value', value='')
  137. def SelectLinesByQueryThresh(self):
  138. """Generic method used for SelectLinesByQuery()
  139. -- to get threshold value"""
  140. thresh = 0.0
  141. if UserSettings.Get(group='vdigit', key='query', subkey='selection') == 0:
  142. thresh = UserSettings.Get(group='vdigit', key='queryLength', subkey='thresh')
  143. if UserSettings.Get(group='vdigit', key="queryLength", subkey='than-selection') == 0:
  144. thresh = -1 * thresh
  145. else:
  146. thresh = UserSettings.Get(group='vdigit', key='queryDangle', subkey='thresh')
  147. if UserSettings.Get(group='vdigit', key="queryDangle", subkey='than-selection') == 0:
  148. thresh = -1 * thresh
  149. return thresh
  150. def GetSelectType(self):
  151. """Get type(s) to be selected
  152. Used by SelectLinesByBox() and SelectLinesByPoint()"""
  153. type = 0
  154. for feature in (('Point', wxvdigit.GV_POINT),
  155. ('Line', wxvdigit.GV_LINE),
  156. ('Centroid', wxvdigit.GV_CENTROID),
  157. ('Boundary', wxvdigit.GV_BOUNDARY)):
  158. if UserSettings.Get(group='vdigit', key='selectFeature'+feature[0], subkey='enabled') is True:
  159. type |= feature[1]
  160. return type
  161. def SelectLinesFromBackgroundMap(self, pos1, pos2):
  162. """Select features from background map
  163. @param pos1,pos2 bounding box defifinition
  164. """
  165. if UserSettings.Get(group='vdigit', key='backgroundMap', subkey='value') == '':
  166. Debug.msg(4, "VEdit.SelectLinesFromBackgroundMap(): []")
  167. return []
  168. x1, y1 = pos1
  169. x2, y2 = pos2
  170. vEditCmd = gcmd.Command(['v.edit',
  171. '--q',
  172. 'map=%s' % UserSettings.Get(group='vdigit', key='backgroundMap', subkey='value'),
  173. 'tool=select',
  174. 'bbox=%f,%f,%f,%f' % (pos1[0], pos1[1], pos2[0], pos2[1])])
  175. #'polygon=%f,%f,%f,%f,%f,%f,%f,%f,%f,%f' % \
  176. # (x1, y1, x2, y1, x2, y2, x1, y2, x1, y1)])
  177. try:
  178. output = vEditCmd.ReadStdOutput()[0] # first line
  179. ids = output.split(',')
  180. ids = map(int, ids) # str -> int
  181. except:
  182. return []
  183. Debug.msg(4, "VEdit.SelectLinesFromBackgroundMap(): %s" % \
  184. ",".join(["%d" % v for v in ids]))
  185. return ids
  186. class VEdit(AbstractDigit):
  187. """
  188. Prototype of digitization class based on v.edit command
  189. Note: This should be replaced by VDigit class.
  190. """
  191. def __init__(self, mapwindow):
  192. """Initialization
  193. @param mapwindow reference to mapwindow (MapFrame) instance
  194. @param settings initial settings of digitization tool
  195. """
  196. AbstractDigit.__init__(self, mapwindow)
  197. def AddPoint (self, map, point, x, y, z=None):
  198. """Add point/centroid
  199. @param map map name
  200. @param point feature type (True for point, otherwise centroid)
  201. @param x,y,z coordinates
  202. """
  203. if point:
  204. key = "P"
  205. else:
  206. key = "C"
  207. if UserSettings.Get(group='vdigit', key="categoryMode", subkey='selection') == 2:
  208. layer = -1 # -> no category
  209. cat = -1
  210. else:
  211. layer = UserSettings.Get(group='vdigit', key="layer", subkey='value')
  212. cat = self.SetCategory()
  213. if layer > 0 and cat != "None":
  214. addstring = "%s 1 1\n" % (key)
  215. else:
  216. addstring = "%s 1\n" % (key)
  217. addstring += "%f %f\n" % (x, y)
  218. if layer > 0 and cat != "None":
  219. addstring += "%d %d\n" % (layer, cat)
  220. Debug.msg (3, "VEdit.AddPoint(): map=%s, type=%s, layer=%d, cat=%d, x=%f, y=%f" % \
  221. (map, type, layer, cat, x, y))
  222. else:
  223. Debug.msg (3, "VEdit.AddPoint(): map=%s, type=%s, x=%f, y=%f" % \
  224. (map, type, x, y))
  225. Debug.msg (4, "Vline.AddPoint(): input=%s" % addstring)
  226. self.__AddFeature (map=map, input=addstring)
  227. def AddLine (self, map, line, coords):
  228. """Add line/boundary
  229. @param map map name
  230. @param line feature type (True for line, otherwise boundary)
  231. @param list of coordinates
  232. """
  233. if len(coords) < 2:
  234. return
  235. if UserSettings.Get(group='vdigit', key="categoryMode", subkey='selection') == 2:
  236. layer = -1 # -> no category
  237. cat = -1
  238. else:
  239. layer = UserSettings.Get(group='vdigit', key="layer", subkey='value')
  240. cat = self.SetCategory()
  241. if line:
  242. key = "L"
  243. flags = []
  244. else:
  245. key = "B"
  246. flags = ['-c'] # close boundaries
  247. if layer > 0 and cat != "None":
  248. addstring = "%s %d 1\n" % (key, len(coords))
  249. else:
  250. addstring = "%s %d\n" % (key, len(coords))
  251. for point in coords:
  252. addstring += "%f %f\n" % \
  253. (float(point[0]), float(point [1]))
  254. if layer > 0 and cat != "None":
  255. addstring += "%d %d\n" % (layer, cat)
  256. Debug.msg (3, "Vline.AddLine(): type=%s, layer=%d, cat=%d coords=%s" % \
  257. (key, layer, cat, coords))
  258. else:
  259. Debug.msg (3, "Vline.AddLine(): type=%s, coords=%s" % \
  260. (key, coords))
  261. Debug.msg (4, "VEdit.AddLine(): input=%s" % addstring)
  262. self.__AddFeature (map=map, input=addstring, flags=flags)
  263. def __AddFeature (self, map, input, flags=[]):
  264. """Generic method to add new vector feature
  265. @param map map name
  266. @param input feature definition in GRASS ASCII format
  267. @param flags additional flags
  268. """
  269. if UserSettings.Get(group='vdigit', key='snapping', subkey='value') <= 0.0:
  270. snap = "no"
  271. else:
  272. if UserSettings.Get(group='vdigit', key='snapToVertex', subkey='enabled') is True:
  273. snap = "vertex"
  274. else:
  275. snap = "node"
  276. command = ["v.edit", "-n", "--q",
  277. "map=%s" % map,
  278. "tool=add",
  279. "thresh=%f,%f" % (self.driver.GetThreshold(type='selectThresh'), self.driver.GetThreshold(type='snapping')),
  280. "snap=%s" % snap]
  281. if UserSettings.Get(group='vdigit', key='backgroundMap', subkey='value') != '':
  282. command.append("bgmap=%s" % UserSettings.Get(group='vdigit', key='backgroundMap', subkey='value'))
  283. # additional flags
  284. for flag in flags:
  285. command.append(flag)
  286. # run the command
  287. Debug.msg(4, "VEdit.AddFeature(): input=%s" % input)
  288. vedit = gcmd.Command(cmd=command, stdin=input, stderr=None)
  289. # reload map (needed for v.edit)
  290. self.driver.ReloadMap()
  291. def DeleteSelectedLines(self):
  292. """Delete selected features"""
  293. selected = self.driver.GetSelected() # grassId
  294. if len(selected) <= 0:
  295. return False
  296. ids = ",".join(["%d" % v for v in selected])
  297. Debug.msg(4, "Digit.DeleteSelectedLines(): ids=%s" % \
  298. ids)
  299. # delete also attributes if requested
  300. if UserSettings.Get(group='vdigit', key='delRecord', subkey='enabled') is True:
  301. layerCommand = gcmd.Command(cmd=["v.db.connect",
  302. "-g", "--q",
  303. "map=%s" % self.map],
  304. rerr=None, stderr=None)
  305. if layerCommand.returncode == 0:
  306. layers = {}
  307. for line in layerCommand.ReadStdOutput():
  308. lineList = line.split(' ')
  309. layers[int(lineList[0])] = { "table" : lineList[1],
  310. "key" : lineList[2],
  311. "database" : lineList[3],
  312. "driver" : lineList[4] }
  313. for layer in layers.keys():
  314. printCats = gcmd.Command(['v.category',
  315. '--q',
  316. 'input=%s' % self.map,
  317. 'layer=%d' % layer,
  318. 'option=print',
  319. 'id=%s' % ids])
  320. sql = 'DELETE FROM %s WHERE' % layers[layer]['table']
  321. n_cats = 0
  322. for cat in printCats.ReadStdOutput():
  323. for c in cat.split('/'):
  324. sql += ' cat = %d or' % int(c)
  325. n_cats += 1
  326. sql = sql.rstrip(' or')
  327. if n_cats > 0:
  328. gcmd.Command(['db.execute',
  329. '--q',
  330. 'driver=%s' % layers[layer]['driver'],
  331. 'database=%s' % layers[layer]['database']],
  332. stdin=sql,
  333. rerr=None, stderr=None)
  334. command = [ "v.edit",
  335. "map=%s" % self.map,
  336. "tool=delete",
  337. "ids=%s" % ids]
  338. # run the command
  339. vedit = gcmd.Command(cmd=command, stderr=None)
  340. # reload map (needed for v.edit)
  341. self.driver.ReloadMap()
  342. return True
  343. def MoveSelectedLines(self, move):
  344. """Move selected features
  345. @param move X,Y direction
  346. """
  347. return self.__MoveFeature("move", None, move)
  348. def MoveSelectedVertex(self, coords, move):
  349. """Move selected vertex
  350. Feature geometry is changed.
  351. @param coords click coordinates
  352. @param move X,Y direction
  353. """
  354. return self.__MoveFeature("vertexmove", coords, move)
  355. def __MoveFeature(self, tool, coords, move):
  356. """Move selected vector feature (line, vertex)
  357. @param tool tool for v.edit
  358. @param coords click coordinates
  359. @param move direction (x, y)
  360. """
  361. selected = self.driver.GetSelected()
  362. if len(selected) <= 0:
  363. return False
  364. ids = ",".join(["%d" % v for v in selected])
  365. Debug.msg(4, "Digit.MoveSelectedLines(): ids=%s, move=%s" % \
  366. (ids, move))
  367. if UserSettings.Get(group='vdigit', key='snapping', subkey='value') <= 0.0:
  368. snap = "no"
  369. else:
  370. if UserSettings.Get(group='vdigit', key='snapToVertex', subkey='enabled') is True:
  371. snap = "vertex"
  372. else:
  373. snap = "node"
  374. command = ["v.edit", "--q",
  375. "map=%s" % self.map,
  376. "tool=%s" % tool,
  377. "ids=%s" % ids,
  378. "move=%f,%f" % (float(move[0]),float(move[1])),
  379. "thresh=%f,%f" % (self.driver.GetThreshold(type='selectThresh'), self.driver.GetThreshold(type='snapping')),
  380. "snap=%s" % snap]
  381. if tool == "vertexmove":
  382. command.append("coords=%f,%f" % (float(coords[0]), float(coords[1])))
  383. command.append("-1") # modify only first selected
  384. if UserSettings.Get(group='vdigit', key='backgroundMap', subkey='value') != '':
  385. command.append("bgmap=%s" % UserSettings.Get(group='vdigit', key='backgroundMap', subkey='value'))
  386. # run the command
  387. vedit = gcmd.Command(cmd=command, stderr=None)
  388. # reload map (needed for v.edit)
  389. self.driver.ReloadMap()
  390. return True
  391. def AddVertex(self, coords):
  392. """Add new vertex to the selected line/boundary on position 'coords'
  393. @param coords coordinates to add vertex
  394. """
  395. return self.__ModifyVertex(coords, "vertexadd")
  396. def RemoveVertex(self, coords):
  397. """Remove vertex from the selected line/boundary on position 'coords'
  398. @param coords coordinates to remove vertex
  399. """
  400. return self.__ModifyVertex(coords, "vertexdel")
  401. def __ModifyVertex(self, coords, action):
  402. """Generic method for vertex manipulation
  403. @param coords coordinates
  404. @param action operation to perform
  405. """
  406. try:
  407. line = self.driver.GetSelected()[0]
  408. except:
  409. return False
  410. command = ["v.edit", "--q",
  411. "map=%s" % self.map,
  412. "tool=%s" % action,
  413. "ids=%s" % line,
  414. "coords=%f,%f" % (float(coords[0]),float(coords[1])),
  415. "thresh=%f,%f" % (self.driver.GetThreshold(type='selectThresh'), self.driver.GetThreshold(type='snapping'))]
  416. # run the command
  417. vedit = gcmd.Command(cmd=command, stderr=None)
  418. # reload map (needed for v.edit)
  419. self.driver.ReloadMap()
  420. return True
  421. def SplitLine(self, coords):
  422. """Split selected line/boundary on position 'coords'
  423. @param coords coordinates to split line
  424. """
  425. try:
  426. line = self.driver.GetSelected()[0]
  427. except:
  428. return False
  429. command = ["v.edit", "--q",
  430. "map=%s" % self.map,
  431. "tool=break",
  432. "ids=%s" % line,
  433. "coords=%f,%f" % (float(coords[0]),float(coords[1])),
  434. "thresh=%f" % self.driver.GetThreshold(type='selectThresh')]
  435. # run the command
  436. vedit = gcmd.Command(cmd=command, stderr=None)
  437. # redraw map
  438. self.driver.ReloadMap()
  439. return True
  440. def EditLine(self, line, coords):
  441. """Edit existing line/boundary
  442. @param line id of line to be modified
  443. @param coords list of coordinates of modified line
  444. """
  445. # remove line
  446. vEditDelete = gcmd.Command(['v.edit',
  447. '--q',
  448. 'map=%s' % self.map,
  449. 'tool=delete',
  450. 'ids=%s' % line], stderr=None)
  451. # add line
  452. if len(coords) > 0:
  453. self.AddLine(self.map, "line", coords)
  454. # reload map (needed for v.edit)
  455. self.driver.ReloadMap()
  456. def __ModifyLines(self, tool):
  457. """Generic method to modify selected lines/boundaries
  458. @param tool operation to be performed by v.edit
  459. """
  460. ids = self.driver.GetSelected()
  461. if len(ids) <= 0:
  462. return False
  463. vEdit = ['v.edit',
  464. '--q',
  465. 'map=%s' % self.map,
  466. 'tool=%s' % tool,
  467. 'ids=%s' % ",".join(["%d" % v for v in ids])]
  468. if tool in ['snap', 'connect']:
  469. vEdit.append("thresh=%f,%f" % (self.driver.GetThreshold(type='selectThresh'), self.driver.GetThreshold(type='snapping')))
  470. runCmd = gcmd.Command(vEdit)
  471. # reload map (needed for v.edit)
  472. self.driver.ReloadMap()
  473. return True
  474. def FlipLine(self):
  475. """Flip selected lines/boundaries"""
  476. return self.__ModifyLines('flip')
  477. def MergeLine(self):
  478. """Merge selected lines/boundaries"""
  479. return self.__ModifyLines('merge')
  480. def BreakLine(self):
  481. """Break selected lines/boundaries"""
  482. return self.__ModifyLines('break')
  483. def SnapLine(self):
  484. """Snap selected lines/boundaries"""
  485. return self.__ModifyLines('snap')
  486. def ConnectLine(self):
  487. """Connect selected lines/boundaries"""
  488. return self.__ModifyLines('connect')
  489. def TypeConvForSelectedLines(self):
  490. """Feature type conversion for selected objects.
  491. Supported conversions:
  492. - point <-> centroid
  493. - line <-> boundary
  494. """
  495. return self.__ModifyLines('chtype')
  496. def ZBulkLine(self, pos1, pos2, value, step):
  497. """Provide z bulk-labeling (automated assigment of z coordinate
  498. to 3d lines
  499. @param pos1,pos2 bounding box definition for selecting lines to be labeled
  500. @param value starting value
  501. @param step step value
  502. """
  503. gcmd.Command(['v.edit',
  504. '--q',
  505. 'map=%s' % self.map,
  506. 'tool=zbulk',
  507. 'bbox=%f,%f,%f,%f' % (pos1[0], pos1[1], pos2[0], pos2[1]),
  508. 'zbulk=%f,%f' % (value, step)])
  509. def CopyLine(self, ids=None):
  510. """Copy features from (background) vector map
  511. @param ids list of line ids to be copied
  512. """
  513. if not ids:
  514. ids = self.driver.GetSelected()
  515. if len(ids) <= 0:
  516. return False
  517. vEdit = ['v.edit',
  518. '--q',
  519. 'map=%s' % self.map,
  520. 'tool=copy',
  521. 'ids=%s' % ",".join(["%d" % v for v in ids])]
  522. if UserSettings.Get(group='vdigit', key='backgroundMap', subkey='value') != '':
  523. vEdit.append('bgmap=%s' % UserSettings.Get(group='vdigit', key='backgroundMap', subkey='value'))
  524. runCmd = gcmd.Command(vEdit)
  525. # reload map (needed for v.edit)
  526. self.driver.ReloadMap()
  527. return True
  528. def CopyCats(self, cats, ids):
  529. """Copy given categories to objects with id listed in ids
  530. @param cats list of cats to be copied
  531. @param ids ids of lines to be modified
  532. """
  533. if len(cats) == 0 or len(ids) == 0:
  534. return False
  535. # collect cats
  536. gcmd.Command(['v.edit',
  537. '--q',
  538. 'map=%s' % self.map,
  539. 'tool=catadd',
  540. 'cats=%s' % ",".join(["%d" % v for v in cats]),
  541. 'ids=%s' % ",".join(["%d" % v for v in ids])])
  542. # reload map (needed for v.edit)
  543. self.driver.ReloadMap()
  544. return True
  545. def SelectLinesByQuery(self, pos1, pos2):
  546. """Select features by query
  547. @param pos1, pos2 bounding box definition
  548. """
  549. thresh = self.SelectLinesByQueryThresh()
  550. w, n = pos1
  551. e, s = pos2
  552. if UserSettings.Get(group='vdigit', key='query', subkey='box') == False: # select globaly
  553. vInfo = gcmd.Command(['v.info',
  554. 'map=%s' % self.map,
  555. '-g'])
  556. for item in vInfo.ReadStdOutput():
  557. if 'north' in item:
  558. n = float(item.split('=')[1])
  559. elif 'south' in item:
  560. s = float(item.split('=')[1])
  561. elif 'east' in item:
  562. e = float(item.split('=')[1])
  563. elif 'west' in item:
  564. w = float(item.split('=')[1])
  565. if UserSettings.Get(group='vdigit', key='query', subkey='selection') == 0:
  566. qtype = 'length'
  567. else:
  568. qtype = 'dangle'
  569. vEdit = (['v.edit',
  570. '--q',
  571. 'map=%s' % self.map,
  572. 'tool=select',
  573. 'bbox=%f,%f,%f,%f' % (w, n, e, s),
  574. 'query=%s' % qtype,
  575. 'thresh=0,0,%f' % thresh])
  576. vEditCmd = gcmd.Command(vEdit)
  577. try:
  578. output = vEditCmd.ReadStdOutput()[0] # first line
  579. ids = output.split(',')
  580. ids = map(int, ids) # str -> int
  581. except:
  582. return []
  583. Debug.msg(4, "VEdit.SelectLinesByQuery(): %s" % \
  584. ",".join(["%d" % v for v in ids]))
  585. return ids
  586. def GetLayers(self):
  587. """Return list of layers"""
  588. layerCommand = gcmd.Command(cmd=["v.db.connect",
  589. "-g", "--q",
  590. "map=%s" % self.map],
  591. rerr=None, stderr=None)
  592. if layerCommand.returncode == 0:
  593. layers = []
  594. for line in layerCommand.ReadStdOutput():
  595. lineList = line.split(' ')
  596. layers.append(int(lineList[0]))
  597. return layers
  598. return [1,]
  599. def Undo(self, level=-1):
  600. """Undo not implemented here"""
  601. wx.MessageBox(parent=self.mapWindow, message=_("Undo is not implemented in vedit component. "
  602. "Use vdigit instead."),
  603. caption=_("Message"), style=wx.ID_OK | wx.ICON_INFORMATION | wx.CENTRE)
  604. class VDigit(AbstractDigit):
  605. """
  606. Prototype of digitization class based on v.digit reimplementation
  607. Under development (wxWidgets C/C++ background)
  608. """
  609. def __init__(self, mapwindow):
  610. """Initialization
  611. @param mapwindow reference to mapwindow (MapFrame) instance
  612. @param settings initial settings of digitization tool
  613. """
  614. AbstractDigit.__init__(self, mapwindow)
  615. try:
  616. self.digit = wxvdigit.Digit(self.driver.GetDevice())
  617. except (ImportError, NameError):
  618. self.digit = None
  619. self.toolbar = mapwindow.parent.toolbars['vdigit']
  620. def __del__(self):
  621. del self.digit
  622. def AddPoint (self, map, point, x, y, z=None):
  623. """Add new point/centroid
  624. @param map map name (unused, for compatability with VEdit)
  625. @param point feature type (if true point otherwise centroid)
  626. @param x,y,z coordinates
  627. """
  628. if UserSettings.Get(group='vdigit', key="categoryMode", subkey='selection') == 2:
  629. layer = -1 # -> no category
  630. cat = -1
  631. else:
  632. layer = UserSettings.Get(group='vdigit', key="layer", subkey='value')
  633. cat = self.SetCategory()
  634. if point:
  635. type = wxvdigit.GV_POINT
  636. else:
  637. type = wxvdigit.GV_CENTROID
  638. snap, thresh = self.__getSnapThreshold()
  639. if z:
  640. ret = self.digit.AddLine(type, [x, y, z], layer, cat,
  641. str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
  642. else:
  643. ret = self.digit.AddLine(type, [x, y], layer, cat,
  644. str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
  645. if ret == -1:
  646. raise gcmd.DigitError, _("Adding new feature to vector map <%s> failed.") % map
  647. self.toolbar.EnableUndo()
  648. def AddLine (self, map, line, coords):
  649. """Add line/boundary
  650. @param map map name (unused, for compatability with VEdit)
  651. @param line feature type (if True line, otherwise boundary)
  652. @param coords list of coordinates
  653. """
  654. if len(coords) < 2:
  655. return
  656. if UserSettings.Get(group='vdigit', key="categoryMode", subkey='selection') == 2:
  657. layer = -1 # -> no category
  658. cat = -1
  659. else:
  660. layer = UserSettings.Get(group='vdigit', key="layer", subkey='value')
  661. cat = self.SetCategory()
  662. if line:
  663. type = wxvdigit.GV_LINE
  664. else:
  665. type = wxvdigit.GV_BOUNDARY
  666. listCoords = []
  667. for c in coords:
  668. for x in c:
  669. listCoords.append(x)
  670. snap, thresh = self.__getSnapThreshold()
  671. ret = self.digit.AddLine(type, listCoords, layer, cat,
  672. str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
  673. if ret == -1:
  674. raise gcmd.DigitError, _("Adding new feature to vector map <%s> failed.") % map
  675. self.toolbar.EnableUndo()
  676. def DeleteSelectedLines(self):
  677. """Delete selected features
  678. @return number of deleted lines
  679. """
  680. nlines = self.digit.DeleteLines(UserSettings.Get(group='vdigit', key='delRecord', subkey='enabled'))
  681. if nlines > 0:
  682. self.toolbar.EnableUndo()
  683. return nlines
  684. def MoveSelectedLines(self, move):
  685. """Move selected features
  686. @param move direction (x, y)
  687. """
  688. snap, thresh = self.__getSnapThreshold()
  689. nlines = self.digit.MoveLines(move[0], move[1], 0.0, # TODO 3D
  690. str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
  691. if nlines > 0:
  692. self.toolbar.EnableUndo()
  693. return nlines
  694. def MoveSelectedVertex(self, coords, move):
  695. """Move selected vertex of the line
  696. @param coords click coordinates
  697. @param move X,Y direction
  698. @return 1 vertex moved
  699. @return 0 vertex not moved (not found, line is not selected)
  700. """
  701. snap, thresh = self.__getSnapThreshold()
  702. moved = self.digit.MoveVertex(coords[0], coords[1], 0.0, # TODO 3D
  703. move[0], move[1], 0.0,
  704. str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap,
  705. self.driver.GetThreshold(type='selectThresh'), thresh)
  706. if moved:
  707. self.toolbar.EnableUndo()
  708. return moved
  709. def AddVertex(self, coords):
  710. """Add new vertex to the selected line/boundary on position 'coords'
  711. @param coords coordinates to add vertex
  712. @return 1 vertex added
  713. @return 0 nothing changed
  714. @return -1 on failure
  715. """
  716. added = self.digit.ModifyLineVertex(1, coords[0], coords[1], 0.0, # TODO 3D
  717. self.driver.GetThreshold(type='selectThresh'))
  718. if added > 0:
  719. self.toolbar.EnableUndo()
  720. return added
  721. def RemoveVertex(self, coords):
  722. """Remove vertex from the selected line/boundary on position 'coords'
  723. @param coords coordinates to remove vertex
  724. @return 1 vertex removed
  725. @return 0 nothing changed
  726. @return -1 on failure
  727. """
  728. deleted = self.digit.ModifyLineVertex(0, coords[0], coords[1], 0.0, # TODO 3D
  729. self.driver.GetThreshold(type='selectThresh'))
  730. if deleted > 0:
  731. self.toolbar.EnableUndo()
  732. return deleted
  733. def SplitLine(self, coords):
  734. """Split selected line/boundary on position 'coords'
  735. @param coords coordinates to split line
  736. @return 1 line modified
  737. @return 0 nothing changed
  738. @return -1 error
  739. """
  740. ret = self.digit.SplitLine(coords[0], coords[1], 0.0, # TODO 3D
  741. self.driver.GetThreshold('selectThresh'))
  742. if ret > 0:
  743. self.toolbar.EnableUndo()
  744. return ret
  745. def EditLine(self, line, coords):
  746. """Edit existing line/boundary
  747. @param line id of line to be modified
  748. @param coords list of coordinates of modified line
  749. @return feature id of new line
  750. @return -1 on error
  751. """
  752. try:
  753. lineid = line[0]
  754. except:
  755. lineid = -1
  756. if len(coords) < 2:
  757. self.DeleteSelectedLines()
  758. return 0
  759. listCoords = []
  760. for c in coords:
  761. for x in c:
  762. listCoords.append(x)
  763. snap, thresh = self.__getSnapThreshold()
  764. ret = self.digit.RewriteLine(lineid, listCoords,
  765. str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
  766. if ret > 0:
  767. self.toolbar.EnableUndo()
  768. return ret
  769. def FlipLine(self):
  770. """Flip selected lines/boundaries
  771. @return number of modified lines
  772. @return -1 on error
  773. """
  774. ret = self.digit.FlipLines()
  775. if ret > 0:
  776. self.toolbar.EnableUndo()
  777. return ret
  778. def MergeLine(self):
  779. """Merge selected lines/boundaries
  780. @return number of modified lines
  781. @return -1 on error
  782. """
  783. ret = self.digit.MergeLines()
  784. if ret > 0:
  785. self.toolbar.EnableUndo()
  786. return ret
  787. def BreakLine(self):
  788. """Break selected lines/boundaries
  789. @return number of modified lines
  790. @return -1 on error
  791. """
  792. ret = self.digit.BreakLines()
  793. if ret > 0:
  794. self.toolbar.EnableUndo()
  795. return ret
  796. def SnapLine(self):
  797. """Snap selected lines/boundaries
  798. @return on success
  799. @return -1 on error
  800. """
  801. snap, thresh = self.__getSnapThreshold()
  802. ret = self.digit.SnapLines(thresh)
  803. if ret == 0:
  804. self.toolbar.EnableUndo()
  805. return ret
  806. def ConnectLine(self):
  807. """Connect selected lines/boundaries
  808. @return 1 lines connected
  809. @return 0 lines not connected
  810. @return -1 on error
  811. """
  812. snap, thresh = self.__getSnapThreshold()
  813. ret = self.digit.ConnectLines(thresh)
  814. if ret > 0:
  815. self.toolbar.EnableUndo()
  816. return ret
  817. def CopyLine(self, ids=None):
  818. """Copy features from (background) vector map
  819. @param ids list of line ids to be copied
  820. @return number of copied features
  821. @return -1 on error
  822. """
  823. ret = self.digit.CopyLines(ids, str(UserSettings.Get(group='vdigit', key='backgroundMap', subkey='value')))
  824. if ret > 0:
  825. self.toolbar.EnableUndo()
  826. return ret
  827. def CopyCats(self, cats, ids):
  828. """Copy given categories to objects with id listed in ids
  829. @param cats list of cats to be copied
  830. @param ids ids of lines to be modified
  831. @return number of modified features
  832. @return -1 on error
  833. """
  834. if len(cats) == 0 or len(ids) == 0:
  835. return 0
  836. ret = self.digit.CopyCats(cats, ids)
  837. if ret > 0:
  838. self.toolbar.EnableUndo()
  839. return ret
  840. def SelectLinesByQuery(self, pos1, pos2):
  841. """Select features by query
  842. @param pos1, pos2 bounding box definition
  843. """
  844. thresh = self.SelectLinesByQueryThresh()
  845. w, n = pos1
  846. e, s = pos2
  847. query = wxvdigit.QUERY_UNKNOWN
  848. if UserSettings.Get(group='vdigit', key='query', subkey='selection') == 0:
  849. query = wxvdigit.QUERY_LENGTH
  850. else:
  851. query = wxvdigit.QUERY_DANGLE
  852. type = wxvdigit.GV_POINTS | wxvdigit.GV_LINES # TODO: 3D
  853. ids = self.digit.SelectLinesByQuery(w, n, 0.0, e, s, 1000.0,
  854. UserSettings.Get(group='vdigit', key='query', subkey='box'),
  855. query, type, thresh)
  856. Debug.msg(4, "VDigit.SelectLinesByQuery(): %s" % \
  857. ",".join(["%d" % v for v in ids]))
  858. return ids
  859. def GetLineCats(self, line=-1):
  860. """Get layer/category pairs from given (selected) line
  861. @param line feature id (-1 for first selected line)
  862. """
  863. return self.digit.GetLineCats(line)
  864. def SetLineCats(self, line, layer, cats, add=True):
  865. """Set categories for given line and layer
  866. @param line feature id
  867. @param layer layer number (-1 for first selected line)
  868. @param cats list of categories
  869. @param add if True to add, otherwise do delete categories
  870. @return new feature id (feature need to be rewritten)
  871. @return -1 on error
  872. """
  873. ret = self.digit.SetLineCats(line, layer, cats, add)
  874. if ret > 0:
  875. self.toolbar.EnableUndo()
  876. return ret
  877. def GetLayers(self):
  878. """Get list of layers"""
  879. return self.digit.GetLayers()
  880. def TypeConvForSelectedLines(self):
  881. """Feature type conversion for selected objects.
  882. Supported conversions:
  883. - point <-> centroid
  884. - line <-> boundary
  885. @return number of modified features
  886. @return -1 on error
  887. """
  888. ret = self.digit.TypeConvLines()
  889. if ret > 0:
  890. self.toolbar.EnableUndo()
  891. return ret
  892. def Undo(self, level=-1):
  893. """Undo action
  894. @param level levels to undo (0 to revert all)
  895. @return id of current changeset
  896. """
  897. try:
  898. ret = self.digit.Undo(level)
  899. except SystemExit:
  900. ret = -2
  901. if ret == -2:
  902. raise gcmd.DigitError, _("Undo failed, data corrupted.")
  903. self.mapWindow.UpdateMap(render=False)
  904. if ret < 0: # disable undo tool
  905. self.toolbar.EnableUndo(False)
  906. def GetUndoLevel(self):
  907. """Get undo level (number of active changesets)"""
  908. return self.digit.GetUndoLevel()
  909. def __getSnapThreshold(self):
  910. """Get snap mode and threshold value
  911. @return (snap, thresh)
  912. """
  913. thresh = self.driver.GetThreshold()
  914. if thresh > 0.0:
  915. if UserSettings.Get(group='vdigit', key='snapToVertex', subkey='enabled') is True:
  916. snap = wxvdigit.SNAPVERTEX
  917. else:
  918. snap = wxvdigit.SNAP
  919. else:
  920. snap = wxvdigit.NO_SNAP
  921. return (snap, thresh)
  922. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':
  923. class Digit(VEdit):
  924. """Default digit class"""
  925. def __init__(self, mapwindow):
  926. VEdit.__init__(self, mapwindow)
  927. self.type = 'vedit'
  928. else:
  929. class Digit(VDigit):
  930. """Default digit class"""
  931. def __init__(self, mapwindow):
  932. VDigit.__init__(self, mapwindow)
  933. self.type = 'vdigit'
  934. def __del__(self):
  935. VDigit.__del__(self)
  936. class AbstractDisplayDriver:
  937. """Abstract classs for display driver"""
  938. def __init__(self, parent, mapwindow):
  939. """Initialization
  940. @param parent
  941. @param mapwindow reference to mapwindow (MFrame)
  942. """
  943. self.parent = parent
  944. self.mapwindow = mapwindow
  945. self.ids = {} # dict[g6id] = [pdcId]
  946. self.selected = [] # list of selected objects (grassId!)
  947. def GetThreshold(self, type='snapping', value=None, units=None):
  948. """Return threshold in map units
  949. @param value threshold to be set up
  950. @param units units (map, screen)
  951. """
  952. if value is None:
  953. value = UserSettings.Get(group='vdigit', key=type, subkey='value')
  954. if units is None:
  955. units = UserSettings.Get(group='vdigit', key=type, subkey='units')
  956. if units == "screen pixels":
  957. # pixel -> cell
  958. reg = self.mapwindow.Map.region
  959. if reg['nsres'] > reg['ewres']:
  960. res = reg['nsres']
  961. else:
  962. res = reg['ewres']
  963. threshold = value * res
  964. else:
  965. threshold = value
  966. Debug.msg(4, "AbstractDisplayDriver.GetThreshold(): type=%s, thresh=%f" % (type, threshold))
  967. return threshold
  968. class CDisplayDriver(AbstractDisplayDriver):
  969. """
  970. Display driver using grass6_wxdriver module
  971. """
  972. def __init__(self, parent, mapwindow):
  973. """Initialization
  974. @param parent
  975. @param mapwindow reference to mapwindow (MFrame)
  976. """
  977. AbstractDisplayDriver.__init__(self, parent, mapwindow)
  978. self.mapWindow = mapwindow
  979. # initialize wx display driver
  980. try:
  981. self.__display = wxvdigit.DisplayDriver(mapwindow.pdcVector)
  982. except:
  983. self.__display = None
  984. self.UpdateSettings()
  985. def GetDevice(self):
  986. """Get device"""
  987. return self.__display
  988. def SetDevice(self, pdc):
  989. """Set device for driver
  990. @param pdc wx.PseudoDC instance
  991. """
  992. self.__display.SetDevice(pdc)
  993. def Reset(self, map):
  994. """Reset map
  995. Open or close the vector map by driver.
  996. @param map map name or None to close the map
  997. @return 0 on success (close map)
  998. @return topo level on success (open map)
  999. @return non-zero (close map)
  1000. @return -1 on error (open map)
  1001. """
  1002. if map:
  1003. name, mapset = map.split('@')
  1004. try:
  1005. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':
  1006. ret = self.__display.OpenMap(str(name), str(mapset), False)
  1007. else:
  1008. ret = self.__display.OpenMap(str(name), str(mapset), True)
  1009. except SystemExit:
  1010. ret = -1
  1011. else:
  1012. ret = self.__display.CloseMap()
  1013. return ret
  1014. def ReloadMap(self):
  1015. """Reload map (close and re-open).
  1016. Needed for v.edit, TODO: get rid of that..."""
  1017. Debug.msg(4, "CDisplayDriver.ReloadMap():")
  1018. self.__display.ReloadMap()
  1019. def DrawMap(self):
  1020. """Draw vector map layer content
  1021. @return wx.Image instance
  1022. """
  1023. nlines = self.__display.DrawMap(True) # force
  1024. Debug.msg(3, "CDisplayDriver.DrawMap(): nlines=%d" % nlines)
  1025. return nlines
  1026. def SelectLinesByBox(self, begin, end, type=0):
  1027. """Select vector features by given bounding box.
  1028. If type is given, only vector features of given type are selected.
  1029. @param begin,end bounding box definition
  1030. @param type select only objects of given type
  1031. """
  1032. x1, y1 = begin
  1033. x2, y2 = end
  1034. nselected = self.__display.SelectLinesByBox(x1, y1, -1.0 * wxvdigit.PORT_DOUBLE_MAX,
  1035. x2, y2, wxvdigit.PORT_DOUBLE_MAX,
  1036. type)
  1037. Debug.msg(4, "CDisplayDriver.SelectLinesByBox(): selected=%d" % \
  1038. nselected)
  1039. return nselected
  1040. def SelectLineByPoint(self, point, type=0):
  1041. """Select vector feature by coordinates of click point (in given threshold).
  1042. If type is given, only vector features of given type are selected.
  1043. @param point click coordinates (bounding box given by threshold)
  1044. @param type select only objects of given type
  1045. """
  1046. pointOnLine = self.__display.SelectLineByPoint(point[0], point[1], 0.0,
  1047. self.GetThreshold(type='selectThresh'),
  1048. type, 0); # without_z
  1049. if len(pointOnLine) > 0:
  1050. Debug.msg(4, "CDisplayDriver.SelectLineByPoint(): pointOnLine=%f,%f" % \
  1051. (pointOnLine[0], pointOnLine[1]))
  1052. return pointOnLine
  1053. else:
  1054. Debug.msg(4, "CDisplayDriver.SelectLineByPoint(): no line found")
  1055. return None
  1056. def GetSelected(self, grassId=True):
  1057. """Return ids of selected vector features
  1058. @param grassId if grassId is True returns GRASS ids, otherwise
  1059. internal ids of objects drawn in PseudoDC"""
  1060. if grassId:
  1061. selected = self.__display.GetSelected(True)
  1062. else:
  1063. selected = self.__display.GetSelected(False)
  1064. Debug.msg(4, "CDisplayDriver.GetSelected(): grassId=%d, ids=%s" % \
  1065. (grassId, (",".join(["%d" % v for v in selected]))))
  1066. return selected
  1067. def GetDuplicates(self):
  1068. """Return ids of (selected) duplicated vector features
  1069. """
  1070. # -> id : (list of ids)
  1071. dupl = dict(self.__display.GetDuplicates())
  1072. vdigitComp = UserSettings.Get(group='advanced', key='digitInterface', subkey='type')
  1073. # -> id : ((id, cat), ...)
  1074. dupl_full = {}
  1075. for key in dupl.keys():
  1076. dupl_full[key] = []
  1077. for id in dupl[key]:
  1078. catStr = ''
  1079. # categories not supported for v.edit !
  1080. if vdigitComp == 'vdigit':
  1081. cats = self.parent.GetLineCats(line=id)
  1082. for layer in cats.keys():
  1083. if len(cats[layer]) > 0:
  1084. catStr = "%d: (" % layer
  1085. for cat in cats[layer]:
  1086. catStr += "%d," % cat
  1087. catStr = catStr.rstrip(',')
  1088. catStr += ')'
  1089. dupl_full[key].append([id, catStr])
  1090. return dupl_full
  1091. def GetSelectedVertex(self, coords):
  1092. """Get PseudoDC id(s) of vertex (of selected line)
  1093. on position 'coords'
  1094. @param coords click position
  1095. """
  1096. x, y = coords
  1097. id = self.__display.GetSelectedVertex(x, y, self.GetThreshold(type='selectThresh'))
  1098. Debug.msg(4, "CDisplayDriver.GetSelectedVertex(): id=%s" % \
  1099. (",".join(["%d" % v for v in id])))
  1100. return id
  1101. def SetSelected(self, id):
  1102. """Set selected vector features
  1103. @param id line id to be selected
  1104. """
  1105. Debug.msg(4, "CDisplayDriver.SetSelected(): id=%s" % \
  1106. ",".join(["%d" % v for v in id]))
  1107. self.__display.SetSelected(id)
  1108. def UnSelect(self, id):
  1109. """Unselect vector features
  1110. @param id list of feature id(s)
  1111. """
  1112. Debug.msg(4, "CDisplayDriver.UnSelect(): id=%s" % \
  1113. ",".join(["%d" % v for v in id]))
  1114. self.__display.UnSelect(id)
  1115. def UpdateRegion(self):
  1116. """Set geographical region
  1117. Needed for 'cell2pixel' conversion"""
  1118. map = self.mapwindow.Map
  1119. reg = map.region
  1120. self.__display.SetRegion(reg['n'],
  1121. reg['s'],
  1122. reg['e'],
  1123. reg['w'],
  1124. reg['nsres'],
  1125. reg['ewres'],
  1126. reg['center_easting'],
  1127. reg['center_northing'],
  1128. map.width, map.height)
  1129. def GetMapBoundingBox(self):
  1130. """Return bounding box of given vector map layer
  1131. @return (w,s,b,e,n,t)
  1132. """
  1133. return self.__display.GetMapBoundingBox()
  1134. def DrawSelected(self, draw=True):
  1135. """Show/hide selected features"""
  1136. self.__display.DrawSelected(draw)
  1137. def UpdateSettings(self):
  1138. """Update display driver settings"""
  1139. # TODO map units
  1140. if not self.__display:
  1141. return
  1142. self.__display.UpdateSettings (wx.Color(UserSettings.Get(group='vdigit', key='symbolHighlight', subkey='color')[0],
  1143. UserSettings.Get(group='vdigit', key='symbolHighlight', subkey='color')[1],
  1144. UserSettings.Get(group='vdigit', key='symbolHighlight', subkey='color')[2],
  1145. 255).GetRGB(),
  1146. UserSettings.Get(group='vdigit', key='checkForDupl', subkey='enabled'),
  1147. wx.Color(UserSettings.Get(group='vdigit', key='symbolHighlightDupl', subkey='color')[0],
  1148. UserSettings.Get(group='vdigit', key='symbolHighlightDupl', subkey='color')[1],
  1149. UserSettings.Get(group='vdigit', key='symbolHighlightDupl', subkey='color')[2],
  1150. 255).GetRGB(),
  1151. UserSettings.Get(group='vdigit', key='symbolPoint', subkey='enabled'),
  1152. wx.Color(UserSettings.Get(group='vdigit', key='symbolPoint', subkey='color')[0],
  1153. UserSettings.Get(group='vdigit', key='symbolPoint', subkey='color')[1],
  1154. UserSettings.Get(group='vdigit', key='symbolPoint', subkey='color')[2],
  1155. 255).GetRGB(),
  1156. UserSettings.Get(group='vdigit', key='symbolLine', subkey='enabled'),
  1157. wx.Color(UserSettings.Get(group='vdigit', key='symbolLine', subkey='color')[0],
  1158. UserSettings.Get(group='vdigit', key='symbolLine', subkey='color')[1],
  1159. UserSettings.Get(group='vdigit', key='symbolLine', subkey='color')[2],
  1160. 255).GetRGB(),
  1161. UserSettings.Get(group='vdigit', key='symbolBoundaryNo', subkey='enabled'),
  1162. wx.Color(UserSettings.Get(group='vdigit', key='symbolBoundaryNo', subkey='color')[0],
  1163. UserSettings.Get(group='vdigit', key='symbolBoundaryNo', subkey='color')[1],
  1164. UserSettings.Get(group='vdigit', key='symbolBoundaryNo', subkey='color')[2],
  1165. 255).GetRGB(),
  1166. UserSettings.Get(group='vdigit', key='symbolBoundaryOne', subkey='enabled'),
  1167. wx.Color(UserSettings.Get(group='vdigit', key='symbolBoundaryOne', subkey='color')[0],
  1168. UserSettings.Get(group='vdigit', key='symbolBoundaryOne', subkey='color')[1],
  1169. UserSettings.Get(group='vdigit', key='symbolBoundaryOne', subkey='color')[2],
  1170. 255).GetRGB(),
  1171. UserSettings.Get(group='vdigit', key='symbolBoundaryTwo', subkey='enabled'),
  1172. wx.Color(UserSettings.Get(group='vdigit', key='symbolBoundaryTwo', subkey='color')[0],
  1173. UserSettings.Get(group='vdigit', key='symbolBoundaryTwo', subkey='color')[1],
  1174. UserSettings.Get(group='vdigit', key='symbolBoundaryTwo', subkey='color')[2],
  1175. 255).GetRGB(),
  1176. UserSettings.Get(group='vdigit', key='symbolCentroidIn', subkey='enabled'),
  1177. wx.Color(UserSettings.Get(group='vdigit', key='symbolCentroidIn', subkey='color')[0],
  1178. UserSettings.Get(group='vdigit', key='symbolCentroidIn', subkey='color')[1],
  1179. UserSettings.Get(group='vdigit', key='symbolCentroidIn', subkey='color')[2],
  1180. 255).GetRGB(),
  1181. UserSettings.Get(group='vdigit', key='symbolCentroidOut', subkey='enabled'),
  1182. wx.Color(UserSettings.Get(group='vdigit', key='symbolCentroidOut', subkey='color')[0],
  1183. UserSettings.Get(group='vdigit', key='symbolCentroidOut', subkey='color')[1],
  1184. UserSettings.Get(group='vdigit', key='symbolCentroidOut', subkey='color')[2],
  1185. 255).GetRGB(),
  1186. UserSettings.Get(group='vdigit', key='symbolCentroidDup', subkey='enabled'),
  1187. wx.Color(UserSettings.Get(group='vdigit', key='symbolCentroidDup', subkey='color')[0],
  1188. UserSettings.Get(group='vdigit', key='symbolCentroidDup', subkey='color')[1],
  1189. UserSettings.Get(group='vdigit', key='symbolCentroidDup', subkey='color')[2],
  1190. 255).GetRGB(),
  1191. UserSettings.Get(group='vdigit', key='symbolNodeOne', subkey='enabled'),
  1192. wx.Color(UserSettings.Get(group='vdigit', key='symbolNodeOne', subkey='color')[0],
  1193. UserSettings.Get(group='vdigit', key='symbolNodeOne', subkey='color')[1],
  1194. UserSettings.Get(group='vdigit', key='symbolNodeOne', subkey='color')[2],
  1195. 255).GetRGB(),
  1196. UserSettings.Get(group='vdigit', key='symbolNodeTwo', subkey='enabled'),
  1197. wx.Color(UserSettings.Get(group='vdigit', key='symbolNodeTwo', subkey='color')[0],
  1198. UserSettings.Get(group='vdigit', key='symbolNodeTwo', subkey='color')[1],
  1199. UserSettings.Get(group='vdigit', key='symbolNodeTwo', subkey='color')[2],
  1200. 255).GetRGB(),
  1201. UserSettings.Get(group='vdigit', key='symbolVertex', subkey='enabled'),
  1202. wx.Color(UserSettings.Get(group='vdigit', key='symbolVertex', subkey='color')[0],
  1203. UserSettings.Get(group='vdigit', key='symbolVertex', subkey='color')[1],
  1204. UserSettings.Get(group='vdigit', key='symbolVertex', subkey='color')[2],
  1205. 255).GetRGB(),
  1206. UserSettings.Get(group='vdigit', key='symbolArea', subkey='enabled'),
  1207. wx.Color(UserSettings.Get(group='vdigit', key='symbolArea', subkey='color')[0],
  1208. UserSettings.Get(group='vdigit', key='symbolArea', subkey='color')[1],
  1209. UserSettings.Get(group='vdigit', key='symbolArea', subkey='color')[2],
  1210. 255).GetRGB(),
  1211. UserSettings.Get(group='vdigit', key='symbolDirection', subkey='enabled'),
  1212. wx.Color(UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[0],
  1213. UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[1],
  1214. UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[2],
  1215. 255).GetRGB(),
  1216. UserSettings.Get(group='vdigit', key='lineWidth', subkey='value'))
  1217. class VDigitSettingsDialog(wx.Dialog):
  1218. """
  1219. Standard settings dialog for digitization purposes
  1220. """
  1221. def __init__(self, parent, title, style=wx.DEFAULT_DIALOG_STYLE):
  1222. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title, style=style)
  1223. self.parent = parent # mapdisplay.BufferedWindow class instance
  1224. # notebook
  1225. notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  1226. self.__CreateSymbologyPage(notebook)
  1227. parent.digit.SetCategory() # update category number (next to use)
  1228. self.__CreateGeneralPage(notebook)
  1229. self.__CreateAttributesPage(notebook)
  1230. self.__CreateQueryPage(notebook)
  1231. # buttons
  1232. btnApply = wx.Button(self, wx.ID_APPLY)
  1233. btnCancel = wx.Button(self, wx.ID_CANCEL)
  1234. btnSave = wx.Button(self, wx.ID_SAVE)
  1235. btnSave.SetDefault()
  1236. # bindigs
  1237. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  1238. btnApply.SetToolTipString(_("Apply changes for this session"))
  1239. btnApply.SetDefault()
  1240. btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
  1241. btnSave.SetToolTipString(_("Close dialog and save changes to user settings file"))
  1242. btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  1243. btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  1244. # sizers
  1245. btnSizer = wx.StdDialogButtonSizer()
  1246. btnSizer.AddButton(btnCancel)
  1247. btnSizer.AddButton(btnApply)
  1248. btnSizer.AddButton(btnSave)
  1249. btnSizer.Realize()
  1250. mainSizer = wx.BoxSizer(wx.VERTICAL)
  1251. mainSizer.Add(item=notebook, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  1252. mainSizer.Add(item=btnSizer, proportion=0,
  1253. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  1254. self.SetSizer(mainSizer)
  1255. mainSizer.Fit(self)
  1256. def __CreateSymbologyPage(self, notebook):
  1257. """Create notebook page concerning with symbology settings"""
  1258. panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
  1259. notebook.AddPage(page=panel, text=_("Symbology"))
  1260. sizer = wx.BoxSizer(wx.VERTICAL)
  1261. flexSizer = wx.FlexGridSizer (cols=3, hgap=5, vgap=5)
  1262. flexSizer.AddGrowableCol(0)
  1263. self.symbology = {}
  1264. for label, key in self.__SymbologyData():
  1265. textLabel = wx.StaticText(panel, wx.ID_ANY, label)
  1266. color = csel.ColourSelect(panel, id=wx.ID_ANY,
  1267. colour=UserSettings.Get(group='vdigit', key=key, subkey='color'), size=(25, 25))
  1268. isEnabled = UserSettings.Get(group='vdigit', key=key, subkey='enabled')
  1269. if isEnabled is not None:
  1270. enabled = wx.CheckBox(panel, id=wx.ID_ANY, label="")
  1271. enabled.SetValue(isEnabled)
  1272. self.symbology[key] = (enabled, color)
  1273. else:
  1274. enabled = (1, 1)
  1275. self.symbology[key] = (None, color)
  1276. flexSizer.Add(textLabel, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1277. flexSizer.Add(enabled, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
  1278. flexSizer.Add(color, proportion=0, flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1279. color.SetName("GetColour")
  1280. sizer.Add(item=flexSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=10)
  1281. panel.SetSizer(sizer)
  1282. return panel
  1283. def __CreateGeneralPage(self, notebook):
  1284. """Create notebook page concerning with symbology settings"""
  1285. panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
  1286. notebook.AddPage(page=panel, text=_("General"))
  1287. border = wx.BoxSizer(wx.VERTICAL)
  1288. #
  1289. # display section
  1290. #
  1291. box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Display"))
  1292. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1293. flexSizer = wx.FlexGridSizer (cols=3, hgap=5, vgap=5)
  1294. flexSizer.AddGrowableCol(0)
  1295. # line width
  1296. text = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Line width"))
  1297. self.lineWidthValue = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(75, -1),
  1298. initial=UserSettings.Get(group='vdigit', key="lineWidth", subkey='value'),
  1299. min=1, max=1e6)
  1300. units = wx.StaticText(parent=panel, id=wx.ID_ANY, size=(115, -1),
  1301. label=UserSettings.Get(group='vdigit', key="lineWidth", subkey='units'),
  1302. style=wx.ALIGN_LEFT)
  1303. flexSizer.Add(text, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1304. flexSizer.Add(self.lineWidthValue, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
  1305. flexSizer.Add(units, proportion=0, flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
  1306. border=10)
  1307. sizer.Add(item=flexSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=1)
  1308. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  1309. #
  1310. # snapping section
  1311. #
  1312. box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Snapping"))
  1313. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1314. flexSizer1 = wx.FlexGridSizer (cols=3, hgap=5, vgap=5)
  1315. flexSizer1.AddGrowableCol(0)
  1316. flexSizer2 = wx.FlexGridSizer (cols=2, hgap=5, vgap=5)
  1317. flexSizer2.AddGrowableCol(0)
  1318. # snapping
  1319. text = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Snapping threshold"))
  1320. self.snappingValue = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(75, -1),
  1321. initial=UserSettings.Get(group='vdigit', key="snapping", subkey='value'),
  1322. min=0, max=1e6)
  1323. self.snappingValue.Bind(wx.EVT_SPINCTRL, self.OnChangeSnappingValue)
  1324. self.snappingUnit = wx.Choice(parent=panel, id=wx.ID_ANY, size=(125, -1),
  1325. choices=["screen pixels", "map units"])
  1326. self.snappingUnit.SetStringSelection(UserSettings.Get(group='vdigit', key="snapping", subkey='units'))
  1327. self.snappingUnit.Bind(wx.EVT_CHOICE, self.OnChangeSnappingUnits)
  1328. flexSizer1.Add(text, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1329. flexSizer1.Add(self.snappingValue, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
  1330. flexSizer1.Add(self.snappingUnit, proportion=0, flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1331. # background map
  1332. text = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Background vector map"))
  1333. self.backgroundMap = gselect.Select(parent=panel, id=wx.ID_ANY, size=(200,-1),
  1334. type="vector", exceptOf=[self.parent.digit.map])
  1335. self.backgroundMap.SetValue(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value'))
  1336. self.backgroundMap.Bind(wx.EVT_TEXT, self.OnChangeBackgroundMap)
  1337. flexSizer2.Add(text, proportion=1, flag=wx.ALIGN_CENTER_VERTICAL)
  1338. flexSizer2.Add(self.backgroundMap, proportion=1, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
  1339. #flexSizer.Add(self.snappingUnit, proportion=0, flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1340. vertexSizer = wx.BoxSizer(wx.VERTICAL)
  1341. self.snapVertex = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1342. label=_("Snap also to vertex"))
  1343. self.snapVertex.SetValue(UserSettings.Get(group='vdigit', key="snapToVertex", subkey='enabled'))
  1344. vertexSizer.Add(item=self.snapVertex, proportion=0, flag=wx.EXPAND)
  1345. self.mapUnits = self.parent.MapWindow.Map.ProjInfo()['units']
  1346. self.snappingInfo = wx.StaticText(parent=panel, id=wx.ID_ANY,
  1347. label=_("Snapping threshold is %(value).1f %(units)s") % \
  1348. {'value' : self.parent.digit.driver.GetThreshold(),
  1349. 'units' : self.mapUnits})
  1350. vertexSizer.Add(item=self.snappingInfo, proportion=0,
  1351. flag=wx.ALL | wx.EXPAND, border=1)
  1352. sizer.Add(item=flexSizer1, proportion=1, flag=wx.TOP | wx.LEFT | wx.EXPAND, border=1)
  1353. sizer.Add(item=flexSizer2, proportion=1, flag=wx.TOP | wx.LEFT | wx.EXPAND, border=1)
  1354. sizer.Add(item=vertexSizer, proportion=1, flag=wx.BOTTOM | wx.LEFT | wx.EXPAND, border=1)
  1355. border.Add(item=sizer, proportion=0, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
  1356. #
  1357. # select box
  1358. #
  1359. box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Select vector features"))
  1360. # feature type
  1361. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1362. inSizer = wx.BoxSizer(wx.HORIZONTAL)
  1363. self.selectFeature = {}
  1364. for feature in ('Point', 'Line',
  1365. 'Centroid', 'Boundary'):
  1366. chkbox = wx.CheckBox(parent=panel, label=feature)
  1367. self.selectFeature[feature] = chkbox.GetId()
  1368. chkbox.SetValue(UserSettings.Get(group='vdigit', key='selectFeature'+feature, subkey='enabled'))
  1369. inSizer.Add(item=chkbox, proportion=0,
  1370. flag=wx.EXPAND | wx.ALL, border=5)
  1371. sizer.Add(item=inSizer, proportion=0, flag=wx.EXPAND)
  1372. # threshold
  1373. flexSizer = wx.FlexGridSizer (cols=3, hgap=5, vgap=5)
  1374. flexSizer.AddGrowableCol(0)
  1375. text = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Select threshold"))
  1376. self.selectThreshValue = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(75, -1),
  1377. initial=UserSettings.Get(group='vdigit', key="selectThresh", subkey='value'),
  1378. min=1, max=1e6)
  1379. units = wx.StaticText(parent=panel, id=wx.ID_ANY, size=(115, -1),
  1380. label=UserSettings.Get(group='vdigit', key="lineWidth", subkey='units'),
  1381. style=wx.ALIGN_LEFT)
  1382. flexSizer.Add(text, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1383. flexSizer.Add(self.selectThreshValue, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
  1384. flexSizer.Add(units, proportion=0, flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
  1385. border=10)
  1386. self.checkForDupl = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1387. label=_("Check for duplicates"))
  1388. self.checkForDupl.SetValue(UserSettings.Get(group='vdigit', key="checkForDupl", subkey='enabled'))
  1389. flexSizer.Add(item=self.checkForDupl, proportion=0, flag=wx.EXPAND)
  1390. sizer.Add(item=flexSizer, proportion=0, flag=wx.EXPAND)
  1391. border.Add(item=sizer, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
  1392. #
  1393. # digitize lines box
  1394. #
  1395. box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Digitize line features"))
  1396. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1397. self.intersect = wx.CheckBox(parent=panel, label=_("Break lines on intersection"))
  1398. self.intersect.SetValue(UserSettings.Get(group='vdigit', key='breakLines', subkey='enabled'))
  1399. sizer.Add(item=self.intersect, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
  1400. border.Add(item=sizer, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
  1401. #
  1402. # save-on-exit box
  1403. #
  1404. box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Save changes"))
  1405. # save changes on exit?
  1406. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1407. self.save = wx.CheckBox(parent=panel, label=_("Save changes on exit"))
  1408. self.save.SetValue(UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled'))
  1409. sizer.Add(item=self.save, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
  1410. border.Add(item=sizer, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
  1411. panel.SetSizer(border)
  1412. return panel
  1413. def __CreateQueryPage(self, notebook):
  1414. """Create notebook page for query tool"""
  1415. panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
  1416. notebook.AddPage(page=panel, text=_("Query tool"))
  1417. border = wx.BoxSizer(wx.VERTICAL)
  1418. #
  1419. # query tool box
  1420. #
  1421. box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Choose query tool"))
  1422. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1423. LocUnits = self.parent.MapWindow.Map.ProjInfo()['units']
  1424. self.queryBox = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_("Select by box"))
  1425. self.queryBox.SetValue(UserSettings.Get(group='vdigit', key="query", subkey='box'))
  1426. sizer.Add(item=self.queryBox, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
  1427. sizer.Add((0, 5))
  1428. #
  1429. # length
  1430. #
  1431. self.queryLength = wx.RadioButton(parent=panel, id=wx.ID_ANY, label=_("length"))
  1432. self.queryLength.Bind(wx.EVT_RADIOBUTTON, self.OnChangeQuery)
  1433. sizer.Add(item=self.queryLength, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
  1434. flexSizer = wx.FlexGridSizer (cols=4, hgap=5, vgap=5)
  1435. flexSizer.AddGrowableCol(0)
  1436. txt = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Select lines"))
  1437. self.queryLengthSL = wx.Choice (parent=panel, id=wx.ID_ANY,
  1438. choices = [_("shorter than"), _("longer than")])
  1439. self.queryLengthSL.SetSelection(UserSettings.Get(group='vdigit', key="queryLength", subkey='than-selection'))
  1440. self.queryLengthValue = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(100, -1),
  1441. initial=1,
  1442. min=0, max=1e6)
  1443. self.queryLengthValue.SetValue(UserSettings.Get(group='vdigit', key="queryLength", subkey='thresh'))
  1444. units = wx.StaticText(parent=panel, id=wx.ID_ANY, label="%s" % LocUnits)
  1445. flexSizer.Add(txt, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1446. flexSizer.Add(self.queryLengthSL, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
  1447. flexSizer.Add(self.queryLengthValue, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
  1448. flexSizer.Add(units, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1449. sizer.Add(item=flexSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
  1450. #
  1451. # dangle
  1452. #
  1453. self.queryDangle = wx.RadioButton(parent=panel, id=wx.ID_ANY, label=_("dangle"))
  1454. self.queryDangle.Bind(wx.EVT_RADIOBUTTON, self.OnChangeQuery)
  1455. sizer.Add(item=self.queryDangle, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
  1456. flexSizer = wx.FlexGridSizer (cols=4, hgap=5, vgap=5)
  1457. flexSizer.AddGrowableCol(0)
  1458. txt = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Select dangles"))
  1459. self.queryDangleSL = wx.Choice (parent=panel, id=wx.ID_ANY,
  1460. choices = [_("shorter than"), _("longer than")])
  1461. self.queryDangleSL.SetSelection(UserSettings.Get(group='vdigit', key="queryDangle", subkey='than-selection'))
  1462. self.queryDangleValue = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(100, -1),
  1463. initial=1,
  1464. min=0, max=1e6)
  1465. self.queryDangleValue.SetValue(UserSettings.Get(group='vdigit', key="queryDangle", subkey='thresh'))
  1466. units = wx.StaticText(parent=panel, id=wx.ID_ANY, label="%s" % LocUnits)
  1467. flexSizer.Add(txt, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1468. flexSizer.Add(self.queryDangleSL, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
  1469. flexSizer.Add(self.queryDangleValue, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
  1470. flexSizer.Add(units, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1471. sizer.Add(item=flexSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
  1472. if UserSettings.Get(group='vdigit', key="query", subkey='selection') == 0:
  1473. self.queryLength.SetValue(True)
  1474. else:
  1475. self.queryDangle.SetValue(True)
  1476. # enable & disable items
  1477. self.OnChangeQuery(None)
  1478. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  1479. panel.SetSizer(border)
  1480. return panel
  1481. def __CreateAttributesPage(self, notebook):
  1482. """Create notebook page for query tool"""
  1483. panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
  1484. notebook.AddPage(page=panel, text=_("Attributes"))
  1485. border = wx.BoxSizer(wx.VERTICAL)
  1486. #
  1487. # add new record
  1488. #
  1489. box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Digitize new feature"))
  1490. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1491. # checkbox
  1492. self.addRecord = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1493. label=_("Add new record into table"))
  1494. self.addRecord.SetValue(UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled'))
  1495. sizer.Add(item=self.addRecord, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
  1496. # settings
  1497. flexSizer = wx.FlexGridSizer(cols=2, hgap=3, vgap=3)
  1498. flexSizer.AddGrowableCol(0)
  1499. settings = ((_("Layer"), 1), (_("Category"), 1), (_("Mode"), _("Next to use")))
  1500. # layer
  1501. text = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Layer"))
  1502. if self.parent.digit.map:
  1503. layers = map(str, self.parent.digit.GetLayers())
  1504. if len(layers) == 0:
  1505. layers = [str(UserSettings.Get(group='vdigit', key="layer", subkey='value')), ]
  1506. else:
  1507. layers = [str(UserSettings.Get(group='vdigit', key="layer", subkey='value')), ]
  1508. self.layer = wx.Choice(parent=panel, id=wx.ID_ANY, size=(125, -1),
  1509. choices=layers)
  1510. self.layer.SetStringSelection(str(UserSettings.Get(group='vdigit', key="layer", subkey='value')))
  1511. flexSizer.Add(item=text, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1512. flexSizer.Add(item=self.layer, proportion=0,
  1513. flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
  1514. # category number
  1515. text = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Category number"))
  1516. self.category = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(125, -1),
  1517. initial=UserSettings.Get(group='vdigit', key="category", subkey='value'),
  1518. min=-1e9, max=1e9)
  1519. if UserSettings.Get(group='vdigit', key="categoryMode", subkey='selection') != 1:
  1520. self.category.Enable(False)
  1521. flexSizer.Add(item=text, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1522. flexSizer.Add(item=self.category, proportion=0,
  1523. flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
  1524. # category mode
  1525. text = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Category mode"))
  1526. self.categoryMode = wx.Choice(parent=panel, id=wx.ID_ANY, size=(125, -1),
  1527. choices=[_("Next to use"), _("Manual entry"), _("No category")])
  1528. self.categoryMode.SetSelection(UserSettings.Get(group='vdigit', key="categoryMode", subkey='selection'))
  1529. flexSizer.Add(item=text, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1530. flexSizer.Add(item=self.categoryMode, proportion=0,
  1531. flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
  1532. sizer.Add(item=flexSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=1)
  1533. border.Add(item=sizer, proportion=0,
  1534. flag=wx.ALL | wx.EXPAND, border=5)
  1535. #
  1536. # delete existing record
  1537. #
  1538. box = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Delete existing feature(s)"))
  1539. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1540. # checkbox
  1541. self.deleteRecord = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1542. label=_("Delete record from table"))
  1543. self.deleteRecord.SetValue(UserSettings.Get(group='vdigit', key="delRecord", subkey='enabled'))
  1544. sizer.Add(item=self.deleteRecord, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
  1545. border.Add(item=sizer, proportion=0,
  1546. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
  1547. # bindings
  1548. self.Bind(wx.EVT_CHECKBOX, self.OnChangeAddRecord, self.addRecord)
  1549. self.Bind(wx.EVT_CHOICE, self.OnChangeCategoryMode, self.categoryMode)
  1550. self.Bind(wx.EVT_CHOICE, self.OnChangeLayer, self.layer)
  1551. panel.SetSizer(border)
  1552. return panel
  1553. def __SymbologyData(self):
  1554. """
  1555. Data for __CreateSymbologyPage()
  1556. label | checkbox | color
  1557. """
  1558. return (
  1559. # ("Background", "symbolBackground"),
  1560. (_("Highlight"), "symbolHighlight"),
  1561. (_("Highlight (duplicates)"), "symbolHighlightDupl"),
  1562. (_("Point"), "symbolPoint"),
  1563. (_("Line"), "symbolLine"),
  1564. (_("Boundary (no area)"), "symbolBoundaryNo"),
  1565. (_("Boundary (one area)"), "symbolBoundaryOne"),
  1566. (_("Boundary (two areas)"), "symbolBoundaryTwo"),
  1567. (_("Centroid (in area)"), "symbolCentroidIn"),
  1568. (_("Centroid (outside area)"), "symbolCentroidOut"),
  1569. (_("Centroid (duplicate in area)"), "symbolCentroidDup"),
  1570. (_("Node (one line)"), "symbolNodeOne"),
  1571. (_("Node (two lines)"), "symbolNodeTwo"),
  1572. (_("Vertex"), "symbolVertex"),
  1573. (_("Area (closed boundary + centroid)"), "symbolArea"),
  1574. (_("Direction"), "symbolDirection"),)
  1575. def OnChangeCategoryMode(self, event):
  1576. """Change category mode"""
  1577. mode = event.GetSelection()
  1578. UserSettings.Set(group='vdigit', key="categoryMode", subkey='selection', value=mode)
  1579. if mode == 1: # manual entry
  1580. self.category.Enable(True)
  1581. elif self.category.IsEnabled(): # disable
  1582. self.category.Enable(False)
  1583. if mode == 2 and self.addRecord.IsChecked(): # no category
  1584. self.addRecord.SetValue(False)
  1585. self.parent.digit.SetCategory()
  1586. self.category.SetValue(UserSettings.Get(group='vdigit', key='category', subkey='value'))
  1587. def OnChangeLayer(self, event):
  1588. """Layer changed"""
  1589. layer = int(event.GetString())
  1590. if layer > 0:
  1591. UserSettings.Set(group='vdigit', key='layer', subkey='value', value=layer)
  1592. self.parent.digit.SetCategory()
  1593. self.category.SetValue(UserSettings.Get(group='vdigit', key='category', subkey='value'))
  1594. event.Skip()
  1595. def OnChangeAddRecord(self, event):
  1596. """Checkbox 'Add new record' status changed"""
  1597. self.category.SetValue(self.parent.digit.SetCategory())
  1598. def OnChangeSnappingValue(self, event):
  1599. """Change snapping value - update static text"""
  1600. value = self.snappingValue.GetValue()
  1601. if self.snappingUnit.GetStringSelection() == "map units":
  1602. threshold = value
  1603. else:
  1604. threshold = self.parent.digit.driver.GetThreshold(value=value)
  1605. self.snappingInfo.SetLabel(_("Snapping threshold is %(value).1f %(units)s") %
  1606. {'value' : threshold,
  1607. 'units' : self.mapUnits})
  1608. event.Skip()
  1609. def OnChangeSnappingUnits(self, event):
  1610. """Snapping units change -> update static text"""
  1611. value = self.snappingValue.GetValue()
  1612. units = self.snappingUnit.GetStringSelection()
  1613. threshold = self.parent.digit.driver.GetThreshold(value=value, units=units)
  1614. if units == "map units":
  1615. self.snappingInfo.SetLabel(_("Snapping threshold is %(value).1f %(units)s") %
  1616. {'value' : value,
  1617. 'units' : self.mapUnits})
  1618. else:
  1619. self.snappingInfo.SetLabel(_("Snapping threshold is %(value).1f %(units)s") %
  1620. {'value' : threshold,
  1621. 'units' : self.mapUnits})
  1622. event.Skip()
  1623. def OnChangeBackgroundMap(self, event):
  1624. """Change background map"""
  1625. map = self.backgroundMap.GetValue()
  1626. UserSettings.Set(group='vdigit', key='backgroundMap', subkey='value', value=map)
  1627. def OnChangeQuery(self, event):
  1628. """Change query"""
  1629. if self.queryLength.GetValue():
  1630. # length
  1631. self.queryLengthSL.Enable(True)
  1632. self.queryLengthValue.Enable(True)
  1633. self.queryDangleSL.Enable(False)
  1634. self.queryDangleValue.Enable(False)
  1635. else:
  1636. # dangle
  1637. self.queryLengthSL.Enable(False)
  1638. self.queryLengthValue.Enable(False)
  1639. self.queryDangleSL.Enable(True)
  1640. self.queryDangleValue.Enable(True)
  1641. def OnSave(self, event):
  1642. """Button 'Save' clicked"""
  1643. self.UpdateSettings()
  1644. self.parent.toolbars['vdigit'].settingsDialog = None
  1645. fileSettings = {}
  1646. UserSettings.ReadSettingsFile(settings=fileSettings)
  1647. fileSettings['vdigit'] = UserSettings.Get(group='vdigit')
  1648. file = UserSettings.SaveToFile(fileSettings)
  1649. self.parent.gismanager.goutput.WriteLog(_('Vector digitizer settings saved to file <%s>.') % file)
  1650. self.Close()
  1651. def OnApply(self, event):
  1652. """Button 'Apply' clicked"""
  1653. self.UpdateSettings()
  1654. def OnCancel(self, event):
  1655. """Button 'Cancel' clicked"""
  1656. self.parent.toolbars['vdigit'].settingsDialog = None
  1657. self.Close()
  1658. def UpdateSettings(self):
  1659. """Update UserSettings"""
  1660. # symbology
  1661. for key, (enabled, color) in self.symbology.iteritems():
  1662. if enabled:
  1663. UserSettings.Set(group='vdigit', key=key, subkey='enabled',
  1664. value=enabled.IsChecked())
  1665. UserSettings.Set(group='vdigit', key=key, subkey='color',
  1666. value=tuple(color.GetColour()))
  1667. else:
  1668. UserSettings.Set(group='vdigit', key=key, subkey='color',
  1669. value=tuple(color.GetColour()))
  1670. # display
  1671. UserSettings.Set(group='vdigit', key="lineWidth", subkey='value',
  1672. value=int(self.lineWidthValue.GetValue()))
  1673. # snapping
  1674. UserSettings.Set(group='vdigit', key="snapping", subkey='value',
  1675. value=int(self.snappingValue.GetValue()))
  1676. UserSettings.Set(group='vdigit', key="snapping", subkey='units',
  1677. value=self.snappingUnit.GetStringSelection())
  1678. UserSettings.Set(group='vdigit', key="snapToVertex", subkey='enabled',
  1679. value=self.snapVertex.IsChecked())
  1680. # digitize new feature
  1681. UserSettings.Set(group='vdigit', key="addRecord", subkey='enabled',
  1682. value=self.addRecord.IsChecked())
  1683. UserSettings.Set(group='vdigit', key="layer", subkey='value',
  1684. value=int(self.layer.GetStringSelection()))
  1685. UserSettings.Set(group='vdigit', key="category", subkey='value',
  1686. value=int(self.category.GetValue()))
  1687. UserSettings.Set(group='vdigit', key="categoryMode", subkey='selection',
  1688. value=self.categoryMode.GetSelection())
  1689. # delete existing feature
  1690. UserSettings.Set(group='vdigit', key="delRecord", subkey='enabled',
  1691. value=self.deleteRecord.IsChecked())
  1692. # snapping threshold
  1693. self.parent.digit.threshold = self.parent.digit.driver.GetThreshold()
  1694. # query tool
  1695. if self.queryLength.GetValue():
  1696. UserSettings.Set(group='vdigit', key="query", subkey='selection',
  1697. value=0)
  1698. else:
  1699. UserSettings.Set(group='vdigit', key="query", subkey='type',
  1700. value=1)
  1701. UserSettings.Set(group='vdigit', key="query", subkey='box',
  1702. value=self.queryBox.IsChecked())
  1703. UserSettings.Set(group='vdigit', key="queryLength", subkey='than-selection',
  1704. value=self.queryLengthSL.GetSelection())
  1705. UserSettings.Set(group='vdigit', key="queryLength", subkey='thresh',
  1706. value=int(self.queryLengthValue.GetValue()))
  1707. UserSettings.Set(group='vdigit', key="queryDangle", subkey='than-selection',
  1708. value=self.queryDangleSL.GetSelection())
  1709. UserSettings.Set(group='vdigit', key="queryDangle", subkey='thresh',
  1710. value=int(self.queryDangleValue.GetValue()))
  1711. # select features
  1712. for feature in ('Point', 'Line',
  1713. 'Centroid', 'Boundary'):
  1714. UserSettings.Set(group='vdigit', key='selectFeature'+feature, subkey='enabled',
  1715. value=self.FindWindowById(self.selectFeature[feature]).IsChecked())
  1716. UserSettings.Set(group='vdigit', key="selectThresh", subkey='value',
  1717. value=int(self.selectThreshValue.GetValue()))
  1718. UserSettings.Set(group='vdigit', key="checkForDupl", subkey='enabled',
  1719. value=self.checkForDupl.IsChecked())
  1720. # on-exit
  1721. UserSettings.Set(group='vdigit', key="saveOnExit", subkey='enabled',
  1722. value=self.save.IsChecked())
  1723. # update driver settings
  1724. self.parent.digit.driver.UpdateSettings()
  1725. # redraw map if auto-rendering is enabled
  1726. if self.parent.autoRender.GetValue():
  1727. self.parent.OnRender(None)
  1728. class VDigitCategoryDialog(wx.Dialog, listmix.ColumnSorterMixin):
  1729. """
  1730. Dialog used to display/modify categories of vector objects
  1731. @param parent
  1732. @param title dialog title
  1733. @param query {coordinates, qdist} - v.edit/v.what
  1734. @param cats directory of categories - vdigit
  1735. @param line line id - vdigit
  1736. @param pos
  1737. @param style
  1738. """
  1739. def __init__(self, parent, title,
  1740. map, query=None, cats=None, line=None,
  1741. pos=wx.DefaultPosition,
  1742. style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  1743. # parent
  1744. self.parent = parent # mapdisplay.BufferedWindow class instance
  1745. # map name
  1746. self.map = map
  1747. # line id (if not found remains 'None')
  1748. self.line = None
  1749. # {layer: [categories]}
  1750. self.cats = {}
  1751. # do not display dialog if no line is found (-> self.cats)
  1752. if cats is None:
  1753. if self.__GetCategories(query[0], query[1]) == 0 or not self.line:
  1754. Debug.msg(3, "VDigitCategoryDialog(): nothing found!")
  1755. return
  1756. else:
  1757. # self.cats = dict(cats)
  1758. for layer in cats.keys():
  1759. self.cats[layer] = list(cats[layer]) # TODO: tuple to list
  1760. self.line = line
  1761. # make copy of cats (used for 'reload')
  1762. self.cats_orig = copy.deepcopy(self.cats)
  1763. Debug.msg(3, "VDigitCategoryDialog(): line=%d, cats=%s" % \
  1764. (self.line, self.cats))
  1765. wx.Dialog.__init__(self, parent=self.parent, id=wx.ID_ANY, title=title,
  1766. style=style, pos=pos)
  1767. # list of categories
  1768. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  1769. label=" %s " % _("List of categories"))
  1770. listSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1771. self.list = CategoryListCtrl(parent=self, id=wx.ID_ANY,
  1772. style=wx.LC_REPORT |
  1773. wx.BORDER_NONE |
  1774. wx.LC_SORT_ASCENDING |
  1775. wx.LC_HRULES |
  1776. wx.LC_VRULES)
  1777. # sorter
  1778. self.itemDataMap = self.list.Populate()
  1779. listmix.ColumnSorterMixin.__init__(self, 2)
  1780. listSizer.Add(item=self.list, proportion=1, flag=wx.EXPAND)
  1781. # add new category
  1782. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  1783. label=" %s " % _("Add new category"))
  1784. addSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1785. flexSizer = wx.FlexGridSizer (cols=5, hgap=5, vgap=5)
  1786. flexSizer.AddGrowableCol(3)
  1787. layerNewTxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1788. label="%s:" % _("Layer"))
  1789. self.layerNew = wx.SpinCtrl(parent=self, id=wx.ID_ANY, size=(50, -1),
  1790. initial=1, min=1, max=1e9)
  1791. catNewTxt = wx.StaticText(parent=self, id=wx.ID_ANY,
  1792. label="%s:" % _("Category"))
  1793. try:
  1794. newCat = max(self.cats[1]) + 1
  1795. except:
  1796. newCat = 1
  1797. self.catNew = wx.SpinCtrl(parent=self, id=wx.ID_ANY, size=(75, -1),
  1798. initial=newCat, min=-1e9, max=1e9)
  1799. btnAddCat = wx.Button(self, wx.ID_ADD)
  1800. flexSizer.Add(item=layerNewTxt, proportion=0,
  1801. flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
  1802. flexSizer.Add(item=self.layerNew, proportion=0,
  1803. flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
  1804. flexSizer.Add(item=catNewTxt, proportion=0,
  1805. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
  1806. border=10)
  1807. flexSizer.Add(item=self.catNew, proportion=0,
  1808. flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
  1809. flexSizer.Add(item=btnAddCat, proportion=0,
  1810. flag=wx.EXPAND | wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1811. addSizer.Add(item=flexSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
  1812. # buttons
  1813. btnApply = wx.Button(self, wx.ID_APPLY)
  1814. btnCancel = wx.Button(self, wx.ID_CANCEL)
  1815. #btnReload = wx.Button(self, wx.ID_UNDO, _("&Reload"))
  1816. btnOk = wx.Button(self, wx.ID_OK)
  1817. btnOk.SetDefault()
  1818. # sizers
  1819. btnSizer = wx.StdDialogButtonSizer()
  1820. btnSizer.AddButton(btnCancel)
  1821. #btnSizer.AddButton(btnReload)
  1822. #btnSizer.SetNegativeButton(btnReload)
  1823. btnSizer.AddButton(btnApply)
  1824. btnSizer.AddButton(btnOk)
  1825. btnSizer.Realize()
  1826. mainSizer = wx.BoxSizer(wx.VERTICAL)
  1827. mainSizer.Add(item=listSizer, proportion=1,
  1828. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  1829. mainSizer.Add(item=addSizer, proportion=0,
  1830. flag=wx.EXPAND | wx.ALIGN_CENTER |
  1831. wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
  1832. mainSizer.Add(item=btnSizer, proportion=0,
  1833. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  1834. self.SetSizer(mainSizer)
  1835. mainSizer.Fit(self)
  1836. self.SetAutoLayout(True)
  1837. # set min size for dialog
  1838. self.SetMinSize(self.GetBestSize())
  1839. # bindings
  1840. # buttons
  1841. #btnReload.Bind(wx.EVT_BUTTON, self.OnReload)
  1842. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  1843. btnOk.Bind(wx.EVT_BUTTON, self.OnOK)
  1844. btnAddCat.Bind(wx.EVT_BUTTON, self.OnAddCat)
  1845. btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  1846. # list
  1847. # self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
  1848. # self.list.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
  1849. self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightUp) #wxMSW
  1850. self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightUp) #wxGTK
  1851. self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnBeginEdit, self.list)
  1852. self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEndEdit, self.list)
  1853. self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick, self.list)
  1854. def GetListCtrl(self):
  1855. """Used by ColumnSorterMixin"""
  1856. return self.list
  1857. def OnColClick(self, event):
  1858. """Click on column header (order by)"""
  1859. event.Skip()
  1860. def OnBeginEdit(self, event):
  1861. """Editing of item started"""
  1862. event.Allow()
  1863. def OnEndEdit(self, event):
  1864. """Finish editing of item"""
  1865. itemIndex = event.GetIndex()
  1866. layerOld = int (self.list.GetItem(itemIndex, 0).GetText())
  1867. catOld = int (self.list.GetItem(itemIndex, 1).GetText())
  1868. if event.GetColumn() == 0:
  1869. layerNew = int(event.GetLabel())
  1870. catNew = catOld
  1871. else:
  1872. layerNew = layerOld
  1873. catNew = int(event.GetLabel())
  1874. try:
  1875. if layerNew not in self.cats.keys():
  1876. self.cats[layerNew] = []
  1877. self.cats[layerNew].append(catNew)
  1878. self.cats[layerOld].remove(catOld)
  1879. except:
  1880. event.Veto()
  1881. self.list.SetStringItem(itemIndex, 0, str(layerNew))
  1882. self.list.SetStringItem(itemIndex, 1, str(catNew))
  1883. dlg = wx.MessageDialog(self, _("Unable to add new layer/category <%(layer)s/%(category)s>.\n"
  1884. "Layer and category number must be integer.\n"
  1885. "Layer number must be greater then zero.") %
  1886. { 'layer': str(self.layerNew.GetValue()),
  1887. 'category' : str(self.catNew.GetValue()) },
  1888. _("Error"), wx.OK | wx.ICON_ERROR)
  1889. dlg.ShowModal()
  1890. dlg.Destroy()
  1891. return False
  1892. def OnRightDown(self, event):
  1893. """Mouse right button down"""
  1894. x = event.GetX()
  1895. y = event.GetY()
  1896. item, flags = self.list.HitTest((x, y))
  1897. if item != wx.NOT_FOUND and \
  1898. flags & wx.LIST_HITTEST_ONITEM:
  1899. self.list.Select(item)
  1900. event.Skip()
  1901. def OnRightUp(self, event):
  1902. """Mouse right button up"""
  1903. if not hasattr(self, "popupID1"):
  1904. self.popupID1 = wx.NewId()
  1905. self.popupID2 = wx.NewId()
  1906. self.popupID3 = wx.NewId()
  1907. self.Bind(wx.EVT_MENU, self.OnItemDelete, id=self.popupID1)
  1908. self.Bind(wx.EVT_MENU, self.OnItemDeleteAll, id=self.popupID2)
  1909. self.Bind(wx.EVT_MENU, self.OnReload, id=self.popupID3)
  1910. # generate popup-menu
  1911. menu = wx.Menu()
  1912. menu.Append(self.popupID1, _("Delete selected"))
  1913. if self.list.GetFirstSelected() == -1:
  1914. menu.Enable(self.popupID1, False)
  1915. menu.Append(self.popupID2, _("Delete all"))
  1916. menu.AppendSeparator()
  1917. menu.Append(self.popupID3, _("Reload"))
  1918. self.PopupMenu(menu)
  1919. menu.Destroy()
  1920. def OnItemSelected(self, event):
  1921. """Item selected"""
  1922. event.Skip()
  1923. def OnItemDelete(self, event):
  1924. """Delete selected item(s) from the list (layer/category pair)"""
  1925. item = self.list.GetFirstSelected()
  1926. while item != -1:
  1927. layer = int (self.list.GetItem(item, 0).GetText())
  1928. cat = int (self.list.GetItem(item, 1).GetText())
  1929. self.list.DeleteItem(item)
  1930. self.cats[layer].remove(cat)
  1931. item = self.list.GetFirstSelected()
  1932. event.Skip()
  1933. def OnItemDeleteAll(self, event):
  1934. """Delete all items from the list"""
  1935. self.list.DeleteAllItems()
  1936. self.cats = {}
  1937. event.Skip()
  1938. def __GetCategories(self, coords, qdist):
  1939. """Get layer/category pairs for all available
  1940. layers
  1941. Return True line found or False if not found"""
  1942. cmdWhat = gcmd.Command(cmd=['v.what',
  1943. '--q',
  1944. 'map=%s' % self.map,
  1945. 'east_north=%f,%f' % \
  1946. (float(coords[0]), float(coords[1])),
  1947. 'distance=%f' % qdist])
  1948. if cmdWhat.returncode != 0:
  1949. return False
  1950. for item in cmdWhat.ReadStdOutput():
  1951. litem = item.lower()
  1952. if "line:" in litem: # get line id
  1953. self.line = int(item.split(':')[1].strip())
  1954. elif "layer:" in litem: # add layer
  1955. layer = int(item.split(':')[1].strip())
  1956. if layer not in self.cats.keys():
  1957. self.cats[layer] = []
  1958. elif "category:" in litem: # add category
  1959. self.cats[layer].append(int(item.split(':')[1].strip()))
  1960. return True
  1961. def OnReload(self, event):
  1962. """Reload button pressed"""
  1963. # restore original list
  1964. self.cats = copy.deepcopy(self.cats_orig)
  1965. # polulate list
  1966. self.itemDataMap = self.list.Populate(update=True)
  1967. event.Skip()
  1968. def OnCancel(self, event):
  1969. """Cancel button pressed"""
  1970. self.parent.parent.dialogs['category'] = None
  1971. if self.parent.parent.digit:
  1972. self.parent.parent.digit.driver.SetSelected([])
  1973. self.parent.UpdateMap(render=False)
  1974. else:
  1975. self.parent.parent.OnRender(None)
  1976. self.Close()
  1977. def OnApply(self, event):
  1978. """Apply button pressed"""
  1979. # action : (catsFrom, catsTo)
  1980. check = {'catadd': (self.cats, self.cats_orig),
  1981. 'catdel': (self.cats_orig, self.cats)}
  1982. # add/delete new category
  1983. for action, cats in check.iteritems():
  1984. for layer in cats[0].keys():
  1985. catList = []
  1986. for cat in cats[0][layer]:
  1987. if layer not in cats[1].keys() or \
  1988. cat not in cats[1][layer]:
  1989. catList.append(cat)
  1990. if catList != []:
  1991. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':
  1992. vEditCmd = ['v.edit', '--q',
  1993. 'map=%s' % self.map,
  1994. 'layer=%d' % layer,
  1995. 'tool=%s' % action,
  1996. 'cats=%s' % ",".join(["%d" % v for v in catList]),
  1997. 'id=%d' % self.line]
  1998. gcmd.Command(vEditCmd)
  1999. else:
  2000. if action == 'catadd':
  2001. add = True
  2002. else:
  2003. add = False
  2004. self.line = self.parent.parent.digit.SetLineCats(-1, layer,
  2005. catList, add)
  2006. if self.line < 0:
  2007. wx.MessageBox(parent=self, message=_("Unable to update vector map."),
  2008. caption=_("Error"), style=wx.OK | wx.ICON_ERROR)
  2009. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':
  2010. # reload map (needed for v.edit)
  2011. self.parent.parent.digit.driver.ReloadMap()
  2012. self.cats_orig = copy.deepcopy(self.cats)
  2013. event.Skip()
  2014. def OnOK(self, event):
  2015. """OK button pressed"""
  2016. self.OnApply(event)
  2017. self.OnCancel(event)
  2018. def OnAddCat(self, event):
  2019. """Button 'Add' new category pressed"""
  2020. try:
  2021. layer = int(self.layerNew.GetValue())
  2022. cat = int(self.catNew.GetValue())
  2023. if layer <= 0:
  2024. raise ValueError
  2025. except ValueError:
  2026. dlg = wx.MessageDialog(self, _("Unable to add new layer/category <%(layer)s/%(category)s>.\n"
  2027. "Layer and category number must be integer.\n"
  2028. "Layer number must be greater then zero.") %
  2029. {'layer' : str(self.layerNew.GetValue()),
  2030. 'category' : str(self.catNew.GetValue())},
  2031. _("Error"), wx.OK | wx.ICON_ERROR)
  2032. dlg.ShowModal()
  2033. dlg.Destroy()
  2034. return False
  2035. if layer not in self.cats.keys():
  2036. self.cats[layer] = []
  2037. self.cats[layer].append(cat)
  2038. # reload list
  2039. self.itemDataMap = self.list.Populate(update=True)
  2040. # update category number for add
  2041. self.catNew.SetValue(cat + 1)
  2042. event.Skip()
  2043. return True
  2044. def GetLine(self):
  2045. """Get id of selected line of 'None' if no line is selected"""
  2046. return self.line
  2047. def UpdateDialog(self, query=None, cats=None, line=None):
  2048. """Update dialog
  2049. @param query {coordinates, distance} - v.edit/v.what
  2050. @param cats directory layer/cats - vdigit
  2051. Return True if updated otherwise False
  2052. """
  2053. # line id (if not found remains 'None')
  2054. self.line = None
  2055. # {layer: [categories]}
  2056. self.cats = {}
  2057. # do not display dialog if no line is found (-> self.cats)
  2058. if cats is None:
  2059. ret = self.__GetCategories(query[0], query[1])
  2060. else:
  2061. # self.cats = dict(cats)
  2062. for layer in cats.keys():
  2063. self.cats[layer] = list(cats[layer]) # TODO: tuple to list
  2064. self.line = line
  2065. ret = 1
  2066. if ret == 0 or not self.line:
  2067. Debug.msg(3, "VDigitCategoryDialog(): nothing found!")
  2068. return False
  2069. # make copy of cats (used for 'reload')
  2070. self.cats_orig = copy.deepcopy(self.cats)
  2071. # polulate list
  2072. self.itemDataMap = self.list.Populate(update=True)
  2073. try:
  2074. newCat = max(self.cats[1]) + 1
  2075. except:
  2076. newCat = 1
  2077. self.catNew.SetValue(newCat)
  2078. return True
  2079. class CategoryListCtrl(wx.ListCtrl,
  2080. listmix.ListCtrlAutoWidthMixin,
  2081. listmix.TextEditMixin):
  2082. """List of layers/categories"""
  2083. def __init__(self, parent, id, pos=wx.DefaultPosition,
  2084. size=wx.DefaultSize, style=0):
  2085. self.parent = parent
  2086. wx.ListCtrl.__init__(self, parent, id, pos, size, style)
  2087. listmix.ListCtrlAutoWidthMixin.__init__(self)
  2088. listmix.TextEditMixin.__init__(self)
  2089. def Populate(self, update=False):
  2090. """Populate the list"""
  2091. itemData = {} # requested by sorter
  2092. if not update:
  2093. self.InsertColumn(0, _("Layer"))
  2094. self.InsertColumn(1, _("Category"))
  2095. else:
  2096. self.DeleteAllItems()
  2097. i = 1
  2098. for layer in self.parent.cats.keys():
  2099. catsList = self.parent.cats[layer]
  2100. for cat in catsList:
  2101. index = self.InsertStringItem(sys.maxint, str(catsList[0]))
  2102. self.SetStringItem(index, 0, str(layer))
  2103. self.SetStringItem(index, 1, str(cat))
  2104. self.SetItemData(index, i)
  2105. itemData[i] = (str(layer), str(cat))
  2106. i = i + 1
  2107. if not update:
  2108. self.SetColumnWidth(0, 100)
  2109. self.SetColumnWidth(1, wx.LIST_AUTOSIZE)
  2110. self.currentItem = 0
  2111. return itemData
  2112. class VDigitZBulkDialog(wx.Dialog):
  2113. """
  2114. Dialog used for Z bulk-labeling tool
  2115. """
  2116. def __init__(self, parent, title, nselected, style=wx.DEFAULT_DIALOG_STYLE):
  2117. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title, style=style)
  2118. self.parent = parent # mapdisplay.BufferedWindow class instance
  2119. # panel = wx.Panel(parent=self, id=wx.ID_ANY)
  2120. border = wx.BoxSizer(wx.VERTICAL)
  2121. txt = wx.StaticText(parent=self,
  2122. label=_("%d lines selected for z bulk-labeling") % nselected);
  2123. border.Add(item=txt, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2124. box = wx.StaticBox (parent=self, id=wx.ID_ANY, label=" %s " % _("Set value"))
  2125. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2126. flexSizer = wx.FlexGridSizer (cols=2, hgap=5, vgap=5)
  2127. flexSizer.AddGrowableCol(0)
  2128. # starting value
  2129. txt = wx.StaticText(parent=self,
  2130. label=_("Starting value"));
  2131. self.value = wx.SpinCtrl(parent=self, id=wx.ID_ANY, size=(150, -1),
  2132. initial=0,
  2133. min=-1e6, max=1e6)
  2134. flexSizer.Add(txt, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  2135. flexSizer.Add(self.value, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
  2136. # step
  2137. txt = wx.StaticText(parent=self,
  2138. label=_("Step"))
  2139. self.step = wx.SpinCtrl(parent=self, id=wx.ID_ANY, size=(150, -1),
  2140. initial=0,
  2141. min=0, max=1e6)
  2142. flexSizer.Add(txt, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  2143. flexSizer.Add(self.step, proportion=0, flag=wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
  2144. sizer.Add(item=flexSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=1)
  2145. border.Add(item=sizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
  2146. # buttons
  2147. btnCancel = wx.Button(self, wx.ID_CANCEL)
  2148. btnOk = wx.Button(self, wx.ID_OK)
  2149. btnOk.SetDefault()
  2150. # sizers
  2151. btnSizer = wx.StdDialogButtonSizer()
  2152. btnSizer.AddButton(btnCancel)
  2153. btnSizer.AddButton(btnOk)
  2154. btnSizer.Realize()
  2155. mainSizer = wx.BoxSizer(wx.VERTICAL)
  2156. mainSizer.Add(item=border, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  2157. mainSizer.Add(item=btnSizer, proportion=0,
  2158. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  2159. self.SetSizer(mainSizer)
  2160. mainSizer.Fit(self)
  2161. class VDigitDuplicatesDialog(wx.Dialog):
  2162. """
  2163. Show duplicated feature ids
  2164. """
  2165. def __init__(self, parent, data, title=_("List of duplicates"),
  2166. style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
  2167. pos=wx.DefaultPosition):
  2168. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title, style=style,
  2169. pos=pos)
  2170. self.parent = parent # BufferedWindow
  2171. self.data = data
  2172. self.winList = []
  2173. # panel = wx.Panel(parent=self, id=wx.ID_ANY)
  2174. # notebook
  2175. self.notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  2176. id = 1
  2177. for key in self.data.keys():
  2178. panel = wx.Panel(parent=self.notebook, id=wx.ID_ANY)
  2179. self.notebook.AddPage(page=panel, text=" %d " % (id))
  2180. # notebook body
  2181. border = wx.BoxSizer(wx.VERTICAL)
  2182. win = CheckListFeature(parent=panel, data=list(self.data[key]))
  2183. self.winList.append(win.GetId())
  2184. border.Add(item=win, proportion=1,
  2185. flag=wx.ALL | wx.EXPAND, border=5)
  2186. panel.SetSizer(border)
  2187. id += 1
  2188. # buttons
  2189. btnCancel = wx.Button(self, wx.ID_CANCEL)
  2190. btnOk = wx.Button(self, wx.ID_OK)
  2191. btnOk.SetDefault()
  2192. # sizers
  2193. btnSizer = wx.StdDialogButtonSizer()
  2194. btnSizer.AddButton(btnCancel)
  2195. btnSizer.AddButton(btnOk)
  2196. btnSizer.Realize()
  2197. mainSizer = wx.BoxSizer(wx.VERTICAL)
  2198. mainSizer.Add(item=self.notebook, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  2199. mainSizer.Add(item=btnSizer, proportion=0,
  2200. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  2201. self.SetSizer(mainSizer)
  2202. mainSizer.Fit(self)
  2203. self.SetAutoLayout(True)
  2204. # set min size for dialog
  2205. self.SetMinSize((250, 180))
  2206. def GetUnSelected(self):
  2207. """Get unselected items (feature id)
  2208. @return list of ids
  2209. """
  2210. ids = []
  2211. for id in self.winList:
  2212. wlist = self.FindWindowById(id)
  2213. for item in range(wlist.GetItemCount()):
  2214. if not wlist.IsChecked(item):
  2215. ids.append(int(wlist.GetItem(item, 0).GetText()))
  2216. return ids
  2217. class CheckListFeature(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin):
  2218. """List of mapset/owner/group"""
  2219. def __init__(self, parent, data,
  2220. pos=wx.DefaultPosition, log=None):
  2221. self.parent = parent
  2222. self.data = data
  2223. wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
  2224. style=wx.LC_REPORT)
  2225. listmix.CheckListCtrlMixin.__init__(self)
  2226. self.log = log
  2227. # setup mixins
  2228. listmix.ListCtrlAutoWidthMixin.__init__(self)
  2229. self.LoadData(self.data)
  2230. def LoadData(self, data):
  2231. """Load data into list"""
  2232. self.InsertColumn(0, _('Feature id'))
  2233. self.InsertColumn(1, _('Layer (Categories)'))
  2234. for item in data:
  2235. index = self.InsertStringItem(sys.maxint, str(item[0]))
  2236. self.SetStringItem(index, 1, str(item[1]))
  2237. # enable all items by default
  2238. for item in range(self.GetItemCount()):
  2239. self.CheckItem(item, True)
  2240. self.SetColumnWidth(col=0, width=wx.LIST_AUTOSIZE_USEHEADER)
  2241. self.SetColumnWidth(col=1, width=wx.LIST_AUTOSIZE_USEHEADER)
  2242. def OnCheckItem(self, index, flag):
  2243. """Mapset checked/unchecked"""
  2244. pass