13 |
# $Source$ |
# $Source$ |
14 |
# $Id$ |
# $Id$ |
15 |
|
|
16 |
import os, sys, math |
import os |
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 get_user_proj_files, get_system_proj_files, \ |
from Thuban.Model.resource import get_user_proj_file, get_system_proj_file, \ |
24 |
read_proj_file, write_proj_file |
read_proj_file, write_proj_file |
25 |
from Thuban.UI.dialogs import NonModalNonParentDialog |
from Thuban.UI.dialogs import NonModalNonParentDialog |
26 |
|
|
207 |
def _OnProjAvail(self, event): |
def _OnProjAvail(self, event): |
208 |
self.__DoOnProjAvail() |
self.__DoOnProjAvail() |
209 |
|
|
210 |
|
def show_warnings(self, title, filename, warnings): |
211 |
|
"""Show the warnings (a list of strings) in a dialog |
212 |
|
|
213 |
|
If the list is empty no dialog will be shown. |
214 |
|
""" |
215 |
|
if warnings: |
216 |
|
text = (_('Warnings when reading "%s":\n\n%s') |
217 |
|
% (filename, "\n\n".join(warnings))) |
218 |
|
self.parent.RunMessageBox(title, text) |
219 |
|
|
220 |
def _OnImport(self, event): |
def _OnImport(self, event): |
221 |
|
|
222 |
dlg = wxFileDialog(self, _("Import"), style = wxOPEN) |
dlg = wxFileDialog(self, _("Import"), style = wxOPEN) |
225 |
path = dlg.GetPath() |
path = dlg.GetPath() |
226 |
|
|
227 |
try: |
try: |
228 |
projFile = read_proj_file(path) |
projFile, warnings = read_proj_file(path) |
229 |
|
self.show_warnings(_("Warnings"), path, warnings) |
230 |
for proj in projFile.GetProjections(): |
for proj in projFile.GetProjections(): |
231 |
self.__usrProjFile.Add(proj) |
self.__usrProjFile.Add(proj) |
232 |
write_proj_file(self.__usrProjFile) |
write_proj_file(self.__usrProjFile) |
405 |
i = 0 |
i = 0 |
406 |
for projType, name, clazz in self.projPanels: |
for projType, name, clazz in self.projPanels: |
407 |
if myProjType == projType: |
if myProjType == projType: |
408 |
|
self.projchoice.Enable(True) |
409 |
self.projchoice.SetSelection(i) |
self.projchoice.SetSelection(i) |
410 |
self.__DoOnProjChoice() |
self.__DoOnProjChoice() |
411 |
|
|
416 |
assert self.curProjPanel is not None |
assert self.curProjPanel is not None |
417 |
|
|
418 |
self.curProjPanel.SetProjection(proj) |
self.curProjPanel.SetProjection(proj) |
419 |
|
break |
420 |
i += 1 |
i += 1 |
421 |
|
else: |
422 |
|
self.projchoice.Disable() |
423 |
|
self._show_proj_panel(UnknownProjPanel(self.panel_edit, |
424 |
|
self.receiver)) |
425 |
|
|
426 |
self.__VerifyButtons() |
self.__VerifyButtons() |
427 |
|
|
443 |
|
|
444 |
sel = choice.GetSelection() |
sel = choice.GetSelection() |
445 |
if sel != -1: |
if sel != -1: |
|
|
|
446 |
clazz, obj = choice.GetClientData(sel) |
clazz, obj = choice.GetClientData(sel) |
|
|
|
447 |
if obj is None: |
if obj is None: |
448 |
obj = clazz(self.panel_edit, self.receiver) |
obj = clazz(self.panel_edit, self.receiver) |
449 |
choice.SetClientData(sel, [clazz, obj]) |
choice.SetClientData(sel, [clazz, obj]) |
450 |
|
self._show_proj_panel(obj) |
451 |
|
|
452 |
if self.curProjPanel is not None: |
def _show_proj_panel(self, panel): |
453 |
self.curProjPanel.Hide() |
"""Show the panel as the projection panel""" |
454 |
self.sizer_projctrls.Remove(self.curProjPanel) |
if self.curProjPanel is not None: |
455 |
|
self.curProjPanel.Hide() |
456 |
self.curProjPanel = obj |
self.sizer_projctrls.Remove(self.curProjPanel) |
457 |
self.curProjPanel.Show() |
|
458 |
|
self.curProjPanel = panel |
459 |
self.sizer_projctrls.Add(self.curProjPanel, 1, |
self.curProjPanel.Show() |
460 |
wxALL|wxEXPAND|wxADJUST_MINSIZE, 3) |
|
461 |
self.sizer_projctrls.Layout() |
self.sizer_projctrls.Add(self.curProjPanel, 1, |
462 |
self.Layout() |
wxALL|wxEXPAND|wxADJUST_MINSIZE, 3) |
463 |
self.topBox.SetSizeHints(self) |
self.sizer_projctrls.Layout() |
464 |
|
self.Layout() |
465 |
|
self.topBox.SetSizeHints(self) |
466 |
|
|
467 |
def __SetProjection(self): |
def __SetProjection(self): |
468 |
"""Set the receiver's projection.""" |
"""Set the receiver's projection.""" |
518 |
# |
# |
519 |
self.availprojs.Append("<None>", (None, None)) |
self.availprojs.Append("<None>", (None, None)) |
520 |
|
|
521 |
projfile = get_system_proj_files() |
projfile, warnings = get_system_proj_file() |
522 |
projfile = projfile[0] |
self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings) |
523 |
for proj in projfile.GetProjections(): |
for proj in projfile.GetProjections(): |
524 |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
525 |
self.__sysProjFile = projfile |
self.__sysProjFile = projfile |
526 |
|
|
527 |
projfile = get_user_proj_files() |
projfile, warnings = get_user_proj_file() |
528 |
projfile = projfile[0] |
self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings) |
529 |
for proj in projfile.GetProjections(): |
for proj in projfile.GetProjections(): |
530 |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
531 |
self.__usrProjFile = projfile |
self.__usrProjFile = projfile |
708 |
ID_TMPANEL_SCALE = 4005 |
ID_TMPANEL_SCALE = 4005 |
709 |
|
|
710 |
class UnknownProjPanel(ProjPanel): |
class UnknownProjPanel(ProjPanel): |
711 |
|
|
712 |
|
"""Panel for unknown projection types""" |
713 |
|
|
714 |
def __init__(self, parent, receiver): |
def __init__(self, parent, receiver): |
715 |
ProjPanel.__init__(self, parent) |
ProjPanel.__init__(self, parent) |
716 |
|
|
719 |
def _DoLayout(self): |
def _DoLayout(self): |
720 |
sizer = wxBoxSizer(wxVERTICAL) |
sizer = wxBoxSizer(wxVERTICAL) |
721 |
|
|
722 |
sizer.Add(wxStaticText(self, -1, |
sizer.Add(wxStaticText(self, -1, |
723 |
_("Thuban does not know the parameters for the " + |
_("Thuban does not know the parameters for the" |
724 |
"current projection and cannot display a " + |
" current projection\n" |
725 |
"configuration panel."))) |
"and cannot display a configuration panel."))) |
726 |
|
|
727 |
ProjPanel._DoLayout(self, sizer) |
ProjPanel._DoLayout(self, sizer) |
728 |
|
|
994 |
ID_UTM_PROPOSE_ZONE_DIALOG_TAKE = 4001 |
ID_UTM_PROPOSE_ZONE_DIALOG_TAKE = 4001 |
995 |
ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002 |
ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002 |
996 |
class UTMProposeZoneDialog(wxDialog): |
class UTMProposeZoneDialog(wxDialog): |
997 |
|
|
998 |
"""Propose a sensible Zone considering the current map extent.""" |
"""Propose a sensible Zone considering the current map extent.""" |
999 |
|
|
1000 |
def __init__(self, parent, (x, y, x2, y2)): |
def __init__(self, parent, (x, y, x2, y2)): |
1001 |
wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"), |
wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"), |
1002 |
wxDefaultPosition, wxSize(200, 100)) |
wxDefaultPosition, wxSize(200, 100)) |
1006 |
center = (x2 - x) / 2 + x |
center = (x2 - x) / 2 + x |
1007 |
self.proposedZone = int(center / 6 + 1) |
self.proposedZone = int(center / 6 + 1) |
1008 |
self.dialogLayout() |
self.dialogLayout() |
1009 |
|
|
1010 |
def dialogLayout(self): |
def dialogLayout(self): |
1011 |
topBox = wxBoxSizer(wxVERTICAL) |
topBox = wxBoxSizer(wxVERTICAL) |
1012 |
|
|
1013 |
textBox = wxBoxSizer(wxVERTICAL) |
textBox = wxBoxSizer(wxVERTICAL) |
1014 |
textBox.Add(wxStaticText(self, -1, _("The current map extent center " + |
textBox.Add(wxStaticText(self, -1, _("The current map extent center " |
1015 |
"lies in UTM Zone")), |
"lies in UTM Zone")), |
1016 |
0, wxALIGN_CENTER|wxALL, 4) |
0, wxALIGN_CENTER|wxALL, 4) |
1017 |
textBox.Add(wxStaticText(self, -1, str(self.proposedZone)), |
textBox.Add(wxStaticText(self, -1, str(self.proposedZone)), |
1018 |
0, wxALIGN_CENTER|wxALL, 4) |
0, wxALIGN_CENTER|wxALL, 4) |
1019 |
|
|
1020 |
topBox.Add(textBox, 1, wxEXPAND|wxALL, 4) |
topBox.Add(textBox, 1, wxEXPAND|wxALL, 4) |
1021 |
|
|
1022 |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
1023 |
buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, |
buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, |
1024 |
_("Take")), 0, wxALL, 4) |
_("Take")), 0, wxALL, 4) |
1027 |
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10) |
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10) |
1028 |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake) |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake) |
1029 |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel) |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel) |
1030 |
|
|
1031 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
1032 |
self.SetSizer(topBox) |
self.SetSizer(topBox) |
1033 |
topBox.Fit(self) |
topBox.Fit(self) |
1034 |
topBox.SetSizeHints(self) |
topBox.SetSizeHints(self) |
1035 |
|
|
1036 |
def OnTake(self, event): |
def OnTake(self, event): |
1037 |
self.EndModal(wxID_OK) |
self.EndModal(wxID_OK) |
1038 |
|
|
1039 |
def OnCancel(self, event): |
def OnCancel(self, event): |
1040 |
self.EndModal(wxID_CANCEL) |
self.EndModal(wxID_CANCEL) |
1041 |
|
|