vdigit.py 109 KB

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