1 |
#!/usr/bin/env python |
# Copyright (c) 2003 by Intevation GmbH |
2 |
# generated by wxGlade 0.2.1 on Thu Apr 17 11:51:39 2003 |
# Authors: |
3 |
|
# Jonathan Coles <[email protected]> |
4 |
|
# Frank Koormann <[email protected]> |
5 |
|
# Jan-Oliver Wagner <[email protected]> |
6 |
|
# |
7 |
|
# This program is free software under the GPL (>=v2) |
8 |
|
# Read the file COPYING coming with Thuban for details. |
9 |
|
|
10 |
|
"""Projection dialog""" |
11 |
|
|
12 |
|
__version__ = "$Revision$" |
13 |
|
# $Source$ |
14 |
|
# $Id$ |
15 |
|
|
16 |
import os, sys |
import os, sys, math |
17 |
from wxPython.wx import * |
from wxPython.wx import * |
18 |
|
|
19 |
from Thuban import _ |
from Thuban import _ |
20 |
|
|
21 |
from Thuban.Model.proj import Projection, ProjFile |
from Thuban.Model.proj import Projection, ProjFile |
22 |
|
|
23 |
from Thuban.Model.resource import GetUserProjFiles, GetSystemProjFiles, \ |
from Thuban.Model.resource import get_user_proj_files, get_system_proj_files, \ |
24 |
ReadProjFile, WriteProjFile |
read_proj_file, write_proj_file |
25 |
from Thuban.UI.dialogs import NonModalDialog |
from Thuban.UI.dialogs import NonModalNonParentDialog |
26 |
|
|
27 |
|
|
28 |
ID_PROJ_ADVANCED = 4001 |
ID_PROJ_ADVANCED = 4001 |
29 |
ID_PROJ_PROJCHOICE = 4002 |
ID_PROJ_PROJCHOICE = 4002 |
30 |
ID_PROJ_SAVEAS = 4003 |
ID_PROJ_ADDTOLIST = 4003 |
31 |
ID_PROJ_NEW = 4004 |
ID_PROJ_NEW = 4004 |
|
ID_PROJ_TRY = 4005 |
|
32 |
ID_PROJ_REVERT = 4006 |
ID_PROJ_REVERT = 4006 |
|
ID_PROJ_OK = 4007 |
|
|
ID_PROJ_CLOSE = 4008 |
|
33 |
ID_PROJ_AVAIL = 4009 |
ID_PROJ_AVAIL = 4009 |
34 |
ID_PROJ_SAVE = 4010 |
ID_PROJ_SAVE = 4010 |
35 |
ID_PROJ_IMPORT = 4011 |
ID_PROJ_IMPORT = 4011 |
40 |
CLIENT_PROJ = 0 |
CLIENT_PROJ = 0 |
41 |
CLIENT_PROJFILE = 1 |
CLIENT_PROJFILE = 1 |
42 |
|
|
43 |
class ProjFrame(NonModalDialog): |
class ProjFrame(NonModalNonParentDialog): |
44 |
|
|
45 |
def __init__(self, parent, name, receiver, *args, **kwds): |
def __init__(self, parent, name, title, receiver): |
46 |
"""Initialize the projection dialog. |
"""Initialize the projection dialog. |
47 |
|
|
48 |
receiver -- An object that implements the following methods: |
receiver -- An object that implements the following methods: |
51 |
""" |
""" |
52 |
|
|
53 |
self.receiver = receiver |
self.receiver = receiver |
54 |
self.originalProjection = -1 |
self.haveTried = False |
55 |
self.curProjPanel = None |
self.curProjPanel = None |
56 |
|
|
57 |
self.projPanels = [] |
self.projPanels = [] |
64 |
self.projPanels.append( |
self.projPanels.append( |
65 |
("latlong", _("Geographic"), GeoPanel)) |
("latlong", _("Geographic"), GeoPanel)) |
66 |
|
|
67 |
NonModalDialog.__init__(self, parent, name, "") |
NonModalNonParentDialog.__init__(self, parent, name, title) |
68 |
# originally generate by wxGlade |
# originally generate by wxGlade |
69 |
self.panel_1 = wxPanel(self, -1) |
self.panel_1 = wxPanel(self, -1) |
70 |
self.panel_edit = wxPanel(self, -1) |
self.panel_edit = wxPanel(self, -1) |
71 |
self.panel_buttons = wxPanel(self, -1) |
self.label_5 = wxStaticText(self.panel_1, -1, |
72 |
self.label_5 = wxStaticText(self.panel_1, -1, _("Available Projections:")) |
_("Available Projections:")) |
73 |
self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL, style=wxLB_EXTENDED |wxLB_SORT) |
|
74 |
|
# Projection List specific actions (Import/Export/Remove) |
75 |
|
self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT, |
76 |
|
_("Import...")) |
77 |
|
self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT, |
78 |
|
_("Export...")) |
79 |
|
self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE, |
80 |
|
_("Remove")) |
81 |
|
|
82 |
|
# The Projection List |
83 |
|
self.availprojs = wxListBox(self.panel_1, ID_PROJ_AVAIL, |
84 |
|
style=wxLB_EXTENDED|wxLB_SORT) |
85 |
self.projfilepath = wxStaticText(self.panel_1, -1, "") |
self.projfilepath = wxStaticText(self.panel_1, -1, "") |
86 |
|
|
87 |
|
# Projection Specific Entries (Name/Projection) |
88 |
self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:")) |
self.label_2 = wxStaticText(self.panel_edit, -1, _("Name:")) |
89 |
self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "") |
self.projname = wxTextCtrl(self.panel_edit, ID_PROJ_PROJNAME, "") |
90 |
self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:")) |
self.label_3 = wxStaticText(self.panel_edit, -1, _("Projection:")) |
91 |
self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE) |
self.projchoice = wxChoice(self.panel_edit, ID_PROJ_PROJCHOICE) |
92 |
self.button_import = wxButton(self.panel_1, ID_PROJ_IMPORT, _("Import...")) |
|
93 |
self.button_export = wxButton(self.panel_1, ID_PROJ_EXPORT, _("Export...")) |
# Projection Specific actions (New/Save/Add) |
|
self.button_remove = wxButton(self.panel_1, ID_PROJ_REMOVE, _("Remove")) |
|
94 |
self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New")) |
self.button_new = wxButton(self.panel_edit, ID_PROJ_NEW, _("New")) |
95 |
self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Save")) |
self.button_add = wxButton(self.panel_edit, ID_PROJ_ADDTOLIST, |
|
self.button_add = wxButton(self.panel_edit, ID_PROJ_SAVEAS, |
|
96 |
_("Add to List")) |
_("Add to List")) |
97 |
self.button_try = wxButton(self.panel_buttons, ID_PROJ_TRY, _("Try")) |
self.button_save = wxButton(self.panel_edit, ID_PROJ_SAVE,_("Update")) |
98 |
self.button_revert = wxButton(self.panel_buttons, ID_PROJ_REVERT, _("Revert")) |
|
99 |
self.button_ok = wxButton(self.panel_buttons, ID_PROJ_OK, _("OK")) |
# Main Action buttons (Try/Revert/OK/Close) |
100 |
self.button_close = wxButton(self.panel_buttons, ID_PROJ_CLOSE, _("Close")) |
self.button_try = wxButton(self, wxID_APPLY, _("Try")) |
101 |
|
self.button_revert = wxButton(self, ID_PROJ_REVERT, |
102 |
|
_("Revert")) |
103 |
|
self.button_ok = wxButton(self, wxID_OK, _("OK")) |
104 |
|
self.button_ok.SetDefault() |
105 |
|
self.button_close = wxButton(self, wxID_CANCEL, |
106 |
|
_("Close")) |
107 |
|
|
108 |
self.__set_properties() |
self.__set_properties() |
109 |
self.__do_layout() |
self.__do_layout() |
110 |
|
|
111 |
# wxGlade |
# wxGlade |
112 |
|
|
113 |
|
# Fill the projection choice list. |
114 |
|
for proj, name, clazz in self.projPanels: |
115 |
|
self.projchoice.Append(name, [clazz, None]) |
116 |
|
|
117 |
|
self.originalProjection = self.receiver.GetProjection() |
118 |
|
|
119 |
self.__DoOnProjAvail() |
self.__DoOnProjAvail() |
120 |
|
self.button_ok.SetFocus() |
121 |
|
self.availprojs.SetFocus() |
122 |
|
|
123 |
EVT_BUTTON(self, ID_PROJ_TRY, self._OnTry) |
EVT_BUTTON(self, wxID_APPLY, self.OnApply) |
124 |
EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert) |
EVT_BUTTON(self, ID_PROJ_REVERT, self._OnRevert) |
125 |
EVT_BUTTON(self, ID_PROJ_OK, self._OnOK) |
EVT_BUTTON(self, wxID_OK, self.OnOK) |
126 |
EVT_BUTTON(self, ID_PROJ_CLOSE, self._OnClose) |
EVT_BUTTON(self, wxID_CANCEL, self.OnCancel) |
127 |
EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice) |
EVT_CHOICE(self, ID_PROJ_PROJCHOICE, self._OnProjChoice) |
128 |
EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail) |
EVT_LISTBOX(self, ID_PROJ_AVAIL, self._OnProjAvail) |
129 |
EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport) |
EVT_BUTTON(self, ID_PROJ_IMPORT, self._OnImport) |
132 |
|
|
133 |
EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew) |
EVT_BUTTON(self, ID_PROJ_NEW, self._OnNew) |
134 |
EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave) |
EVT_BUTTON(self, ID_PROJ_SAVE, self._OnSave) |
135 |
EVT_BUTTON(self, ID_PROJ_SAVEAS, self._OnSaveAs) |
EVT_BUTTON(self, ID_PROJ_ADDTOLIST, self._OnAddToList) |
136 |
|
|
137 |
EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName) |
EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName) |
138 |
|
|
139 |
def GetReceiver(self): |
def OnApply(self, event): |
|
return self.receiver |
|
|
|
|
|
def _OnTry(self, event): |
|
140 |
self.__SetProjection() |
self.__SetProjection() |
141 |
|
self.haveTried = True |
142 |
|
|
143 |
def _OnRevert(self, event): |
def OnOK(self, event): |
|
if self.originalProjection != -1: |
|
|
self.receiver.SetProjection(self.originalProjection) |
|
|
|
|
|
def _OnOK(self, event): |
|
144 |
self.__SetProjection() |
self.__SetProjection() |
145 |
self.Close() |
self.Close() |
146 |
|
|
147 |
def _OnClose(self, event): |
def OnCancel(self, event): |
148 |
|
"""Cancel just closes the dialog, but we call it cancel so we |
149 |
|
can overload the functionality of wxDialog. |
150 |
|
""" |
151 |
self.Close() |
self.Close() |
152 |
|
|
153 |
|
def _OnRevert(self, event): |
154 |
|
if self.haveTried: |
155 |
|
self.receiver.SetProjection(self.originalProjection) |
156 |
|
self.haveTried = False |
157 |
|
|
158 |
def _OnNew(self, event): |
def _OnNew(self, event): |
159 |
self.__DoOnNew() |
|
160 |
|
# clear all selections |
161 |
|
sel = self.availprojs.GetSelections() |
162 |
|
for index in sel: |
163 |
|
self.availprojs.SetSelection(index, False) |
164 |
|
|
165 |
|
self.projname.Clear() |
166 |
|
|
167 |
|
# supply a projection panel if there wasn't one |
168 |
|
if self.curProjPanel is None: |
169 |
|
self.projchoice.SetSelection(0) |
170 |
|
self.__DoOnProjChoice() |
171 |
|
|
172 |
|
self.curProjPanel.Clear() |
173 |
|
|
174 |
def _OnSave(self, event): |
def _OnSave(self, event): |
175 |
|
|
183 |
newproj = self.__GetProjection() |
newproj = self.__GetProjection() |
184 |
|
|
185 |
if newproj is not None: |
if newproj is not None: |
186 |
projfile.Remove(proj) |
projfile.Replace(proj, newproj) |
|
projfile.Add(newproj) |
|
187 |
try: |
try: |
188 |
WriteProjFile(projfile) |
write_proj_file(projfile) |
189 |
except IOError, (errno, errstr): |
except IOError, (errno, errstr): |
190 |
wxMessageDialog(self, |
self.__ShowError(projfile.GetFilename(), errstr) |
191 |
_("The following error occured:\n") + |
self.availprojs.SetClientData(sel[0], [newproj, projfile]) |
|
projfile.GetFileName() + "\n" + errstr, |
|
|
_("Error"), wxOK | wxICON_ERROR).ShowModal() |
|
|
self.__FillAvailList() |
|
192 |
|
|
193 |
def _OnSaveAs(self, event): |
self.__FillAvailList( selectProj = newproj.GetName()) |
194 |
|
|
195 |
|
def _OnAddToList(self, event): |
196 |
|
|
197 |
proj = self.__GetProjection() |
proj = self.__GetProjection() |
198 |
if proj is not None: |
if proj is not None: |
199 |
self.__usrProjFile.Add(proj) |
self.__usrProjFile.Add(proj) |
200 |
try: |
try: |
201 |
WriteProjFile(self.__usrProjFile) |
write_proj_file(self.__usrProjFile) |
202 |
except IOError, (errno, errstr): |
except IOError, (errno, errstr): |
203 |
wxMessageDialog(self, |
self.__ShowError(self.__userProjFile.GetFilename(), errstr) |
|
_("The following error occured:\n") + |
|
|
self.__usrProjFile.GetFileName() + "\n" + errstr, |
|
|
_("Error"), wxOK | wxICON_ERROR).ShowModal() |
|
|
self.__FillAvailList() |
|
|
|
|
|
return |
|
|
|
|
|
"""Save the projection somewhere. |
|
204 |
|
|
205 |
There are three important cases to consider. |
self.__FillAvailList( selectProj = proj.GetName()) |
|
1. the file already exists and the user wants to overwrite it. |
|
|
2. the file already exists and the user wants to append the |
|
|
current projection to the end of the file |
|
|
3. the file doesn't exist and the user wants to create it |
|
|
|
|
|
The list of available projections is then updated. |
|
|
""" |
|
|
|
|
|
proj = Projection(self.curProjPanel.GetParameters()) |
|
|
if self.projname.GetValue() != "": |
|
|
proj.SetName(self.projname.GetValue()) |
|
|
|
|
|
dlg = wxFileDialog(self, _("Save As"), style = wxSAVE) |
|
|
if dlg.ShowModal() == wxID_OK: |
|
|
path = dlg.GetPath() |
|
|
|
|
|
if os.access(path, os.F_OK): |
|
|
# file already exists. |
|
|
if os.access(path, os.W_OK | os.R_OK): |
|
|
|
|
|
# is it a .proj file? |
|
|
try: |
|
|
projFile = ReadProjFile(path) |
|
|
except: |
|
|
# obviously not. |
|
|
dlg = wxMessageDialog(self, |
|
|
path + _(" already exists. Overwrite?"), |
|
|
"", |
|
|
wxYES | wxNO) |
|
|
|
|
|
if dlg.ShowModal() == wxID_YES: |
|
|
projFile = ProjFile(path) |
|
|
else: |
|
|
return # returning early |
|
|
else: |
|
|
# ask the user to overwrite or append |
|
|
dlg = wxMessageDialog(self, |
|
|
_("The selected projection file already exists.\n"+ |
|
|
"The current projection can be added to the " + |
|
|
"file, or it can completely replace the " + |
|
|
"selected file.\n\nShould the current " + |
|
|
"projection be added to the file?"), |
|
|
_("Question"), |
|
|
wxYES | wxNO | wxICON_QUESTION) |
|
|
|
|
|
if dlg.ShowModal() == wxID_NO: |
|
|
projFile = ProjFile(path) |
|
|
else: |
|
|
# can't access the file |
|
|
dlg = wxMessageDialog(self, |
|
|
_("Couldn't access ") + path, |
|
|
"", |
|
|
wxOK | wxICON | wxICON_EXCLAMATION) |
|
|
return |
|
|
|
|
|
else: |
|
|
# file doesn't exist. make a new one. |
|
|
projFile = ProjFile(path) |
|
|
|
|
|
# |
|
|
# if we get this far we have a valid projFile and |
|
|
# can just write the file |
|
|
# |
|
|
projFile.Add(proj) |
|
|
try: |
|
|
WriteProjFile(projFile) |
|
|
self.__FillAvailList() |
|
|
except IOError, (errno, errstr): |
|
|
wxMessageDialog(self, |
|
|
_("The following error occured:\n") + |
|
|
dlg.GetPath() + "\n" + errstr, |
|
|
_("Error"), wxOK | wxICON_ERROR).ShowModal() |
|
|
dlg.Destroy() |
|
206 |
|
|
207 |
def _OnProjAvail(self, event): |
def _OnProjAvail(self, event): |
208 |
self.__DoOnProjAvail() |
self.__DoOnProjAvail() |
215 |
path = dlg.GetPath() |
path = dlg.GetPath() |
216 |
|
|
217 |
try: |
try: |
218 |
projFile = ReadProjFile(path) |
projFile = read_proj_file(path) |
219 |
for proj in projFile.GetProjections(): |
for proj in projFile.GetProjections(): |
220 |
self.__usrProjFile.Add(proj) |
self.__usrProjFile.Add(proj) |
221 |
WriteProjFile(self.__usrProjFile) |
write_proj_file(self.__usrProjFile) |
222 |
except IOError, (errno, errstr): |
except IOError, (errno, errstr): |
223 |
wxMessageDialog(self, |
self.__ShowError(dlg.GetPath(), errstr) |
|
_("The following error occured:\n") + |
|
|
dlg.GetPath() + "\n" + errstr, |
|
|
_("Error"), wxOK | wxICON_ERROR).ShowModal() |
|
224 |
|
|
225 |
self.__FillAvailList() |
self.__FillAvailList() |
226 |
|
|
227 |
dlg.Destroy() |
dlg.Destroy() |
228 |
|
|
229 |
def _OnExport(self, event): |
def _OnExport(self, event): |
|
proj = self.__GetProjection() |
|
230 |
|
|
231 |
if proj is None: return |
sel = self.availprojs.GetSelections() |
232 |
|
assert len(sel) != 0, "button should be disabled" |
233 |
|
|
234 |
dlg = wxFileDialog(self, _("Export"), |
dlg = wxFileDialog(self, _("Export"), |
235 |
style = wxSAVE|wxOVERWRITE_PROMPT) |
style = wxSAVE|wxOVERWRITE_PROMPT) |
236 |
|
|
237 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
238 |
path = dlg.GetPath() |
path = dlg.GetPath() |
239 |
|
|
240 |
projFile = ProjFile(path) |
projFile = ProjFile(path) |
241 |
projFile.Add(proj) |
|
242 |
|
for i in sel: |
243 |
|
proj = self.availprojs.GetClientData(i)[CLIENT_PROJ] |
244 |
|
if proj is not None: |
245 |
|
projFile.Add(proj) |
246 |
|
|
247 |
try: |
try: |
248 |
WriteProjFile(projFile) |
write_proj_file(projFile) |
249 |
except IOError, (errno, errstr): |
except IOError, (errno, errstr): |
250 |
wxMessageDialog(self, |
self.__ShowError(dlg.GetPath(), errstr) |
|
_("The following error occured:\n") + |
|
|
dlg.GetPath() + "\n" + errstr, |
|
|
_("Error"), wxOK | wxICON_ERROR).ShowModal() |
|
251 |
|
|
252 |
dlg.Destroy() |
dlg.Destroy() |
253 |
|
|
280 |
projfile.Remove(proj) |
projfile.Remove(proj) |
281 |
|
|
282 |
try: |
try: |
283 |
WriteProjFile(projfile) |
write_proj_file(projfile) |
284 |
except IOError, (errno, errstr): |
except IOError, (errno, errstr): |
285 |
wxMessageDialog(self, |
self.__ShowError(projfile.GetFilename(), errstr) |
|
_("The following error occured:\n") + |
|
|
projfile.GetFileName() + "\n" + errstr, |
|
|
_("Error"), wxOK | wxICON_ERROR).ShowModal() |
|
|
|
|
286 |
|
|
287 |
self.__FillAvailList() |
self.__FillAvailList() |
288 |
|
|
294 |
if newselection != -1 and self.availprojs.GetCount() > 0: |
if newselection != -1 and self.availprojs.GetCount() > 0: |
295 |
self.availprojs.SetSelection(newselection) |
self.availprojs.SetSelection(newselection) |
296 |
|
|
297 |
|
self.__VerifyButtons() |
298 |
|
|
299 |
def _OnProjName(self, event): |
def _OnProjName(self, event): |
300 |
self.__VerifyButtons() |
self.__VerifyButtons() |
301 |
|
|
302 |
|
def __ShowError(self, filename, errstr): |
303 |
|
wxMessageDialog(self, |
304 |
|
_("The following error occured:\n") + |
305 |
|
filename + "\n" + errstr, |
306 |
|
_("Error"), wxOK | wxICON_ERROR).ShowModal() |
307 |
|
|
308 |
def __VerifyButtons(self): |
def __VerifyButtons(self): |
309 |
|
"""Enable or disable the appropriate buttons based on the |
310 |
|
current state of the dialog. |
311 |
|
""" |
312 |
|
|
313 |
sel = self.availprojs.GetSelections() |
sel = self.availprojs.GetSelections() |
314 |
|
|
315 |
self.button_import.Enable(True) |
self.button_import.Enable(True) |
319 |
|
|
320 |
self.panel_edit.Enable(True) |
self.panel_edit.Enable(True) |
321 |
|
|
322 |
|
for ctrl in [self.button_import, |
323 |
|
self.button_export, |
324 |
|
self.button_remove, |
325 |
|
self.button_save, |
326 |
|
self.button_add, |
327 |
|
self.projchoice, |
328 |
|
self.projname, |
329 |
|
self.panel_edit]: |
330 |
|
ctrl.Enable(True) |
331 |
|
|
332 |
|
if self.curProjPanel is not None: |
333 |
|
self.curProjPanel.Enable(True) |
334 |
|
|
335 |
if len(sel) == 0: |
if len(sel) == 0: |
336 |
self.button_import.Enable(True) |
self.button_import.Enable(True) |
337 |
self.button_export.Enable(False) |
self.button_export.Enable(False) |
338 |
self.button_remove.Enable(False) |
self.button_remove.Enable(False) |
339 |
|
self.button_save.Enable(False) |
340 |
|
|
341 |
elif len(sel) == 1: |
elif len(sel) == 1: |
342 |
|
|
346 |
self.button_add.Enable(len(self.projname.GetValue()) > 0) |
self.button_add.Enable(len(self.projname.GetValue()) > 0) |
347 |
|
|
348 |
if proj is None: |
if proj is None: |
349 |
self.button_export.Enable(False) |
# <None> is selected |
350 |
|
for ctrl in [self.button_export, |
351 |
|
self.button_remove, |
352 |
|
self.button_save, |
353 |
|
self.button_add, |
354 |
|
self.projchoice, |
355 |
|
self.projname]: |
356 |
|
ctrl.Enable(False) |
357 |
|
|
358 |
|
if self.curProjPanel is not None: |
359 |
|
self.curProjPanel.Enable(False) |
360 |
|
|
361 |
|
elif proj is self.originalProjection: |
362 |
self.button_remove.Enable(False) |
self.button_remove.Enable(False) |
363 |
|
|
364 |
if projFile is None: |
if projFile is None: |
367 |
else: |
else: |
368 |
self.panel_edit.Enable(False) |
self.panel_edit.Enable(False) |
369 |
|
|
|
def __DoOnNew(self): |
|
|
sel = self.availprojs.GetSelections() |
|
|
if len(sel) != 0: |
|
|
self.availprojs.SetSelection(sel, False) |
|
|
self.projname.Clear() |
|
|
self.curProjPanel.Clear() |
|
|
|
|
370 |
def __DoOnProjAvail(self): |
def __DoOnProjAvail(self): |
371 |
|
|
372 |
sel = self.availprojs.GetSelections() |
sel = self.availprojs.GetSelections() |
378 |
if proj is None: |
if proj is None: |
379 |
# user selected <None> |
# user selected <None> |
380 |
self.projname.Clear() |
self.projname.Clear() |
381 |
|
self.projfilepath.SetLabel(_("Projection File: ")) |
382 |
else: |
else: |
383 |
|
|
384 |
if projfile is not None: |
if projfile is not None: |
385 |
self.projfilepath.SetLabel(projfile.GetFileName()) |
self.projfilepath.SetLabel(_("Projection File: ") + |
386 |
|
os.path.basename(projfile.GetFilename())) |
387 |
else: |
else: |
388 |
# only None if the currently used projection is selected |
# only None if the currently used projection is selected |
389 |
self.projfilepath.SetLabel("") |
self.projfilepath.SetLabel(_("Projection File: ")) |
390 |
|
|
391 |
self.projname.SetValue(proj.GetName()) |
self.projname.SetValue(proj.GetName()) |
392 |
|
|
396 |
if myProjType == projType: |
if myProjType == projType: |
397 |
self.projchoice.SetSelection(i) |
self.projchoice.SetSelection(i) |
398 |
self.__DoOnProjChoice() |
self.__DoOnProjChoice() |
399 |
|
|
400 |
|
# |
401 |
|
# self.curProjPanel should not be null |
402 |
|
# after a call to __DoOnProjChoice |
403 |
|
# |
404 |
|
assert self.curProjPanel is not None |
405 |
|
|
406 |
self.curProjPanel.SetProjection(proj) |
self.curProjPanel.SetProjection(proj) |
407 |
i += 1 |
i += 1 |
408 |
|
|
412 |
self.__DoOnProjChoice() |
self.__DoOnProjChoice() |
413 |
|
|
414 |
def __DoOnProjChoice(self): |
def __DoOnProjChoice(self): |
415 |
|
"""Create and layout a projection panel based on the selected |
416 |
|
projection type. |
417 |
|
|
418 |
|
This is necessary to have in seperate method since calls to |
419 |
|
wxChoice.SetSelection() do not trigger an event. |
420 |
|
|
421 |
|
At the end of this method self.curProjPanel will not be None |
422 |
|
if there was a item selected. |
423 |
|
""" |
424 |
|
|
425 |
choice = self.projchoice |
choice = self.projchoice |
426 |
|
|
427 |
sel = choice.GetSelection() |
sel = choice.GetSelection() |
447 |
self.topBox.SetSizeHints(self) |
self.topBox.SetSizeHints(self) |
448 |
|
|
449 |
def __SetProjection(self): |
def __SetProjection(self): |
450 |
|
"""Set the receiver's projection.""" |
451 |
|
|
452 |
# |
# |
453 |
# save the original projection only once in case |
# save the original projection only once in case |
454 |
# we try to apply several different projections |
# we try to apply several different projections |
455 |
# |
# |
|
if self.originalProjection == -1: |
|
|
self.originalProjection = self.receiver.GetProjection() |
|
|
|
|
456 |
self.receiver.SetProjection(self.__GetProjection()) |
self.receiver.SetProjection(self.__GetProjection()) |
457 |
|
|
458 |
def __GetProjection(self): |
def __GetProjection(self): |
459 |
"""Return the packaged projection. |
"""Return a suitable Projection object based on the current |
460 |
|
state of the dialog box selections. |
461 |
|
|
462 |
Could be None. |
Could be None. |
463 |
""" |
""" |
464 |
|
|
465 |
proj = None |
sel = self.availprojs.GetSelections() |
466 |
|
assert len(sel) < 2, "button should be disabled" |
467 |
|
|
468 |
|
|
469 |
|
if len(sel) == 1: |
470 |
|
proj = self.availprojs.GetClientData(sel[0])[CLIENT_PROJ] |
471 |
|
if proj is None: |
472 |
|
# <None> is selected |
473 |
|
return None |
474 |
|
|
475 |
|
# |
476 |
|
# self.curProjPanel should always contain the most |
477 |
|
# relevant data for a projection |
478 |
|
# |
479 |
if self.curProjPanel is not None: |
if self.curProjPanel is not None: |
480 |
proj = Projection(self.curProjPanel.GetParameters()) |
return Projection(self.curProjPanel.GetParameters(), |
481 |
proj.SetName(self.projname.GetValue()) |
self.projname.GetValue()) |
482 |
|
|
483 |
|
return None |
484 |
|
|
485 |
return proj |
def __FillAvailList(self, selectCurrent = False, selectProj = None): |
486 |
|
"""Populate the list of available projections. |
487 |
|
|
488 |
|
selectCurrent -- if True, select the projection used by |
489 |
|
the receiver, otherwise select nothing. |
490 |
|
selectProj -- if set, select the projection found under the |
491 |
|
specified name. This overwrites any other |
492 |
|
selection estimate. |
493 |
|
""" |
494 |
|
|
|
def __FillAvailList(self): |
|
495 |
self.availprojs.Clear() |
self.availprojs.Clear() |
496 |
|
|
497 |
# |
# |
500 |
# |
# |
501 |
self.availprojs.Append("<None>", (None, None)) |
self.availprojs.Append("<None>", (None, None)) |
502 |
|
|
503 |
self.__sysProjFile = None |
projfile = get_system_proj_files() |
504 |
self.__usrProjFile = None |
projfile = projfile[0] |
505 |
|
for proj in projfile.GetProjections(): |
506 |
projfile = GetSystemProjFiles() |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
507 |
if len(projfile) > 0: |
self.__sysProjFile = projfile |
508 |
projfile = projfile[0] |
|
509 |
for proj in projfile.GetProjections(): |
projfile = get_user_proj_files() |
510 |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
projfile = projfile[0] |
511 |
self.__sysProjFile = projfile |
for proj in projfile.GetProjections(): |
512 |
|
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
513 |
projfile = GetUserProjFiles() |
self.__usrProjFile = projfile |
|
if len(projfile) > 0: |
|
|
projfile = projfile[0] |
|
|
for proj in projfile.GetProjections(): |
|
|
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
|
|
self.__usrProjFile = projfile |
|
|
|
|
|
# projfiles = GetSystemProjFiles() |
|
|
# for projfile in projfiles: |
|
|
# for proj in projfile.GetProjections(): |
|
|
# self.availprojs.Append(proj.GetName(), [proj, projfile]) |
|
|
# self.__sysProjFiles = projfiles |
|
|
|
|
|
# projfiles = GetUserProjFiles() |
|
|
# for projfile in projfiles: |
|
|
# for proj in projfile.GetProjections(): |
|
|
# self.availprojs.Append(proj.GetName(), [proj, projfile]) |
|
|
# self.__usrProjFiles = projfiles |
|
514 |
|
|
515 |
|
# |
516 |
|
# We add the current projection to the list at last. |
517 |
|
# Since the list is resorted immediately a following FindString() |
518 |
|
# determines the index correctly. |
519 |
|
# |
520 |
proj = self.receiver.GetProjection() |
proj = self.receiver.GetProjection() |
521 |
if proj is not None: |
if proj is not None: |
522 |
self.availprojs.Append(proj.GetName() + _(" (current)"), |
proj_item = _("%s (current)") % proj.GetName() |
523 |
[proj, None]) |
self.availprojs.Append(proj_item, [proj, None]) |
524 |
|
if selectCurrent: |
525 |
|
self.availprojs.SetSelection( |
526 |
|
self.availprojs.FindString(proj_item) |
527 |
|
) |
528 |
|
else: |
529 |
|
if selectCurrent: |
530 |
|
self.availprojs.SetSelection( |
531 |
|
self.availprojs.FindString("<None>") |
532 |
|
) |
533 |
|
if selectProj: |
534 |
|
self.availprojs.SetSelection( |
535 |
|
self.availprojs.FindString(selectProj) |
536 |
|
) |
537 |
|
|
538 |
for proj, name, clazz in self.projPanels: |
|
|
self.projchoice.Append(name, [clazz, None]) |
|
539 |
|
|
540 |
def __set_properties(self): |
def __set_properties(self): |
|
self.__FillAvailList() |
|
541 |
|
|
542 |
# begin wxGlade: ProjFrame.__set_properties |
#self.availprojs.SetSelection(0) |
|
self.SetTitle(_("Projections")) |
|
|
self.availprojs.SetSelection(0) |
|
543 |
self.projchoice.SetSelection(0) |
self.projchoice.SetSelection(0) |
544 |
# end wxGlade |
|
545 |
|
self.__FillAvailList(selectCurrent = True) |
546 |
|
|
547 |
self.projname.SetMaxLength(32) |
self.projname.SetMaxLength(32) |
548 |
|
|
552 |
self.topBox = wxBoxSizer(wxVERTICAL) |
self.topBox = wxBoxSizer(wxVERTICAL) |
553 |
self.sizer_panel = wxBoxSizer(wxVERTICAL) |
self.sizer_panel = wxBoxSizer(wxVERTICAL) |
554 |
sizer_6 = wxBoxSizer(wxHORIZONTAL) |
sizer_6 = wxBoxSizer(wxHORIZONTAL) |
555 |
|
self.sizer_mainbttns = wxBoxSizer(wxHORIZONTAL) |
556 |
self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL) |
self.sizer_mainctrls = wxBoxSizer(wxHORIZONTAL) |
557 |
self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL) |
self.sizer_edit = wxStaticBoxSizer(wxStaticBox(self.panel_edit, -1, _("Edit")), wxHORIZONTAL) |
558 |
sizer_11 = wxBoxSizer(wxVERTICAL) |
sizer_11 = wxBoxSizer(wxVERTICAL) |
571 |
grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0) |
grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0) |
572 |
grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4) |
grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4) |
573 |
grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4) |
grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4) |
574 |
grid_sizer_1.Add(self.projfilepath, 0, wxALL|wxADJUST_MINSIZE, 4) |
grid_sizer_1.Add(self.projfilepath, 0, wxEXPAND|wxALL|wxADJUST_MINSIZE, 4) |
575 |
grid_sizer_1.AddGrowableRow(1) |
grid_sizer_1.AddGrowableRow(1) |
576 |
grid_sizer_1.AddGrowableCol(0) |
grid_sizer_1.AddGrowableCol(0) |
577 |
|
|
580 |
sizer_13.Add(self.projname, 1, wxALL, 4) |
sizer_13.Add(self.projname, 1, wxALL, 4) |
581 |
self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0) |
self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0) |
582 |
sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
583 |
sizer_14.Add(self.projchoice, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4) |
sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
584 |
self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0) |
self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0) |
585 |
self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0) |
self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0) |
586 |
sizer_11.Add(self.button_new, 0, wxALL|wxEXPAND, 4) |
sizer_11.Add(self.button_new, 0, wxEXPAND|wxALL, 4) |
587 |
sizer_11.Add(self.button_save, 0, wxALL|wxEXPAND, 4) |
sizer_11.Add(self.button_add, 0, wxEXPAND|wxALL, 4) |
588 |
sizer_11.Add(self.button_add, 0, wxALL|wxEXPAND, 4) |
sizer_11.Add(20, 20, 0, wxEXPAND, 0) |
589 |
|
sizer_11.Add(self.button_save, 0, wxEXPAND|wxALL|wxALIGN_BOTTOM, 4) |
590 |
self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4) |
self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4) |
591 |
|
|
592 |
sizer_6.Add(20, 20, 1, wxEXPAND, 0) |
sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10) |
593 |
sizer_6.Add(self.button_try, 0, wxALL, 4) |
sizer_6.Add(self.button_revert, 0, wxRIGHT| wxEXPAND, 10) |
594 |
sizer_6.Add(20, 20, 1, 0, 0) |
sizer_6.Add(self.button_ok, 0, wxRIGHT| wxEXPAND, 10) |
595 |
sizer_6.Add(self.button_revert, 0, wxALL, 4) |
sizer_6.Add(self.button_close, 0, wxRIGHT| wxEXPAND, 10) |
|
sizer_6.Add(20, 20, 1, 0, 0) |
|
|
sizer_6.Add(self.button_ok, 0, wxALL, 4) |
|
|
sizer_6.Add(20, 20, 1, 0, 0) |
|
|
sizer_6.Add(self.button_close, 0, wxALL, 4) |
|
|
sizer_6.Add(20, 20, 1, wxEXPAND, 0) |
|
596 |
|
|
597 |
self.panel_1.SetAutoLayout(1) |
self.panel_1.SetAutoLayout(1) |
598 |
self.panel_1.SetSizer(grid_sizer_1) |
self.panel_1.SetSizer(grid_sizer_1) |
604 |
self.sizer_edit.Fit(self.panel_edit) |
self.sizer_edit.Fit(self.panel_edit) |
605 |
self.sizer_edit.SetSizeHints(self.panel_edit) |
self.sizer_edit.SetSizeHints(self.panel_edit) |
606 |
|
|
|
self.panel_buttons.SetAutoLayout(1) |
|
|
self.panel_buttons.SetSizer(sizer_6) |
|
|
sizer_6.Fit(self.panel_buttons) |
|
|
sizer_6.SetSizeHints(self.panel_buttons) |
|
|
|
|
607 |
self.sizer_mainctrls.Add(self.panel_1, 0, |
self.sizer_mainctrls.Add(self.panel_1, 0, |
608 |
wxALL|wxEXPAND|wxADJUST_MINSIZE, 0) |
wxALL|wxEXPAND|wxADJUST_MINSIZE, 0) |
609 |
self.sizer_mainctrls.Add(self.panel_edit, 1, |
self.sizer_mainctrls.Add(self.panel_edit, 1, |
610 |
wxALL|wxEXPAND|wxADJUST_MINSIZE, 0) |
wxALL|wxEXPAND|wxADJUST_MINSIZE, 0) |
611 |
|
|
612 |
|
self.sizer_mainbttns.Add(sizer_6, 0, |
613 |
|
wxALL|wxEXPAND|wxADJUST_MINSIZE, 10) |
614 |
|
|
615 |
self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4) |
self.topBox.Add(self.sizer_mainctrls, 1, wxALL|wxEXPAND, 4) |
616 |
self.topBox.Add(self.panel_buttons, 0, wxEXPAND, 0) |
self.topBox.Add(self.sizer_mainbttns, 0, wxALIGN_RIGHT|wxBOTTOM, 0) |
617 |
|
|
618 |
self.SetAutoLayout(1) |
self.SetAutoLayout(1) |
619 |
self.SetSizer(self.topBox) |
self.SetSizer(self.topBox) |
631 |
wxPanel.__init__(self, parent, -1) |
wxPanel.__init__(self, parent, -1) |
632 |
|
|
633 |
self.__ellps = wxChoice(self, -1) |
self.__ellps = wxChoice(self, -1) |
634 |
self.ellpsData = [("bessel", _("Bessel 1841")), |
self.ellpsData = [("airy" , _("Airy")), |
635 |
|
("bessel", _("Bessel 1841")), |
636 |
("clrk66", _("Clarke 1866")), |
("clrk66", _("Clarke 1866")), |
637 |
("clrk80", _("Clarke 1880")), |
("clrk80", _("Clarke 1880")), |
638 |
("GRS80" , _("GRS 1980 (IUGG, 1980)")), |
("GRS80" , _("GRS 1980 (IUGG, 1980)")), |
648 |
|
|
649 |
panelSizer = wxBoxSizer(wxVERTICAL) |
panelSizer = wxBoxSizer(wxVERTICAL) |
650 |
|
|
|
if childPanel is not None: |
|
|
panelSizer.Add(childPanel, 0, wxALL|wxEXPAND, 4) |
|
|
|
|
651 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wxBoxSizer(wxHORIZONTAL) |
652 |
sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, wxALL, 4) |
sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, |
653 |
sizer.Add(self.__ellps, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4) |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
654 |
|
sizer.Add(self.__ellps, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
655 |
panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4) |
panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4) |
656 |
|
|
657 |
|
if childPanel is not None: |
658 |
|
panelSizer.Add(childPanel, 0, wxEXPAND, 0) |
659 |
|
|
660 |
self.SetAutoLayout(1) |
self.SetAutoLayout(1) |
661 |
self.SetSizer(panelSizer) |
self.SetSizer(panelSizer) |
662 |
panelSizer.Fit(self) |
panelSizer.Fit(self) |
698 |
def _DoLayout(self): |
def _DoLayout(self): |
699 |
sizer = wxBoxSizer(wxVERTICAL) |
sizer = wxBoxSizer(wxVERTICAL) |
700 |
|
|
701 |
sizer.Add(wxStaticText(self, -1, |
sizer.Add(wxStaticText(self, -1, |
702 |
_("Thuban does not know the parameters for the " + |
_("Thuban does not know the parameters for the" |
703 |
"current projection and cannot display a " + |
" current projection and cannot display a" |
704 |
"configuration panel."))) |
" configuration panel."))) |
705 |
|
|
706 |
ProjPanel._DoLayout(self, sizer) |
ProjPanel._DoLayout(self, sizer) |
707 |
|
|
722 |
|
|
723 |
self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT) |
self.__latitude = wxTextCtrl(self, ID_TMPANEL_LAT) |
724 |
self.__longitude = wxTextCtrl(self, ID_TMPANEL_LONG) |
self.__longitude = wxTextCtrl(self, ID_TMPANEL_LONG) |
725 |
|
self.__scale = wxTextCtrl(self, ID_TMPANEL_SCALE) |
726 |
self.__falseEast = wxTextCtrl(self, ID_TMPANEL_FASLE_EAST) |
self.__falseEast = wxTextCtrl(self, ID_TMPANEL_FASLE_EAST) |
727 |
self.__falseNorth = wxTextCtrl(self, ID_TMPANEL_FALSE_NORTH) |
self.__falseNorth = wxTextCtrl(self, ID_TMPANEL_FALSE_NORTH) |
|
self.__scale = wxTextCtrl(self, ID_TMPANEL_SCALE) |
|
728 |
|
|
729 |
self._DoLayout() |
self._DoLayout() |
730 |
|
|
790 |
self.receiver = receiver |
self.receiver = receiver |
791 |
|
|
792 |
self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60) |
self.__zone = wxSpinCtrl(self, ID_UTMPANEL_ZONE, "1", min=1, max=60) |
793 |
|
self.__propButton = wxButton(self, ID_UTMPANEL_PROP, _("Propose")) |
794 |
self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH, |
self.__south = wxCheckBox(self, ID_UTMPANEL_SOUTH, |
795 |
_("Southern Hemisphere")) |
_("Southern Hemisphere")) |
|
self.__propButton = wxButton(self, ID_UTMPANEL_PROP, _("Propose")) |
|
796 |
|
|
797 |
self._DoLayout() |
self._DoLayout() |
798 |
|
|
832 |
ProjPanel.Clear(self) |
ProjPanel.Clear(self) |
833 |
|
|
834 |
def _OnPropose(self, event): |
def _OnPropose(self, event): |
835 |
UTMProposeZoneDialog |
"""Call the propose dialog. |
836 |
|
If the receiver (e.g. the current map) has no bounding box, |
837 |
|
inform the user accordingly. |
838 |
|
""" |
839 |
|
bb = self.receiver.BoundingBox() |
840 |
|
if bb is None: |
841 |
|
dlg = wxMessageDialog(self, |
842 |
|
_("Can not propose: No bounding box found."), |
843 |
|
_("Projection: Propose UTM Zone"), |
844 |
|
wxOK | wxICON_INFORMATION) |
845 |
|
dlg.CenterOnParent() |
846 |
|
result = dlg.ShowModal() |
847 |
|
dlg.Destroy() |
848 |
|
return |
849 |
|
|
850 |
dlg = UTMProposeZoneDialog(self, self.receiver.BoundingBox()) |
dlg = UTMProposeZoneDialog(self, self.receiver.BoundingBox()) |
851 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
852 |
self.__zone.SetValue(dlg.GetProposedZone()) |
self.__zone.SetValue(dlg.GetProposedZone()) |
875 |
sizer.Add(wxStaticText(self, -1, |
sizer.Add(wxStaticText(self, -1, |
876 |
_("Latitude of second standard parallel:"))) |
_("Latitude of second standard parallel:"))) |
877 |
sizer.Add(self.__sspLatitude, 0, wxALL, 4) |
sizer.Add(self.__sspLatitude, 0, wxALL, 4) |
|
sizer.Add(wxStaticText(self, -1, _("Latitude of origin:"))) |
|
|
sizer.Add(self.__originLat, 0, wxALL, 4) |
|
878 |
sizer.Add(wxStaticText(self, -1, _("Central Meridian:"))) |
sizer.Add(wxStaticText(self, -1, _("Central Meridian:"))) |
879 |
sizer.Add(self.__meridian, 0, wxALL, 4) |
sizer.Add(self.__meridian, 0, wxALL, 4) |
880 |
|
sizer.Add(wxStaticText(self, -1, _("Latitude of origin:"))) |
881 |
|
sizer.Add(self.__originLat, 0, wxALL, 4) |
882 |
sizer.Add(wxStaticText(self, -1, _("False Easting:"))) |
sizer.Add(wxStaticText(self, -1, _("False Easting:"))) |
883 |
sizer.Add(self.__falseEast, 0, wxALL, 4) |
sizer.Add(self.__falseEast, 0, wxALL, 4) |
884 |
sizer.Add(wxStaticText(self, -1, _("False Northing:"))) |
sizer.Add(wxStaticText(self, -1, _("False Northing:"))) |
926 |
|
|
927 |
def __init__(self, parent, receiver): |
def __init__(self, parent, receiver): |
928 |
ProjPanel.__init__(self, parent) |
ProjPanel.__init__(self, parent) |
929 |
ProjPanel._DoLayout(self, None) |
|
930 |
|
self.__choices = [(_("Degrees"), "0.017453"), |
931 |
|
(_("Radians"), "1")] |
932 |
|
|
933 |
|
self.__scale = wxChoice(self, -1) |
934 |
|
for choice, value in self.__choices: |
935 |
|
self.__scale.Append(choice, value) |
936 |
|
|
937 |
|
self._DoLayout() |
938 |
|
|
939 |
def GetProjName(self): |
def GetProjName(self): |
940 |
return _("Geographic") |
return _("Geographic") |
941 |
|
|
942 |
def SetProjection(self, proj): |
def SetProjection(self, proj): |
943 |
|
value = proj.GetParameter("to_meter") |
944 |
|
for i in range(len(self.__choices)): |
945 |
|
choice, data = self.__choices[i] |
946 |
|
if value == data: |
947 |
|
self.__scale.SetSelection(i) |
948 |
ProjPanel.SetProjection(self, proj) |
ProjPanel.SetProjection(self, proj) |
949 |
|
|
950 |
def GetParameters(self): |
def GetParameters(self): |
951 |
params = ["proj=latlong"] |
params = ["proj=latlong", |
952 |
|
"to_meter=%s" % self.__scale.GetClientData( |
953 |
|
self.__scale.GetSelection())] |
954 |
|
|
955 |
params.extend(ProjPanel.GetParameters(self)) |
params.extend(ProjPanel.GetParameters(self)) |
956 |
return params |
return params |
957 |
|
|
958 |
def Clear(self): |
def Clear(self): |
959 |
ProjPanel.Clear(self) |
ProjPanel.Clear(self) |
960 |
|
|
961 |
|
def _DoLayout(self): |
962 |
|
sizer = wxBoxSizer(wxHORIZONTAL) |
963 |
|
|
964 |
|
sizer.Add(wxStaticText(self, -1, _("Source Data is in: ")), |
965 |
|
0, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
966 |
|
sizer.Add(self.__scale, 1, wxEXPAND|wxALL, 4) |
967 |
|
|
968 |
|
self.__scale.SetSelection(0) |
969 |
|
|
970 |
|
ProjPanel._DoLayout(self, sizer) |
971 |
|
|
972 |
|
|
973 |
ID_UTM_PROPOSE_ZONE_DIALOG_TAKE = 4001 |
ID_UTM_PROPOSE_ZONE_DIALOG_TAKE = 4001 |
974 |
ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002 |
ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002 |
975 |
class UTMProposeZoneDialog(wxDialog): |
class UTMProposeZoneDialog(wxDialog): |
976 |
|
|
977 |
"""Propose a sensible Zone considering the current map extent.""" |
"""Propose a sensible Zone considering the current map extent.""" |
978 |
|
|
979 |
def __init__(self, parent, (x, y, x2, y2)): |
def __init__(self, parent, (x, y, x2, y2)): |
980 |
wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"), |
wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"), |
981 |
wxDefaultPosition, wxSize(200, 100)) |
wxDefaultPosition, wxSize(200, 100)) |
982 |
self.parent = parent |
self.parent = parent |
|
#x, y, x2, y2 = elf.parent.parent.map_bounding_box |
|
983 |
x = x + 180 |
x = x + 180 |
984 |
x2 = x2 + 180 |
x2 = x2 + 180 |
985 |
center = (x2 - x) / 2 + x |
center = (x2 - x) / 2 + x |
986 |
self.proposedZone = int(center / 6 + 1) |
self.proposedZone = int(center / 6 + 1) |
987 |
self.dialogLayout() |
self.dialogLayout() |
988 |
|
|
989 |
def dialogLayout(self): |
def dialogLayout(self): |
990 |
topBox = wxBoxSizer(wxVERTICAL) |
topBox = wxBoxSizer(wxVERTICAL) |
991 |
|
|
992 |
textBox = wxBoxSizer(wxVERTICAL) |
textBox = wxBoxSizer(wxVERTICAL) |
993 |
textBox.Add(wxStaticText(self, -1, _("The current map extent center " + |
textBox.Add(wxStaticText(self, -1, _("The current map extent center " |
994 |
"lies in UTM Zone")), |
"lies in UTM Zone")), |
995 |
0, wxALIGN_CENTER|wxALL, 4) |
0, wxALIGN_CENTER|wxALL, 4) |
996 |
textBox.Add(wxStaticText(self, -1, str(self.proposedZone)), |
textBox.Add(wxStaticText(self, -1, str(self.proposedZone)), |
997 |
0, wxALIGN_CENTER|wxALL, 4) |
0, wxALIGN_CENTER|wxALL, 4) |
998 |
|
|
999 |
topBox.Add(textBox, 1, wxEXPAND|wxALL, 4) |
topBox.Add(textBox, 1, wxEXPAND|wxALL, 4) |
1000 |
|
|
1001 |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
1002 |
buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, |
buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, |
1003 |
_("Take")), 0, wxALL, 4) |
_("Take")), 0, wxALL, 4) |
1006 |
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10) |
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10) |
1007 |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake) |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake) |
1008 |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel) |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel) |
1009 |
|
|
1010 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
1011 |
self.SetSizer(topBox) |
self.SetSizer(topBox) |
1012 |
topBox.Fit(self) |
topBox.Fit(self) |
1013 |
topBox.SetSizeHints(self) |
topBox.SetSizeHints(self) |
1014 |
|
|
1015 |
def OnTake(self, event): |
def OnTake(self, event): |
1016 |
self.EndModal(wxID_OK) |
self.EndModal(wxID_OK) |
1017 |
|
|
1018 |
def OnCancel(self, event): |
def OnCancel(self, event): |
1019 |
self.EndModal(wxID_CANCEL) |
self.EndModal(wxID_CANCEL) |
1020 |
|
|