/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/projdialog.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Thuban/UI/projdialog.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 747 - (hide annotations)
Fri Apr 25 11:02:08 2003 UTC (21 years, 10 months ago) by jonathan
Original Path: trunk/thuban/Thuban/UI/projdialog.py
File MIME type: text/x-python
File size: 30791 byte(s)
(ProjFrame.__FillAvailList): Now
        takes an optional argument to select the current projection.
        This does not guarantee that the item is visible due to
        limited wxWindows functionality. Fixes RTBug #1821.

1 jonathan 717 #!/usr/bin/env python
2     # generated by wxGlade 0.2.1 on Thu Apr 17 11:51:39 2003
3    
4 jonathan 730 import os, sys
5 jonathan 717 from wxPython.wx import *
6    
7     from Thuban import _
8    
9 jonathan 730 from Thuban.Model.proj import Projection, ProjFile
10 jonathan 717
11 jonathan 730 from Thuban.Model.resource import GetUserProjFiles, GetSystemProjFiles, \
12     ReadProjFile, WriteProjFile
13 jonathan 717 from Thuban.UI.dialogs import NonModalDialog
14    
15 jonathan 730
16 jonathan 717 ID_PROJ_ADVANCED = 4001
17     ID_PROJ_PROJCHOICE = 4002
18 jonathan 741 ID_PROJ_ADDTOLIST = 4003
19 jonathan 717 ID_PROJ_NEW = 4004
20     ID_PROJ_TRY = 4005
21     ID_PROJ_REVERT = 4006
22     ID_PROJ_OK = 4007
23     ID_PROJ_CLOSE = 4008
24     ID_PROJ_AVAIL = 4009
25 jonathan 730 ID_PROJ_SAVE = 4010
26     ID_PROJ_IMPORT = 4011
27     ID_PROJ_EXPORT = 4012
28     ID_PROJ_REMOVE = 4013
29     ID_PROJ_PROJNAME = 4014
30 jonathan 717
31 jonathan 730 CLIENT_PROJ = 0
32     CLIENT_PROJFILE = 1
33 jonathan 717
34     class ProjFrame(NonModalDialog):
35    
36     def __init__(self, parent, name, receiver, *args, **kwds):
37 jonathan 730 """Initialize the projection dialog.
38 jonathan 717
39 jonathan 730 receiver -- An object that implements the following methods:
40     SetProjection(projection)
41     GetProjection()
42     """
43    
44 jonathan 717 self.receiver = receiver
45     self.originalProjection = -1
46     self.curProjPanel = None
47    
48     self.projPanels = []
49     self.projPanels.append(
50 jonathan 730 ("tmerc", _("Transverse Mercator"), TMPanel))
51 jonathan 717 self.projPanels.append(
52 jonathan 730 ("utm", _("Universal Transverse Mercator"), UTMPanel))
53 jonathan 717 self.projPanels.append(
54     ("lcc", _("Lambert Conic Conformal"), LCCPanel))
55     self.projPanels.append(
56     ("latlong", _("Geographic"), GeoPanel))
57    
58     NonModalDialog.__init__(self, parent, name, "")
59 jonathan 730 # originally generate by wxGlade
60 jonathan 717 self.panel_1 = wxPanel(self, -1)
61 jonathan 730 self.panel_edit = wxPanel(self, -1)
62     self.panel_buttons = wxPanel(self, -1)
63 jonathan 717 self.label_5 = wxStaticText(self.panel_1, -1, _("Available Projections:"))
64 jonathan 747 self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL, style=wxLB_EXTENDED|wxLB_SORT)
65 jonathan 730 self.projfilepath = wxStaticText(self.panel_1, -1, "")
66     self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:"))
67     self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "")
68     self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:"))
69     self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE)
70     self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT, _("Import..."))
71     self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT, _("Export..."))
72     self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE, _("Remove"))
73     self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New"))
74     self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Save"))
75 jonathan 741 self.button_add = wxButton(self.panel_edit, ID_PROJ_ADDTOLIST,
76 jonathan 730 _("Add to List"))
77     self.button_try = wxButton(self.panel_buttons, ID_PROJ_TRY, _("Try"))
78     self.button_revert = wxButton(self.panel_buttons, ID_PROJ_REVERT, _("Revert"))
79     self.button_ok = wxButton(self.panel_buttons, ID_PROJ_OK, _("OK"))
80     self.button_close = wxButton(self.panel_buttons, ID_PROJ_CLOSE, _("Close"))
81 jonathan 717
82     self.__set_properties()
83     self.__do_layout()
84 jonathan 730 # wxGlade
85 jonathan 717
86 jonathan 730 self.__DoOnProjAvail()
87    
88 jonathan 717 EVT_BUTTON(self, ID_PROJ_TRY, self._OnTry)
89     EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert)
90     EVT_BUTTON(self, ID_PROJ_OK, self._OnOK)
91     EVT_BUTTON(self, ID_PROJ_CLOSE, self._OnClose)
92     EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice)
93     EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail)
94 jonathan 730 EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport)
95     EVT_BUTTON(self, ID_PROJ_EXPORT, self._OnExport)
96     EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove)
97 jonathan 717
98     EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew)
99 jonathan 730 EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave)
100 jonathan 741 EVT_BUTTON(self, ID_PROJ_ADDTOLIST, self._OnAddToList)
101 jonathan 717
102 jonathan 730 EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName)
103    
104 jonathan 717 def GetReceiver(self):
105     return self.receiver
106    
107     def _OnTry(self, event):
108     self.__SetProjection()
109    
110     def _OnRevert(self, event):
111     if self.originalProjection != -1:
112     self.receiver.SetProjection(self.originalProjection)
113    
114     def _OnOK(self, event):
115     self.__SetProjection()
116     self.Close()
117    
118     def _OnClose(self, event):
119     self.Close()
120    
121 jonathan 730 def _OnNew(self, event):
122     self.__DoOnNew()
123 jonathan 717
124 jonathan 730 def _OnSave(self, event):
125 jonathan 717
126 jonathan 730 sel = self.availprojs.GetSelections()
127     assert len(sel) == 1, "button shouldn't be enabled"
128 jonathan 717
129 jonathan 730 proj, projfile = self.availprojs.GetClientData(sel[0])
130 jonathan 717
131 jonathan 730 assert proj is not None and projfile is not None
132 jonathan 717
133 jonathan 730 newproj = self.__GetProjection()
134 jonathan 717
135 jonathan 730 if newproj is not None:
136     projfile.Remove(proj)
137     projfile.Add(newproj)
138     try:
139     WriteProjFile(projfile)
140     except IOError, (errno, errstr):
141     wxMessageDialog(self,
142     _("The following error occured:\n") +
143 jonathan 741 projfile.GetFilename() + "\n" + errstr,
144 jonathan 730 _("Error"), wxOK | wxICON_ERROR).ShowModal()
145     self.__FillAvailList()
146    
147 jonathan 741 def _OnAddToList(self, event):
148 jonathan 730
149     proj = self.__GetProjection()
150     if proj is not None:
151     self.__usrProjFile.Add(proj)
152     try:
153     WriteProjFile(self.__usrProjFile)
154     except IOError, (errno, errstr):
155     wxMessageDialog(self,
156     _("The following error occured:\n") +
157 jonathan 741 self.__usrProjFile.GetFilename() + "\n" + errstr,
158 jonathan 730 _("Error"), wxOK | wxICON_ERROR).ShowModal()
159     self.__FillAvailList()
160    
161 jonathan 717 def _OnProjAvail(self, event):
162     self.__DoOnProjAvail()
163    
164 jonathan 730 def _OnImport(self, event):
165    
166     dlg = wxFileDialog(self, _("Import"), style = wxOPEN)
167    
168     if dlg.ShowModal() == wxID_OK:
169     path = dlg.GetPath()
170    
171     try:
172     projFile = ReadProjFile(path)
173     for proj in projFile.GetProjections():
174     self.__usrProjFile.Add(proj)
175     WriteProjFile(self.__usrProjFile)
176     except IOError, (errno, errstr):
177     wxMessageDialog(self,
178     _("The following error occured:\n") +
179     dlg.GetPath() + "\n" + errstr,
180     _("Error"), wxOK | wxICON_ERROR).ShowModal()
181    
182     self.__FillAvailList()
183    
184     dlg.Destroy()
185    
186     def _OnExport(self, event):
187    
188 jonathan 741 sel = self.availprojs.GetSelections()
189     assert len(sel) != 0, "button should be disabled"
190 jonathan 730
191     dlg = wxFileDialog(self, _("Export"),
192 jonathan 741 style = wxSAVE|wxOVERWRITE_PROMPT)
193 jonathan 730
194     if dlg.ShowModal() == wxID_OK:
195     path = dlg.GetPath()
196    
197     projFile = ProjFile(path)
198 jonathan 741
199     for i in sel:
200     proj = self.availprojs.GetClientData(i)[CLIENT_PROJ]
201     if proj is not None:
202     projFile.Add(proj)
203    
204 jonathan 730 try:
205     WriteProjFile(projFile)
206     except IOError, (errno, errstr):
207     wxMessageDialog(self,
208     _("The following error occured:\n") +
209     dlg.GetPath() + "\n" + errstr,
210     _("Error"), wxOK | wxICON_ERROR).ShowModal()
211    
212     dlg.Destroy()
213    
214     def _OnRemove(self, event):
215    
216     sel = self.availprojs.GetSelections()
217     assert len(sel) != 0, "button should be disabled!"
218    
219     #
220     # remove the items backwards so the indices don't change
221     #
222     sel = list(sel)
223     sel.sort()
224     sel.reverse()
225    
226     newselection = -1
227     if len(sel) == 1:
228     newselection = sel[0] - 1
229     if newselection < 0:
230     newselection = 0
231    
232     for i in sel:
233     proj, projfile = self.availprojs.GetClientData(i)
234    
235     #
236     # this could be the case if they selected <None> or
237     # the currently used projection
238     #
239     if proj is not None and projfile is not None:
240     projfile.Remove(proj)
241    
242     try:
243     WriteProjFile(projfile)
244     except IOError, (errno, errstr):
245     wxMessageDialog(self,
246     _("The following error occured:\n") +
247 jonathan 741 projfile.GetFilename() + "\n" + errstr,
248 jonathan 730 _("Error"), wxOK | wxICON_ERROR).ShowModal()
249    
250    
251     self.__FillAvailList()
252    
253     #
254     # this *could* produce incorrect results if the .proj files
255     # change between the last list update and this selection
256     # because the list has been repopulated.
257     #
258     if newselection != -1 and self.availprojs.GetCount() > 0:
259     self.availprojs.SetSelection(newselection)
260    
261     def _OnProjName(self, event):
262     self.__VerifyButtons()
263    
264     def __VerifyButtons(self):
265     sel = self.availprojs.GetSelections()
266    
267     self.button_import.Enable(True)
268     self.button_export.Enable(True)
269     self.button_save.Enable(True)
270     self.button_remove.Enable(True)
271    
272     self.panel_edit.Enable(True)
273    
274     if len(sel) == 0:
275     self.button_import.Enable(True)
276     self.button_export.Enable(False)
277     self.button_remove.Enable(False)
278    
279     elif len(sel) == 1:
280    
281     proj, projFile = self.availprojs.GetClientData(sel[0])
282    
283     self.button_save.Enable(len(self.projname.GetValue()) > 0)
284     self.button_add.Enable(len(self.projname.GetValue()) > 0)
285    
286     if proj is None:
287     self.button_export.Enable(False)
288     self.button_remove.Enable(False)
289    
290     if projFile is None:
291     self.button_save.Enable(False)
292    
293     else:
294     self.panel_edit.Enable(False)
295    
296     def __DoOnNew(self):
297     sel = self.availprojs.GetSelections()
298     if len(sel) != 0:
299     self.availprojs.SetSelection(sel, False)
300     self.projname.Clear()
301     self.curProjPanel.Clear()
302    
303 jonathan 717 def __DoOnProjAvail(self):
304    
305 jonathan 730 sel = self.availprojs.GetSelections()
306     if len(sel) == 1:
307 jonathan 717
308 jonathan 730 proj = self.availprojs.GetClientData(sel[0])[CLIENT_PROJ]
309     projfile = self.availprojs.GetClientData(sel[0])[CLIENT_PROJFILE]
310 jonathan 717
311 jonathan 730 if proj is None:
312     # user selected <None>
313     self.projname.Clear()
314     else:
315    
316     if projfile is not None:
317 jonathan 741 self.projfilepath.SetLabel(projfile.GetFilename())
318 jonathan 730 else:
319     # only None if the currently used projection is selected
320     self.projfilepath.SetLabel("")
321 jonathan 717
322 jonathan 730 self.projname.SetValue(proj.GetName())
323 jonathan 717
324 jonathan 730 myProjType = proj.GetParameter("proj")
325     i = 0
326     for projType, name, clazz in self.projPanels:
327     if myProjType == projType:
328     self.projchoice.SetSelection(i)
329     self.__DoOnProjChoice()
330     self.curProjPanel.SetProjection(proj)
331     i += 1
332 jonathan 717
333 jonathan 730 self.__VerifyButtons()
334    
335 jonathan 717 def _OnProjChoice(self, event):
336     self.__DoOnProjChoice()
337    
338     def __DoOnProjChoice(self):
339     choice = self.projchoice
340    
341     sel = choice.GetSelection()
342 jonathan 730 if sel != -1:
343 jonathan 717
344 jonathan 730 clazz, obj = choice.GetClientData(sel)
345 jonathan 717
346 jonathan 730 if obj is None:
347     obj = clazz(self.panel_edit, self.receiver)
348     choice.SetClientData(sel, [clazz, obj])
349 jonathan 717
350 jonathan 730 if self.curProjPanel is not None:
351     self.curProjPanel.Hide()
352     self.sizer_projctrls.Remove(self.curProjPanel)
353 jonathan 717
354 jonathan 730 self.curProjPanel = obj
355     self.curProjPanel.Show()
356 jonathan 717
357 jonathan 730 self.sizer_projctrls.Add(self.curProjPanel, 1,
358     wxALL|wxEXPAND|wxADJUST_MINSIZE, 3)
359     self.sizer_projctrls.Layout()
360     self.Layout()
361     self.topBox.SetSizeHints(self)
362 jonathan 717
363     def __SetProjection(self):
364    
365     #
366     # save the original projection only once in case
367     # we try to apply several different projections
368     #
369     if self.originalProjection == -1:
370     self.originalProjection = self.receiver.GetProjection()
371    
372 jonathan 730 self.receiver.SetProjection(self.__GetProjection())
373 jonathan 717
374 jonathan 730 def __GetProjection(self):
375     """Return the packaged projection.
376 jonathan 717
377 jonathan 730 Could be None.
378     """
379 jonathan 717
380 jonathan 730 proj = None
381 jonathan 717
382 jonathan 730 if self.curProjPanel is not None:
383     proj = Projection(self.curProjPanel.GetParameters())
384     proj.SetName(self.projname.GetValue())
385 jonathan 717
386 jonathan 730 return proj
387    
388 jonathan 747 def __FillAvailList(self, selectCurrent = False):
389 jonathan 730 self.availprojs.Clear()
390    
391     #
392 jonathan 747 # We add the current projection to the list first so that
393     # we are sure that it's at index 0. That way we can
394     # set the selection with confidence. The problem is the
395     # the list is automatically sorted when an item is appended
396     # and the index of where it was inserted is not returned.
397     #
398     proj = self.receiver.GetProjection()
399     if proj is not None:
400     self.availprojs.Append(_("%s (current)") % proj.GetName(),
401     [proj, None])
402     if selectCurrent:
403     self.availprojs.SetSelection(0)
404     self.availprojs.SetFirstItem(0)
405    
406     #
407 jonathan 730 # the list can never be empty. there will always be
408     # at least this one item
409     #
410     self.availprojs.Append("<None>", (None, None))
411    
412     self.__sysProjFile = None
413     self.__usrProjFile = None
414    
415     projfile = GetSystemProjFiles()
416     if len(projfile) > 0:
417     projfile = projfile[0]
418 jonathan 717 for proj in projfile.GetProjections():
419 jonathan 730 self.availprojs.Append(proj.GetName(), [proj, projfile])
420     self.__sysProjFile = projfile
421 jonathan 717
422 jonathan 730 projfile = GetUserProjFiles()
423     if len(projfile) > 0:
424     projfile = projfile[0]
425 jonathan 717 for proj in projfile.GetProjections():
426 jonathan 730 self.availprojs.Append(proj.GetName(), [proj, projfile])
427     self.__usrProjFile = projfile
428 jonathan 717
429     for proj, name, clazz in self.projPanels:
430     self.projchoice.Append(name, [clazz, None])
431    
432 jonathan 730 def __set_properties(self):
433    
434 jonathan 717 self.SetTitle(_("Projections"))
435     self.availprojs.SetSelection(0)
436     self.projchoice.SetSelection(0)
437    
438 jonathan 747 self.__FillAvailList(selectCurrent = True)
439    
440 jonathan 730 self.projname.SetMaxLength(32)
441    
442 jonathan 717 def __do_layout(self):
443 jonathan 730 # originally generated by wxGlade
444    
445 jonathan 717 self.topBox = wxBoxSizer(wxVERTICAL)
446     self.sizer_panel = wxBoxSizer(wxVERTICAL)
447     sizer_6 = wxBoxSizer(wxHORIZONTAL)
448     self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL)
449 jonathan 730 self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL)
450 jonathan 717 sizer_11 = wxBoxSizer(wxVERTICAL)
451     self.sizer_projctrls = wxBoxSizer(wxVERTICAL)
452     sizer_14 = wxBoxSizer(wxHORIZONTAL)
453     sizer_13 = wxBoxSizer(wxHORIZONTAL)
454 jonathan 730 sizer_15 = wxBoxSizer(wxVERTICAL)
455     sizer_15.Add(self.button_import, 0, wxALL, 4)
456     sizer_15.Add(self.button_export, 0, wxALL, 4)
457     sizer_15.Add(20, 20, 0, wxEXPAND, 0)
458     sizer_15.Add(self.button_remove, 0, wxALL|wxALIGN_BOTTOM, 4)
459    
460     # list controls
461     grid_sizer_1 = wxFlexGridSizer(3, 2, 0, 0)
462 jonathan 717 grid_sizer_1.Add(self.label_5, 0, wxLEFT|wxRIGHT|wxTOP, 4)
463     grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0)
464 jonathan 730 grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
465     grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4)
466     grid_sizer_1.Add(self.projfilepath, 0, wxALL|wxADJUST_MINSIZE, 4)
467 jonathan 717 grid_sizer_1.AddGrowableRow(1)
468     grid_sizer_1.AddGrowableCol(0)
469 jonathan 730
470     # edit controls
471 jonathan 717 sizer_13.Add(self.label_2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
472     sizer_13.Add(self.projname, 1, wxALL, 4)
473     self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0)
474     sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4)
475 jonathan 730 sizer_14.Add(self.projchoice, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
476 jonathan 717 self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0)
477     self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0)
478     sizer_11.Add(self.button_new, 0, wxALL|wxEXPAND, 4)
479 jonathan 730 sizer_11.Add(self.button_save, 0, wxALL|wxEXPAND, 4)
480     sizer_11.Add(self.button_add, 0, wxALL|wxEXPAND, 4)
481 jonathan 717 self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4)
482 jonathan 730
483 jonathan 717 sizer_6.Add(20, 20, 1, wxEXPAND, 0)
484     sizer_6.Add(self.button_try, 0, wxALL, 4)
485     sizer_6.Add(20, 20, 1, 0, 0)
486     sizer_6.Add(self.button_revert, 0, wxALL, 4)
487     sizer_6.Add(20, 20, 1, 0, 0)
488     sizer_6.Add(self.button_ok, 0, wxALL, 4)
489     sizer_6.Add(20, 20, 1, 0, 0)
490     sizer_6.Add(self.button_close, 0, wxALL, 4)
491     sizer_6.Add(20, 20, 1, wxEXPAND, 0)
492 jonathan 730
493 jonathan 717 self.panel_1.SetAutoLayout(1)
494 jonathan 730 self.panel_1.SetSizer(grid_sizer_1)
495     grid_sizer_1.Fit(self.panel_1)
496     grid_sizer_1.SetSizeHints(self.panel_1)
497    
498     self.panel_edit.SetAutoLayout(1)
499     self.panel_edit.SetSizer(self.sizer_edit)
500     self.sizer_edit.Fit(self.panel_edit)
501     self.sizer_edit.SetSizeHints(self.panel_edit)
502    
503     self.panel_buttons.SetAutoLayout(1)
504     self.panel_buttons.SetSizer(sizer_6)
505     sizer_6.Fit(self.panel_buttons)
506     sizer_6.SetSizeHints(self.panel_buttons)
507    
508     self.sizer_mainctrls.Add(self.panel_1, 0,
509     wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)
510     self.sizer_mainctrls.Add(self.panel_edit, 1,
511     wxALL|wxEXPAND|wxADJUST_MINSIZE, 0)
512    
513     self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4)
514     self.topBox.Add(self.panel_buttons, 0, wxEXPAND, 0)
515    
516 jonathan 717 self.SetAutoLayout(1)
517     self.SetSizer(self.topBox)
518     self.topBox.Fit(self)
519     self.topBox.SetSizeHints(self)
520     self.Layout()
521    
522     # end of class ProjFrame
523    
524    
525     class ProjPanel(wxPanel):
526     """Base class for all projection panels."""
527    
528     def __init__(self, parent):
529     wxPanel.__init__(self, parent, -1)
530    
531     self.__ellps = wxChoice(self, -1)
532     self.ellpsData = [("bessel", _("Bessel 1841")),
533     ("clrk66", _("Clarke 1866")),
534     ("clrk80", _("Clarke 1880")),
535     ("GRS80" , _("GRS 1980 (IUGG, 1980)")),
536     ("intl" , _("International 1909 (Hayford)")),
537     ("WGS84" , _("WGS 84"))]
538    
539     for tag, name in self.ellpsData:
540     self.__ellps.Append(name, tag)
541    
542     self.__ellps.SetSelection(0)
543    
544     def _DoLayout(self, childPanel = None):
545    
546     panelSizer = wxBoxSizer(wxVERTICAL)
547    
548     if childPanel is not None:
549     panelSizer.Add(childPanel, 0, wxALL|wxEXPAND, 4)
550    
551     sizer = wxBoxSizer(wxHORIZONTAL)
552     sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, wxALL, 4)
553 jonathan 730 sizer.Add(self.__ellps, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4)
554 jonathan 717 panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4)
555    
556     self.SetAutoLayout(1)
557     self.SetSizer(panelSizer)
558     panelSizer.Fit(self)
559     panelSizer.SetSizeHints(self)
560     self.Layout()
561    
562     def SetProjection(self, proj):
563     if proj is not None:
564     param = proj.GetParameter("ellps")
565     i = 0
566     for tag, name in self.ellpsData:
567     if param == tag:
568     self.__ellps.SetSelection(i)
569     return # returning early!
570     i += 1
571    
572     #
573     # if proj is none, or the parameter couldn't be found...
574     #
575     self.__ellps.SetSelection(0)
576    
577     def GetParameters(self):
578     return ["ellps=" + self.__ellps.GetClientData(
579     self.__ellps.GetSelection())]
580    
581    
582     ID_TMPANEL_LAT = 4001
583     ID_TMPANEL_LONG = 4002
584     ID_TMPANEL_FASLE_EAST = 4003
585     ID_TMPANEL_FALSE_NORTH = 4004
586     ID_TMPANEL_SCALE = 4005
587    
588     class UnknownProjPanel(ProjPanel):
589 jonathan 730 def __init__(self, parent, receiver):
590 jonathan 717 ProjPanel.__init__(self, parent)
591    
592     self._DoLayout()
593    
594     def _DoLayout(self):
595     sizer = wxBoxSizer(wxVERTICAL)
596    
597     sizer.Add(wxStaticText(self, -1,
598     _("Thuban does not know the parameters for the " +
599     "current projection and cannot display a " +
600     "configuration panel.")))
601    
602     ProjPanel._DoLayout(self, sizer)
603    
604     def GetProjName(self):
605     return "Unknown"
606    
607     def SetProjection(self, proj):
608     pass
609    
610     def GetParameters(self):
611     return None
612    
613     class TMPanel(ProjPanel):
614 jonathan 730 """Projection panel for Transverse Mercator."""
615 jonathan 717
616 jonathan 730 def __init__(self, parent, receiver):
617 jonathan 717 ProjPanel.__init__(self, parent)
618    
619     self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT)
620     self.__longitude = wxTextCtrl(self, ID_TMPANEL_LONG)
621     self.__falseEast = wxTextCtrl(self, ID_TMPANEL_FASLE_EAST)
622     self.__falseNorth = wxTextCtrl(self, ID_TMPANEL_FALSE_NORTH)
623     self.__scale = wxTextCtrl(self, ID_TMPANEL_SCALE)
624    
625     self._DoLayout()
626    
627     def _DoLayout(self):
628    
629     sizer = wxFlexGridSizer(4, 4, 0, 0)
630     sizer.Add(wxStaticText(self, -1, _("Latitude:")), 0, wxALL, 4)
631     sizer.Add(self.__latitude, 0, wxALL, 4)
632     sizer.Add(wxStaticText(self, -1, _("False Easting:")), 0, wxALL, 4)
633     sizer.Add(self.__falseEast, 0, wxALL, 4)
634     sizer.Add(wxStaticText(self, -1, _("Longitude:")), 0, wxALL, 4)
635     sizer.Add(self.__longitude, 0, wxALL, 4)
636     sizer.Add(wxStaticText(self, -1, _("False Northing:")), 0, wxALL, 4)
637     sizer.Add(self.__falseNorth, 0, wxALL, 4)
638     sizer.Add(wxStaticText(self, -1, _("Scale Factor:")), 0, wxALL, 4)
639     sizer.Add(self.__scale, 0, wxALL, 4)
640    
641     ProjPanel._DoLayout(self, sizer)
642    
643     def GetProjName(self):
644 jonathan 730 return _("Transverse Mercator")
645 jonathan 717
646     def SetProjection(self, proj):
647     ProjPanel.SetProjection(self, proj)
648    
649     self.__latitude.SetValue(proj.GetParameter("lat_0"))
650     self.__longitude.SetValue(proj.GetParameter("lon_0"))
651     self.__falseEast.SetValue(proj.GetParameter("x_0"))
652     self.__falseNorth.SetValue(proj.GetParameter("y_0"))
653     self.__scale.SetValue(proj.GetParameter("k"))
654    
655     ProjPanel.SetProjection(self, proj)
656    
657     def GetParameters(self):
658     params = ["proj=tmerc",
659     "lat_0=" + self.__latitude.GetValue(),
660     "lon_0=" + self.__longitude.GetValue(),
661     "x_0=" + self.__falseEast.GetValue(),
662     "y_0=" + self.__falseNorth.GetValue(),
663     "k=" + self.__scale.GetValue()]
664     params.extend(ProjPanel.GetParameters(self))
665     return params
666    
667     def Clear(self):
668     self.__latitude.Clear()
669     self.__longitude.Clear()
670     self.__falseEast.Clear()
671     self.__falseNorth.Clear()
672     self.__scale.Clear()
673    
674     ProjPanel.Clear(self)
675    
676     ID_UTMPANEL_ZONE = 4001
677     ID_UTMPANEL_SOUTH = 4002
678     ID_UTMPANEL_PROP = 4003
679    
680     class UTMPanel(ProjPanel):
681 jonathan 730 """Projection Panel for Universal Transverse Mercator."""
682 jonathan 717
683 jonathan 730 def __init__(self, parent, receiver):
684 jonathan 717 ProjPanel.__init__(self, parent)
685    
686 jonathan 730 self.receiver = receiver
687 jonathan 717
688     self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60)
689     self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH,
690     _("Southern Hemisphere"))
691     self.__propButton = wxButton(self, ID_UTMPANEL_PROP, _("Propose"))
692    
693     self._DoLayout()
694    
695     EVT_BUTTON(self, ID_UTMPANEL_PROP, self._OnPropose)
696    
697     def _DoLayout(self):
698    
699     sizer = wxBoxSizer(wxVERTICAL)
700     psizer = wxBoxSizer(wxHORIZONTAL)
701     psizer.Add(wxStaticText(self, -1, _("Zone:")), 0, wxALL, 4)
702     psizer.Add(self.__zone, 0, wxALL, 4)
703     psizer.Add(self.__propButton, 0, wxALL, 4)
704     sizer.Add(psizer, 0, wxALL, 4)
705     sizer.Add(self.__south, 0, wxALL, 4)
706    
707     ProjPanel._DoLayout(self, sizer)
708    
709     def GetProjName(self):
710 jonathan 730 return _("Universal Transverse Mercator")
711 jonathan 717
712     def SetProjection(self, proj):
713     self.__zone.SetValue(int(proj.GetParameter("zone")))
714     self.__south.SetValue(proj.GetParameter("south") != "")
715     ProjPanel.SetProjection(self, proj)
716    
717     def GetParameters(self):
718     params = ["proj=utm", "zone=" + str(self.__zone.GetValue())]
719     if self.__south.IsChecked():
720     params.append("south")
721    
722     params.extend(ProjPanel.GetParameters(self))
723     return params
724    
725     def Clear(self):
726     self.__zone.SetValue(1)
727     self.__south.SetValue(False)
728     ProjPanel.Clear(self)
729    
730     def _OnPropose(self, event):
731     UTMProposeZoneDialog
732 jonathan 730 dlg = UTMProposeZoneDialog(self, self.receiver.BoundingBox())
733 jonathan 717 if dlg.ShowModal() == wxID_OK:
734     self.__zone.SetValue(dlg.GetProposedZone())
735    
736     class LCCPanel(ProjPanel):
737     """Projection Panel for Lambert Conic Conformal."""
738    
739 jonathan 730 def __init__(self, parent, receiver):
740 jonathan 717 ProjPanel.__init__(self, parent)
741    
742     self.__fspLatitude = wxTextCtrl(self, -1)
743     self.__sspLatitude = wxTextCtrl(self, -1)
744     self.__originLat = wxTextCtrl(self, -1)
745     self.__meridian = wxTextCtrl(self, -1)
746     self.__falseEast = wxTextCtrl(self, -1)
747     self.__falseNorth = wxTextCtrl(self, -1)
748    
749     self._DoLayout()
750    
751     def _DoLayout(self):
752    
753     sizer = wxFlexGridSizer(6, 2, 0, 0)
754     sizer.Add(wxStaticText(self, -1,
755     _("Latitude of first standard parallel:")))
756     sizer.Add(self.__fspLatitude, 0, wxALL, 4)
757     sizer.Add(wxStaticText(self, -1,
758     _("Latitude of second standard parallel:")))
759     sizer.Add(self.__sspLatitude, 0, wxALL, 4)
760     sizer.Add(wxStaticText(self, -1, _("Latitude of origin:")))
761     sizer.Add(self.__originLat, 0, wxALL, 4)
762     sizer.Add(wxStaticText(self, -1, _("Central Meridian:")))
763     sizer.Add(self.__meridian, 0, wxALL, 4)
764     sizer.Add(wxStaticText(self, -1, _("False Easting:")))
765     sizer.Add(self.__falseEast, 0, wxALL, 4)
766     sizer.Add(wxStaticText(self, -1, _("False Northing:")))
767     sizer.Add(self.__falseNorth, 0, wxALL, 4)
768    
769     ProjPanel._DoLayout(self, sizer)
770    
771     def GetProjName(self):
772     return _("Lambert Conic Conformal")
773    
774     def SetProjection(self, proj):
775     self.__fspLatitude.SetValue(proj.GetParameter("lat_1"))
776     self.__sspLatitude.SetValue(proj.GetParameter("lat_2"))
777     self.__originLat.SetValue(proj.GetParameter("lat_0"))
778     self.__meridian.SetValue(proj.GetParameter("lon_0"))
779     self.__falseEast.SetValue(proj.GetParameter("x_0"))
780     self.__falseNorth.SetValue(proj.GetParameter("y_0"))
781    
782     ProjPanel.SetProjection(self, proj)
783    
784     def GetParameters(self):
785     params = ["proj=lcc",
786     "lat_1=" + self.__fspLatitude.GetValue(),
787     "lat_2=" + self.__sspLatitude.GetValue(),
788     "lat_0=" + self.__originLat.GetValue(),
789     "lon_0=" + self.__meridian.GetValue(),
790     "x_0=" + self.__falseEast.GetValue(),
791     "y_0=" + self.__falseNorth.GetValue()]
792    
793     params.extend(ProjPanel.GetParameters(self))
794     return params
795    
796     def Clear(self):
797     self.__fspLatitude.Clear()
798     self.__sspLatitude.Clear()
799     self.__originLat.Clear()
800     self.__meridian.Clear()
801     self.__falseEast.Clear()
802     self.__falseNorth.Clear()
803    
804     ProjPanel.Clear(self)
805    
806     class GeoPanel(ProjPanel):
807     """Projection Panel for a Geographic Projection."""
808    
809 jonathan 730 def __init__(self, parent, receiver):
810 jonathan 717 ProjPanel.__init__(self, parent)
811     ProjPanel._DoLayout(self, None)
812    
813     def GetProjName(self):
814     return _("Geographic")
815    
816     def SetProjection(self, proj):
817     ProjPanel.SetProjection(self, proj)
818    
819     def GetParameters(self):
820     params = ["proj=latlong"]
821     params.extend(ProjPanel.GetParameters(self))
822     return params
823    
824     def Clear(self):
825     ProjPanel.Clear(self)
826    
827    
828     ID_UTM_PROPOSE_ZONE_DIALOG_TAKE = 4001
829     ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002
830     class UTMProposeZoneDialog(wxDialog):
831    
832     """Propose a sensible Zone considering the current map extent."""
833    
834     def __init__(self, parent, (x, y, x2, y2)):
835     wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"),
836     wxDefaultPosition, wxSize(200, 100))
837     self.parent = parent
838     #x, y, x2, y2 = elf.parent.parent.map_bounding_box
839     x = x + 180
840     x2 = x2 + 180
841     center = (x2 - x) / 2 + x
842     self.proposedZone = int(center / 6 + 1)
843     self.dialogLayout()
844    
845     def dialogLayout(self):
846     topBox = wxBoxSizer(wxVERTICAL)
847    
848     textBox = wxBoxSizer(wxVERTICAL)
849     textBox.Add(wxStaticText(self, -1, _("The current map extent center " +
850     "lies in UTM Zone")),
851     0, wxALIGN_CENTER|wxALL, 4)
852     textBox.Add(wxStaticText(self, -1, str(self.proposedZone)),
853     0, wxALIGN_CENTER|wxALL, 4)
854    
855     topBox.Add(textBox, 1, wxEXPAND|wxALL, 4)
856    
857     buttonBox = wxBoxSizer(wxHORIZONTAL)
858     buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE,
859     _("Take")), 0, wxALL, 4)
860     buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL,
861     _("Cancel")), 0, wxALL, 4)
862     topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10)
863     EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake)
864     EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel)
865    
866     self.SetAutoLayout(True)
867     self.SetSizer(topBox)
868     topBox.Fit(self)
869     topBox.SetSizeHints(self)
870    
871     def OnTake(self, event):
872     self.EndModal(wxID_OK)
873    
874     def OnCancel(self, event):
875     self.EndModal(wxID_CANCEL)
876    
877     def GetProposedZone(self):
878     return self.proposedZone

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26