5 |
# |
# |
6 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
7 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
8 |
|
|
9 |
|
"""Projection dialog""" |
10 |
|
|
11 |
|
__version__ = "$Revision$" |
12 |
|
# $Source$ |
13 |
|
# $Id$ |
14 |
|
|
15 |
import os, sys, math |
import os, sys, math |
16 |
from wxPython.wx import * |
from wxPython.wx import * |
17 |
|
|
19 |
|
|
20 |
from Thuban.Model.proj import Projection, ProjFile |
from Thuban.Model.proj import Projection, ProjFile |
21 |
|
|
22 |
from Thuban.Model.resource import GetUserProjFiles, GetSystemProjFiles, \ |
from Thuban.Model.resource import get_user_proj_files, get_system_proj_files, \ |
23 |
ReadProjFile, WriteProjFile |
read_proj_file, write_proj_file |
24 |
from Thuban.UI.dialogs import NonModalDialog |
from Thuban.UI.dialogs import NonModalNonParentDialog |
25 |
|
|
26 |
|
|
27 |
ID_PROJ_ADVANCED = 4001 |
ID_PROJ_ADVANCED = 4001 |
39 |
CLIENT_PROJ = 0 |
CLIENT_PROJ = 0 |
40 |
CLIENT_PROJFILE = 1 |
CLIENT_PROJFILE = 1 |
41 |
|
|
42 |
class ProjFrame(NonModalDialog): |
class ProjFrame(NonModalNonParentDialog): |
43 |
|
|
44 |
def __init__(self, parent, name, title, receiver): |
def __init__(self, parent, name, title, receiver): |
45 |
"""Initialize the projection dialog. |
"""Initialize the projection dialog. |
63 |
self.projPanels.append( |
self.projPanels.append( |
64 |
("latlong", _("Geographic"), GeoPanel)) |
("latlong", _("Geographic"), GeoPanel)) |
65 |
|
|
66 |
NonModalDialog.__init__(self, parent, name, title) |
NonModalNonParentDialog.__init__(self, parent, name, title) |
67 |
# originally generate by wxGlade |
# originally generate by wxGlade |
68 |
self.panel_1 = wxPanel(self, -1) |
self.panel_1 = wxPanel(self, -1) |
69 |
self.panel_edit = wxPanel(self, -1) |
self.panel_edit = wxPanel(self, -1) |
106 |
|
|
107 |
self.__set_properties() |
self.__set_properties() |
108 |
self.__do_layout() |
self.__do_layout() |
109 |
|
|
110 |
# wxGlade |
# wxGlade |
111 |
|
|
112 |
|
# Fill the projection choice list. |
113 |
|
for proj, name, clazz in self.projPanels: |
114 |
|
self.projchoice.Append(name, [clazz, None]) |
115 |
|
|
116 |
self.originalProjection = self.receiver.GetProjection() |
self.originalProjection = self.receiver.GetProjection() |
117 |
|
|
118 |
self.__DoOnProjAvail() |
self.__DoOnProjAvail() |
135 |
|
|
136 |
EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName) |
EVT_TEXT(self, ID_PROJ_PROJNAME, self._OnProjName) |
137 |
|
|
|
|
|
138 |
def OnApply(self, event): |
def OnApply(self, event): |
139 |
self.__SetProjection() |
self.__SetProjection() |
140 |
self.haveTried = True |
self.haveTried = True |
154 |
self.receiver.SetProjection(self.originalProjection) |
self.receiver.SetProjection(self.originalProjection) |
155 |
self.haveTried = False |
self.haveTried = False |
156 |
|
|
|
|
|
157 |
def _OnNew(self, event): |
def _OnNew(self, event): |
158 |
|
|
159 |
# clear all selections |
# clear all selections |
184 |
if newproj is not None: |
if newproj is not None: |
185 |
projfile.Replace(proj, newproj) |
projfile.Replace(proj, newproj) |
186 |
try: |
try: |
187 |
WriteProjFile(projfile) |
write_proj_file(projfile) |
188 |
except IOError, (errno, errstr): |
except IOError, (errno, errstr): |
189 |
self.__ShowError(projfile.GetFilename(), errstr) |
self.__ShowError(projfile.GetFilename(), errstr) |
190 |
self.availprojs.SetClientData(sel[0], [newproj, projfile]) |
self.availprojs.SetClientData(sel[0], [newproj, projfile]) |
191 |
|
|
192 |
|
self.__FillAvailList( selectProj = newproj.GetName()) |
193 |
|
|
194 |
def _OnAddToList(self, event): |
def _OnAddToList(self, event): |
195 |
|
|
196 |
proj = self.__GetProjection() |
proj = self.__GetProjection() |
197 |
if proj is not None: |
if proj is not None: |
198 |
self.__usrProjFile.Add(proj) |
self.__usrProjFile.Add(proj) |
199 |
try: |
try: |
200 |
WriteProjFile(self.__usrProjFile) |
write_proj_file(self.__usrProjFile) |
201 |
except IOError, (errno, errstr): |
except IOError, (errno, errstr): |
202 |
self.__ShowError(self.__userProjFile.GetFilename(), errstr) |
self.__ShowError(self.__userProjFile.GetFilename(), errstr) |
203 |
|
|
204 |
self.__FillAvailList() |
self.__FillAvailList( selectProj = proj.GetName()) |
205 |
|
|
206 |
def _OnProjAvail(self, event): |
def _OnProjAvail(self, event): |
207 |
self.__DoOnProjAvail() |
self.__DoOnProjAvail() |
214 |
path = dlg.GetPath() |
path = dlg.GetPath() |
215 |
|
|
216 |
try: |
try: |
217 |
projFile = ReadProjFile(path) |
projFile = read_proj_file(path) |
218 |
for proj in projFile.GetProjections(): |
for proj in projFile.GetProjections(): |
219 |
self.__usrProjFile.Add(proj) |
self.__usrProjFile.Add(proj) |
220 |
WriteProjFile(self.__usrProjFile) |
write_proj_file(self.__usrProjFile) |
221 |
except IOError, (errno, errstr): |
except IOError, (errno, errstr): |
222 |
self.__ShowError(dlg.GetPath(), errstr) |
self.__ShowError(dlg.GetPath(), errstr) |
223 |
|
|
244 |
projFile.Add(proj) |
projFile.Add(proj) |
245 |
|
|
246 |
try: |
try: |
247 |
WriteProjFile(projFile) |
write_proj_file(projFile) |
248 |
except IOError, (errno, errstr): |
except IOError, (errno, errstr): |
249 |
self.__ShowError(dlg.GetPath(), errstr) |
self.__ShowError(dlg.GetPath(), errstr) |
250 |
|
|
279 |
projfile.Remove(proj) |
projfile.Remove(proj) |
280 |
|
|
281 |
try: |
try: |
282 |
WriteProjFile(projfile) |
write_proj_file(projfile) |
283 |
except IOError, (errno, errstr): |
except IOError, (errno, errstr): |
284 |
self.__ShowError(projfile.GetFilename(), errstr) |
self.__ShowError(projfile.GetFilename(), errstr) |
285 |
|
|
377 |
if proj is None: |
if proj is None: |
378 |
# user selected <None> |
# user selected <None> |
379 |
self.projname.Clear() |
self.projname.Clear() |
380 |
|
self.projfilepath.SetLabel(_("Projection File: ")) |
381 |
else: |
else: |
382 |
|
|
383 |
if projfile is not None: |
if projfile is not None: |
384 |
self.projfilepath.SetLabel(projfile.GetFilename()) |
self.projfilepath.SetLabel(_("Projection File: ") + |
385 |
|
os.path.basename(projfile.GetFilename())) |
386 |
else: |
else: |
387 |
# only None if the currently used projection is selected |
# only None if the currently used projection is selected |
388 |
self.projfilepath.SetLabel("") |
self.projfilepath.SetLabel(_("Projection File: ")) |
389 |
|
|
390 |
self.projname.SetValue(proj.GetName()) |
self.projname.SetValue(proj.GetName()) |
391 |
|
|
481 |
|
|
482 |
return None |
return None |
483 |
|
|
484 |
def __FillAvailList(self, selectCurrent = False): |
def __FillAvailList(self, selectCurrent = False, selectProj = None): |
485 |
"""Populate the list of available projections. |
"""Populate the list of available projections. |
486 |
|
|
487 |
selectCurrent -- if True, select the projection used by |
selectCurrent -- if True, select the projection used by |
488 |
the receiver, otherwise select nothing. |
the receiver, otherwise select nothing. |
489 |
|
selectProj -- if set, select the projection found under the |
490 |
|
specified name. This overwrites any other |
491 |
|
selection estimate. |
492 |
""" |
""" |
493 |
|
|
494 |
self.availprojs.Clear() |
self.availprojs.Clear() |
499 |
# |
# |
500 |
self.availprojs.Append("<None>", (None, None)) |
self.availprojs.Append("<None>", (None, None)) |
501 |
|
|
502 |
projfile = GetSystemProjFiles() |
projfile = get_system_proj_files() |
503 |
projfile = projfile[0] |
projfile = projfile[0] |
504 |
for proj in projfile.GetProjections(): |
for proj in projfile.GetProjections(): |
505 |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
506 |
self.__sysProjFile = projfile |
self.__sysProjFile = projfile |
507 |
|
|
508 |
projfile = GetUserProjFiles() |
projfile = get_user_proj_files() |
509 |
projfile = projfile[0] |
projfile = projfile[0] |
510 |
for proj in projfile.GetProjections(): |
for proj in projfile.GetProjections(): |
511 |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
512 |
self.__usrProjFile = projfile |
self.__usrProjFile = projfile |
513 |
|
|
|
for proj, name, clazz in self.projPanels: |
|
|
self.projchoice.Append(name, [clazz, None]) |
|
|
|
|
514 |
# |
# |
515 |
# We add the current projection to the list at last. |
# We add the current projection to the list at last. |
516 |
# Since the list is resorted immediately a following FindString() |
# Since the list is resorted immediately a following FindString() |
529 |
self.availprojs.SetSelection( |
self.availprojs.SetSelection( |
530 |
self.availprojs.FindString("<None>") |
self.availprojs.FindString("<None>") |
531 |
) |
) |
532 |
|
if selectProj: |
533 |
|
self.availprojs.SetSelection( |
534 |
|
self.availprojs.FindString(selectProj) |
535 |
|
) |
536 |
|
|
537 |
|
|
538 |
|
|
539 |
def __set_properties(self): |
def __set_properties(self): |
570 |
grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0) |
grid_sizer_1.Add(20, 20, 0, wxEXPAND, 0) |
571 |
grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4) |
grid_sizer_1.Add(self.availprojs, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4) |
572 |
grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4) |
grid_sizer_1.Add(sizer_15, 0, wxALL|wxEXPAND, 4) |
573 |
grid_sizer_1.Add(self.projfilepath, 0, wxALL|wxADJUST_MINSIZE, 4) |
grid_sizer_1.Add(self.projfilepath, 0, wxEXPAND|wxALL|wxADJUST_MINSIZE, 4) |
574 |
grid_sizer_1.AddGrowableRow(1) |
grid_sizer_1.AddGrowableRow(1) |
575 |
grid_sizer_1.AddGrowableCol(0) |
grid_sizer_1.AddGrowableCol(0) |
576 |
|
|
579 |
sizer_13.Add(self.projname, 1, wxALL, 4) |
sizer_13.Add(self.projname, 1, wxALL, 4) |
580 |
self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0) |
self.sizer_projctrls.Add(sizer_13, 0, wxEXPAND, 0) |
581 |
sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
sizer_14.Add(self.label_3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
582 |
sizer_14.Add(self.projchoice, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4) |
sizer_14.Add(self.projchoice, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
583 |
self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0) |
self.sizer_projctrls.Add(sizer_14, 0, wxEXPAND, 0) |
584 |
self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0) |
self.sizer_edit.Add(self.sizer_projctrls, 1, wxEXPAND, 0) |
585 |
sizer_11.Add(self.button_new, 0, wxALL, 4) |
sizer_11.Add(self.button_new, 0, wxEXPAND|wxALL, 4) |
586 |
sizer_11.Add(self.button_add, 0, wxALL, 4) |
sizer_11.Add(self.button_add, 0, wxEXPAND|wxALL, 4) |
587 |
sizer_11.Add(20, 20, 0, wxEXPAND, 0) |
sizer_11.Add(20, 20, 0, wxEXPAND, 0) |
588 |
sizer_11.Add(self.button_save, 0, wxALL|wxALIGN_BOTTOM, 4) |
sizer_11.Add(self.button_save, 0, wxEXPAND|wxALL|wxALIGN_BOTTOM, 4) |
589 |
self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4) |
self.sizer_edit.Add(sizer_11, 0, wxALL|wxEXPAND, 4) |
590 |
|
|
591 |
sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10) |
sizer_6.Add(self.button_try, 0, wxRIGHT| wxEXPAND, 10) |
650 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wxBoxSizer(wxHORIZONTAL) |
651 |
sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, |
sizer.Add(wxStaticText(self, -1, _("Ellipsoid:")), 0, |
652 |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
wxALL|wxALIGN_CENTER_VERTICAL, 4) |
653 |
sizer.Add(self.__ellps, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4) |
sizer.Add(self.__ellps, 1, wxALL|wxALIGN_CENTER_VERTICAL, 4) |
654 |
panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4) |
panelSizer.Add(sizer, 0, wxALL|wxEXPAND, 4) |
655 |
|
|
656 |
if childPanel is not None: |
if childPanel is not None: |
860 |
sizer.Add(wxStaticText(self, -1, |
sizer.Add(wxStaticText(self, -1, |
861 |
_("Latitude of second standard parallel:"))) |
_("Latitude of second standard parallel:"))) |
862 |
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) |
|
863 |
sizer.Add(wxStaticText(self, -1, _("Central Meridian:"))) |
sizer.Add(wxStaticText(self, -1, _("Central Meridian:"))) |
864 |
sizer.Add(self.__meridian, 0, wxALL, 4) |
sizer.Add(self.__meridian, 0, wxALL, 4) |
865 |
|
sizer.Add(wxStaticText(self, -1, _("Latitude of origin:"))) |
866 |
|
sizer.Add(self.__originLat, 0, wxALL, 4) |
867 |
sizer.Add(wxStaticText(self, -1, _("False Easting:"))) |
sizer.Add(wxStaticText(self, -1, _("False Easting:"))) |
868 |
sizer.Add(self.__falseEast, 0, wxALL, 4) |
sizer.Add(self.__falseEast, 0, wxALL, 4) |
869 |
sizer.Add(wxStaticText(self, -1, _("False Northing:"))) |
sizer.Add(wxStaticText(self, -1, _("False Northing:"))) |