import os
from wxPython.wx import *
import dislin
import string
RenderTemplate = """
Cottonwood Arizona's Rockin' B Ranch - Strangeness
"""
lat_num = 39.99583333333333
start_lat = 39.99583333333333
long_num = -139.99583333333334
start_long = -139.99583333333334
Latitude_Minimum = -10
Latitude_Maximum = 40
Longitude_Minimum = -140
Longitude_Maximum = -100
x_scale = 0.00833333333333
y_scale = 0.00833333333333
demdirectory = 'EMPTY'
RSpin = 10
USpin = 25
DSpin = 400
height_num = 1.0
width_num = 1.0
wxInitAllImageHandlers()
def get_init_data(parent):
global tom,long_num,start_long,lat_num,start_lat,x_scale,y_scale,Latitude_Minimum,Latitude_Maximum ,Longitude_Minimum,Longitude_Maximum
dir = ''
dlg = wxFileDialog(parent, "Location of DEM file", ".", "", "*.dem", wxOPEN)
if dlg.ShowModal() == wxID_OK:
dir = dlg.GetPath()
dlg.Destroy()
tom = open(dir,'rb')
head_file_name = os.path.join(os.path.split(dir)[0],os.path.splitext(os.path.split(dir)[1])[0] + '.hdr')
temp_file = open(head_file_name,'r')
temp_file.readline()
temp_file.readline()
N_ROWS = int(string.split(temp_file.readline())[1])
N_COLS = int(string.split(temp_file.readline())[1])
temp_file.readline()
temp_file.readline()
temp_file.readline()
temp_file.readline()
temp_file.readline()
temp_file.readline()
long_num = float(string.split(temp_file.readline())[1])
start_long = long_num
lat_num = float(string.split(temp_file.readline())[1])
start_lat = lat_num
x_scale = float(string.split(temp_file.readline())[1])
y_scale = float(string.split(temp_file.readline())[1])
Latitude_Minimum = lat_num - (N_ROWS * y_scale)
Latitude_Maximum = lat_num + y_scale
Longitude_Minimum = long_num - x_scale
Longitude_Maximum = long_num + (N_COLS * x_scale)
return dir
class Global_tile(wxScrolledWindow):
def __init__(self, parent, main_parent,id = -1, size = wxDefaultSize):
self.parent = main_parent
wxScrolledWindow.__init__(self, parent, id, wxPoint(0, 0), size, wxSUNKEN_BORDER)
self.lines = []
self.maxWidth = 1500
self.maxHeight = 1500
self.SetBackgroundColour(wxNamedColor("WHITE"))
EVT_MOUSE_EVENTS(self, self.OnMouseEvent)
EVT_PAINT(self,self.OnPaint)
self.SetCursor(wxStockCursor(wxCURSOR_CROSS))
temp_dir = os.path.join(os.path.split(demdirectory)[0],os.path.splitext(os.path.split(demdirectory)[1])[0] + '.gif')
bmp = wxBitmap(temp_dir,wxBITMAP_TYPE_GIF)
self.bmp = bmp
self.SetScrollbars(1, 1,600, 750)
self.curLine = []
self.coords = (0,0,1,1)
self.x, self.y = 0,0
self.recstartx, self.recstarty = 0,0
def OnMouseEvent(self,event):
if event.LeftDown():
global lat_num,long_num
self.x, self.y = self.ConvertEventCoords(event)
self.recstartx, self.recstarty = self.ConvertEventCoords(event)
lat_num = start_lat - ((self.recstarty * 8) * y_scale)
long_num = start_long + ((self.recstartx * 8) * x_scale)
self.parent.Longitude.SetValue(str(long_num))
self.parent.Latitude.SetValue(str(lat_num))
self.CaptureMouse()
elif event.Dragging():
dc = wxClientDC(self)
self.PrepareDC(dc)
dc.DrawBitmap(self.bmp, 0, 0, 0)
dc.BeginDrawing()
self.x, self.y = self.ConvertEventCoords(event)
dc.SetBrush(wxTRANSPARENT_BRUSH)
dc.SetPen(wxPen(wxNamedColour('RED'), 1))
self.coords = (self.recstartx, self.recstarty) + ((self.x - self.recstartx), (self.y - self.recstarty))
apply(dc.DrawRectangle, self.coords)
dc.EndDrawing()
elif event.LeftUp():
global height_num,width_num
height_num = ((self.y - self.recstarty)* 8) * y_scale
width_num = ((self.x - self.recstartx) * 8) * x_scale
self.parent.Width.SetValue(str(width_num))
self.parent.Height.SetValue(str(height_num))
self.ReleaseMouse()
def OnPaint(self, event):
dc = wxPaintDC(self)
self.PrepareDC(dc)
dc.BeginDrawing()
dc.DrawBitmap(self.bmp, 0, 0, 0)
dc.SetBrush(wxTRANSPARENT_BRUSH)
dc.SetPen(wxPen(wxNamedColour('RED'), 1))
apply(dc.DrawRectangle, self.coords)
dc.EndDrawing()
def ConvertEventCoords(self, event):
xView, yView = self.GetViewStart()
xDelta, yDelta = self.GetScrollPixelsPerUnit()
return (event.GetX() + (xView * xDelta), event.GetY() + (yView * yDelta))
## Create a new frame class, derived from the wxPython Frame.
class ViewerFrame(wxFrame):
def __init__(self, parent, id, title):
# First, call the base class' __init__ method to create the frame
wxFrame.__init__(self, parent, id, title,wxDefaultPosition,wxDefaultSize)
global demdirectory,tom,long_num,start_long,lat_num,start_lat,x_scale,y_scale,Latitude_Minimum,Latitude_Maximum ,Longitude_Minimum,Longitude_Maximum
demdirectory = get_init_data(self)
self.displaychoice = 'shade'
self.globdir = os.path.join(os.getcwd(),'glob.png')
self.mainmenu = wxMenuBar() # Create menu bar.
menu=wxMenu()# Make a menu (will be the Open menu)
exitID=wxNewId() # Make a new ID for a menu entry.
menu.Append(exitID, '&Open', 'Open Picture') # Name the ID by adding it to the menu.
EVT_MENU(self, exitID, self.Picture_Open)
exitID=wxNewId()# Make a new ID for a menu entry.
menu.Append(exitID, '&Save', 'Save Projection')
EVT_MENU(self, exitID, self.Picture_Save)
exitID=wxNewId()
menu.Append(exitID, 'E&xit', 'Exit program')
EVT_MENU(self, exitID, self.Picture_Exit)
self.mainmenu.Append (menu, '&File') # Add the File menu to the menu bar.
self.SetMenuBar (self.mainmenu) # Attach the menu bar to the window.
self.Splitter = wxSplitterWindow(self, -1)
self.Picture_button_sizer = wxBoxSizer(wxHORIZONTAL)
self.Picture_sizer = wxBoxSizer(wxVERTICAL)
self.AandS_sizer = wxBoxSizer(wxVERTICAL)
self.AandS_lable_sizer = wxBoxSizer(wxVERTICAL)
self.Picture_view = wxPanel(self.Splitter, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
self.PictureWindow = Global_tile(self.Picture_view, self)
self.Longitude_ID = wxNewId()
self.Latitude_ID = wxNewId()
l4 = wxStaticText(self.Picture_view, -1, "Latitude")
l5 = wxStaticText(self.Picture_view, -1, "Longitude")
self.Latitude = wxTextCtrl(self.Picture_view, self.Latitude_ID, "0", size=(125, -1))
self.Latitude.SetInsertionPoint(0)
self.Latitude.SetValue(str(lat_num))
EVT_TEXT(self, self.Latitude_ID, self.EvtLatitudeText)
self.Longitude = wxTextCtrl(self.Picture_view, self.Longitude_ID, "0", size=(125, -1))
self.Longitude.SetInsertionPoint(0)
self.Longitude.SetValue(str(long_num))
EVT_TEXT(self, self.Longitude_ID, self.EvtLongitudeText)
l1 = wxStaticText(self.Picture_view, -1, "Width")
l6 = wxStaticText(self.Picture_view, -1, "Height")
self.Width_ID = wxNewId()
self.Height_ID = wxNewId()
self.Width = wxTextCtrl(self.Picture_view, self.Width_ID, "0", size=(125, -1))
self.Width.SetInsertionPoint(0)
self.Width.SetValue(str(width_num))
EVT_TEXT(self, self.Width_ID, self.EvtText)
self.Height = wxTextCtrl(self.Picture_view, self.Height_ID, "0", size=(125, -1))
self.Height.SetInsertionPoint(0)
self.Height.SetValue(str(height_num))
EVT_TEXT(self, self.Height_ID, self.EvtHeightText)
self.sub_Picture_button_sizer = wxBoxSizer(wxVERTICAL)
self.sub_Picture_button_text_sizer = wxBoxSizer(wxVERTICAL)
self.sub_Picture_button_sizer2 = wxBoxSizer(wxVERTICAL)
self.sub_Picture_button_text_sizer2 = wxBoxSizer(wxVERTICAL)
self.sub_Picture_button_text_sizer.Add(l4, 1, wxEXPAND)
self.sub_Picture_button_text_sizer.Add(l5, 1, wxEXPAND)
self.sub_Picture_button_sizer.Add(self.Latitude, 1, wxEXPAND)
self.sub_Picture_button_sizer.Add(self.Longitude, 1, wxEXPAND)
self.sub_Picture_button_text_sizer2.Add(l1, 1, wxEXPAND)
self.sub_Picture_button_text_sizer2.Add(l6, 1, wxEXPAND)
self.sub_Picture_button_sizer2.Add(self.Width, 1, wxEXPAND)
self.sub_Picture_button_sizer2.Add(self.Height, 1, wxEXPAND)
self.Picture_button_sizer.Add(self.sub_Picture_button_text_sizer, 1, wxEXPAND)
self.Picture_button_sizer.Add(self.sub_Picture_button_sizer, 1, wxEXPAND)
self.Picture_button_sizer.Add(self.sub_Picture_button_text_sizer2, 1, wxEXPAND)
self.Picture_button_sizer.Add(self.sub_Picture_button_sizer2, 1, wxEXPAND)
self.Picture_sizer.Add(self.Picture_button_sizer, 1, wxEXPAND)
self.Picture_sizer.Add(self.PictureWindow, 10, wxEXPAND)
self.Picture_view.SetSizer(self.Picture_sizer)
self.Picture_view.SetAutoLayout(1)
self.Picture_sizer.Fit(self.Picture_view)
self.ThreeD_button_sizer = wxBoxSizer(wxHORIZONTAL)
self.ThreeD_sizer = wxBoxSizer(wxVERTICAL)
self.ThreeD_viewID = wxNewId()
self.ThreeD_view = wxPanel(self.Splitter, self.ThreeD_viewID, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
self.ThreeDWindowID = wxNewId()
self.ThreeDWindow = wxScrolledWindow(self.ThreeD_view, self.ThreeDWindowID, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER)
self.ThreeD_Refresh_Button_ID = wxNewId()
self.ThreeD_Refresh_Button = wxButton(self.ThreeD_view, self.ThreeD_Refresh_Button_ID, 'Refresh', wxDefaultPosition)
EVT_BUTTON(self, self.ThreeD_Refresh_Button_ID, self.ThreeD_Refresh_Button_Press)
self.gen_Refresh_Button_ID = wxNewId()
self.gen_Refresh_Button = wxButton(self.ThreeD_view, self.gen_Refresh_Button_ID, 'Generate', wxDefaultPosition)
EVT_BUTTON(self, self.gen_Refresh_Button_ID, self.gen_Refresh_Button_Press)
self.newbutton_sizer = wxBoxSizer(wxVERTICAL)
self.newbutton_sizer.Add(self.ThreeD_Refresh_Button, 1, wxEXPAND)
self.newbutton_sizer.Add(self.gen_Refresh_Button, 1, wxEXPAND)
self.checkboxtext_sizer = wxBoxSizer(wxVERTICAL)
self.checkbox_sizer = wxBoxSizer(wxVERTICAL)
l4 = wxStaticText(self.ThreeD_view, -1, "Display")
TypeList = ['shade', 'contour', 'grid']
self.choice = wxChoice(self.ThreeD_view, 40, (80, 50), choices = TypeList)
self.choice.SetStringSelection('shade')
EVT_CHOICE(self, 40 , self.EvtChoice)
self.choices_sizer = wxBoxSizer(wxVERTICAL)
self.choices_text_sizer = wxBoxSizer(wxVERTICAL)
l10 = wxStaticText(self.ThreeD_view, -1, "Cont. lines")
l11 = wxStaticText(self.ThreeD_view, -1, "Z depth")
self.Cont_linesID = wxNewId()
self.Cont_lines = wxSpinCtrl(self.ThreeD_view, self.Cont_linesID, "", wxPoint(30, 50), wxSize(80, -1))
self.Cont_lines.SetRange(1,25)
self.Cont_lines.SetValue(10)
self.Z_depthID = wxNewId()
self.Z_depth = wxSpinCtrl(self.ThreeD_view, self.Z_depthID, "", wxPoint(30, 50), wxSize(80, -1))
self.Z_depth.SetRange(1,150)
self.Z_depth.SetValue(10)
self.camera_sizer = wxBoxSizer(wxVERTICAL)
self.camera_text_sizer = wxBoxSizer(wxVERTICAL)
l7 = wxStaticText(self.ThreeD_view, -1, "R Angle")
l8 = wxStaticText(self.ThreeD_view, -1, "Up Angle")
l9 = wxStaticText(self.ThreeD_view, -1, "Distance")
self.camera_text_sizer.Add(l7, 1, wxEXPAND)
self.camera_text_sizer.Add(l8, 1, wxEXPAND)
self.camera_text_sizer.Add(l9, 1, wxEXPAND)
self.RAngle_ID = wxNewId()
self.RAngle = wxSpinCtrl(self.ThreeD_view, self.RAngle_ID, "", wxPoint(30, 50), wxSize(80, -1))
self.RAngle.SetRange(0,359)
self.RAngle.SetValue(RSpin)
EVT_SPINCTRL(self, self.RAngle_ID, self.OnRSpin)
self.UAngle_ID = wxNewId()
self.UAngle = wxSpinCtrl(self.ThreeD_view, self.UAngle_ID, "", wxPoint(30, 50), wxSize(80, -1))
self.UAngle.SetRange(0,359)
self.UAngle.SetValue(USpin)
EVT_SPINCTRL(self, self.UAngle_ID, self.OnUSpin)
self.DAngle_ID = wxNewId()
self.DAngle = wxSpinCtrl(self.ThreeD_view, self.DAngle_ID, "", wxPoint(30, 50), wxSize(80, -1))
self.DAngle.SetRange(0,5000)
self.DAngle.SetValue(DSpin)
EVT_SPINCTRL(self, self.DAngle_ID, self.OnDSpin)
self.camera_sizer.Add(self.RAngle, 1, wxEXPAND)
self.camera_sizer.Add(self.UAngle, 1, wxEXPAND)
self.camera_sizer.Add(self.DAngle, 1, wxEXPAND)
self.ThreeD_button_sizer.Add(self.newbutton_sizer, 1, wxEXPAND)
self.ThreeD_button_sizer.Add(self.camera_text_sizer, 1, wxEXPAND)
self.ThreeD_button_sizer.Add(self.camera_sizer, 1, wxEXPAND)
self.choices_sizer.Add(self.choice, 1, wxEXPAND)
self.choices_sizer.Add(self.Cont_lines, 1, wxEXPAND)
self.choices_sizer.Add(self.Z_depth, 1, wxEXPAND)
self.choices_text_sizer.Add(l4, 1, wxEXPAND)
self.choices_text_sizer.Add(l10, 1, wxEXPAND)
self.choices_text_sizer.Add(l11, 1, wxEXPAND)
self.ThreeD_button_sizer.Add(self.choices_text_sizer, 1, wxEXPAND)
self.ThreeD_button_sizer.Add(self.choices_sizer, 1, wxEXPAND)
self.ThreeD_sizer.Add(self.ThreeD_button_sizer, 1, wxEXPAND)
self.ThreeD_sizer.Add(self.ThreeDWindow, 10, wxEXPAND)
self.ThreeD_view.SetSizer(self.ThreeD_sizer)
self.ThreeD_view.SetAutoLayout(1)
self.ThreeD_sizer.Fit(self.ThreeD_view)
self.Splitter.SetMinimumPaneSize(20)
self.Splitter.SplitVertically(self.ThreeD_view, self.Picture_view)
self.Splitter.SetSashPosition(300)
temp_dir = os.path.join(os.path.split(demdirectory)[0],os.path.splitext(os.path.split(demdirectory)[1])[0] + '.gif')
self.view_bitmap = wxBitmap(temp_dir,wxBITMAP_TYPE_GIF)
self.bitmapID = wxNewId()
self.bitmap2ID = wxNewId()
self.glob_thing = wxStaticBitmap(self.ThreeDWindow, self.bitmap2ID,self.view_bitmap, wxPoint(0,0), wxSize(853, 603))
#self.ThreeDWindow.SetScrollbars(1, 1, 853, 603)
def OnCloseWindow(self, event):
tom.close()
# tell the window to kill itself
self.Destroy()
def Picture_Open(self, event):
global demdirectory
demdirectory = get_init_data(self)
temp_dir = os.path.join(os.path.split(demdirectory)[0],os.path.splitext(os.path.split(demdirectory)[1])[0] + '.gif')
bitmap = wxBitmap(temp_dir,wxBITMAP_TYPE_GIF)
self.PictureWindow.bmp = bitmap
self.PictureWindow.Refresh()
self.Longitude.SetValue(str(long_num))
self.Latitude.SetValue(str(lat_num))
self.Height.SetValue(str(height_num))
self.Width.SetValue(str(width_num))
def EvtChoice(self, event):
self.displaychoice = event.GetString()
def OnRSpin(self, event):
RSpin = self.RAngle.GetValue()
def OnUSpin(self, event):
USpin = self.UAngle.GetValue()
def OnDSpin(self, event):
DSpin = self.DAngle.GetValue()
def EvtLatitudeText(self, event):
try:
my_lat_num = float(event.GetString())
if my_lat_num > Latitude_Minimum and my_lat_num < Latitude_Maximum:
temp = int((-(my_lat_num - start_lat)/ y_scale)/ 8)
if temp != self.PictureWindow.recstarty:
self.PictureWindow.recstarty = int((-(my_lat_num - start_lat)/ y_scale)/ 8)
self.PictureWindow.coords = (self.PictureWindow.recstartx, self.PictureWindow.recstarty) + ((self.PictureWindow.x - self.PictureWindow.recstartx), (self.PictureWindow.y - self.PictureWindow.recstarty))
width_num = ((self.PictureWindow.x - self.PictureWindow.recstartx) * 8) * x_scale
self.Width.SetValue(str(width_num))
dc = wxClientDC(self.PictureWindow)
self.PictureWindow.PrepareDC(dc)
dc.BeginDrawing()
dc.DrawBitmap(self.PictureWindow.bmp, 0, 0, 0)
dc.SetBrush(wxTRANSPARENT_BRUSH)
dc.SetPen(wxPen(wxNamedColour('RED'), 1))
apply(dc.DrawRectangle, self.PictureWindow.coords)
dc.EndDrawing()
except ValueError:
pass
def EvtLongitudeText(self, event):
try:
my_long_num = float(event.GetString())
if my_long_num > Longitude_Minimum and my_long_num < Longitude_Maximum:
temp = int(((my_long_num - start_long) / x_scale)/ 8)
if temp != self.PictureWindow.recstartx:
self.PictureWindow.recstartx = int(((my_long_num - start_long) / x_scale)/ 8)
self.PictureWindow.coords = (self.PictureWindow.recstartx, self.PictureWindow.recstarty) + ((self.PictureWindow.x - self.PictureWindow.recstartx), (self.PictureWindow.y - self.PictureWindow.recstarty))
height_num = ((self.PictureWindow.y - self.PictureWindow.recstarty)* 8) * y_scale
self.Height.SetValue(str(height_num))
dc = wxClientDC(self.PictureWindow)
self.PictureWindow.PrepareDC(dc)
dc.BeginDrawing()
dc.DrawBitmap(self.PictureWindow.bmp, 0, 0, 0)
dc.SetBrush(wxTRANSPARENT_BRUSH)
dc.SetPen(wxPen(wxNamedColour('RED'), 1))
apply(dc.DrawRectangle, self.PictureWindow.coords)
dc.EndDrawing()
except ValueError:
pass
def Picture_Save(self, event):
path = os.path.join(os.getcwd(),'glob2.png')
dlg = wxFileDialog(self, "Save Shading Map", ".", "","BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif|Jpeg files (*.jpg)|*.jpg|PNG files (*.png)|*.png|All files (*.*)|*.*", wxSAVE)
if dlg.ShowModal() == wxID_OK:
path = dlg.GetPath()
self.view_bit.SaveFile(path,imgtyp(path))
else:
self.view_bit.SaveFile(path,imgtyp(path))
dlg.Destroy()
def EvtText(self, event):
try:
my_width_num = float(event.GetString())
temp = int(((my_width_num / x_scale) / 8) + self.PictureWindow.recstartx)
if temp != self.PictureWindow.x:
self.PictureWindow.x = int(((my_width_num / x_scale) / 8) + self.PictureWindow.recstartx)
self.PictureWindow.coords = (self.PictureWindow.recstartx, self.PictureWindow.recstarty) + ((self.PictureWindow.x - self.PictureWindow.recstartx), (self.PictureWindow.y - self.PictureWindow.recstarty))
dc = wxClientDC(self.PictureWindow)
self.PictureWindow.PrepareDC(dc)
dc.BeginDrawing()
dc.DrawBitmap(self.PictureWindow.bmp, 0, 0, 0)
dc.SetBrush(wxTRANSPARENT_BRUSH)
dc.SetPen(wxPen(wxNamedColour('RED'), 1))
apply(dc.DrawRectangle, self.PictureWindow.coords)
dc.EndDrawing()
except ValueError:
pass
#my_width_num = ((self.PictureWindow.x - self.PictureWindow.recstartx) * 8) * 0.00833333333333
#self.PictureWindow.x = int(((my_width_num / 0.00833333333333) / 8) + self.PictureWindow.recstartx)
#self.PictureWindow.coords = (self.PictureWindow.recstartx, self.PictureWindow.recstarty) + ((self.PictureWindow.x - self.PictureWindow.recstartx), (self.PictureWindow.y - self.PictureWindow.recstarty))
def EvtHeightText(self, event):
try:
my_height_num = float(event.GetString())
temp = int(((my_height_num / y_scale) / 8) + self.PictureWindow.recstarty)
if temp != self.PictureWindow.y:
self.PictureWindow.y = int(((my_height_num / y_scale) / 8) + self.PictureWindow.recstarty)
self.PictureWindow.coords = (self.PictureWindow.recstartx, self.PictureWindow.recstarty) + ((self.PictureWindow.x - self.PictureWindow.recstartx), (self.PictureWindow.y - self.PictureWindow.recstarty))
dc = wxClientDC(self.PictureWindow)
self.PictureWindow.PrepareDC(dc)
dc.BeginDrawing()
dc.DrawBitmap(self.PictureWindow.bmp, 0, 0, 0)
dc.SetBrush(wxTRANSPARENT_BRUSH)
dc.SetPen(wxPen(wxNamedColour('RED'), 1))
apply(dc.DrawRectangle, self.PictureWindow.coords)
dc.EndDrawing()
except ValueError:
pass
#my_height_num = (self.PictureWindow.y - self.PictureWindow.recstarty) * 0.00833333333333
#self.PictureWindow.y = int(((my_height_num / 0.00833333333333) / 8) + self.PictureWindow.recstarty)
#self.PictureWindow.coords = (self.PictureWindow.recstartx, self.PictureWindow.recstarty) + ((self.PictureWindow.x - self.PictureWindow.recstartx), (self.PictureWindow.y - self.PictureWindow.recstarty))
def Picture_Exit(self, event):
self.Destroy()
def ThreeD_Refresh_Button_Press(self, event):
hi_num = 0
lo_num = 4328
new_line = []
data_char = ''
data_line_num = (self.PictureWindow.coords[2] * 16)
for x in range((self.PictureWindow.coords[1] * 8),(self.PictureWindow.coords[1] + self.PictureWindow.coords[3]) * 8):
data_start = (x * 9600) + (self.PictureWindow.coords[0] * 16)
tom.seek(data_start)
data_char = tom.read(data_line_num)
for i in range(0, len(data_char) - 1, 2):
data_num = (ord(data_char[i]) << 8) | ord(data_char[i+1])
if data_num == 55537:
data_num = 0
elif data_num >= 32767:
data_num = -(data_num ^ 65535)
if hi_num < data_num:
hi_num = data_num
elif lo_num > data_num:
lo_num = data_num
new_line.append(data_num)
img_size = ((self.PictureWindow.coords[2] * 8) , (self.PictureWindow.coords[3] * 8) )
try:
os.remove(self.globdir)
except OSError:
if self.displaychoice == 'shade':
self.dis_img(new_line, img_size[1], img_size[0], lo_num, hi_num)
elif self.displaychoice == 'grid':
self.dis_img2(new_line,img_size[1],img_size[0], lo_num, hi_num)
elif self.displaychoice == 'contour':
self.dis_img3(new_line,img_size[1],img_size[0], lo_num, hi_num)
self.view_bit = wxBitmap(self.globdir,wxBITMAP_TYPE_PNG)
self.ThreeDWindow.Scroll(0,0)
self.glob_thing.SetBitmap(self.view_bit)
self.ThreeDWindow.SetScrollbars(1, 1, self.view_bit.GetWidth() + 2, self.view_bit.GetHeight() + 2)
else:
if self.displaychoice == 'shade':
self.dis_img(new_line, img_size[1], img_size[0], lo_num, hi_num)
elif self.displaychoice == 'grid':
self.dis_img2(new_line, img_size[1], img_size[0], lo_num, hi_num)
elif self.displaychoice == 'contour':
self.dis_img3(new_line, img_size[1], img_size[0], lo_num, hi_num)
self.view_bit = wxBitmap(self.globdir,wxBITMAP_TYPE_PNG)
self.ThreeDWindow.Scroll(0,0)
self.glob_thing.SetBitmap(self.view_bit)
self.ThreeDWindow.SetScrollbars(1, 1, self.view_bit.GetWidth() + 2, self.view_bit.GetHeight() + 2)
def dis_img(self, zmat, n, m, zl, zh):
newmat = []
for i in range(m-1,-1,-1):
for j in range(n):
newmat.append(zmat[(j*m)+i])
newmat.reverse()
try:
temp_Width = float(self.Width.GetValue())
temp_Height = float(self.Height.GetValue())
except ValueError:
temp_Width = 1
temp_Height = 1
try:
temp_lat = float(self.Latitude.GetValue())
temp_long = float(self.Longitude.GetValue())
except ValueError:
temp_lat = lat_num
temp_long = long_num
if zl == zh:
zl = 0
zh = 10
dislin.metafl('PNG')
dislin.setpag('da4l')
dislin.setfil(self.globdir)
dislin.disini()
dislin.pagera()
dislin.hwfont()
dislin.name ('Latitude', 'Y')
dislin.name ('Longitude', 'X')
dislin.name ('Meters', 'Z')
if (m * (1400 / n))< 2000:
dislin.ax3len(m * (1400 / n), 1400, 1400)
else:
dislin.ax3len(2000,n * (2000 / m), 1400)
dislin.shdmod('poly', 'contur')
dislin.autres(m, n)
dislin.graf3(temp_long, temp_long + temp_Height, temp_long, temp_Height/5, temp_lat - temp_Width, temp_lat , temp_lat - temp_Width, temp_Width/5, zl, zh, zl, (zh-zl)/10)
dislin.crvmat(newmat, m, n, 1, 1)
dislin.title()
dislin.disfin()
def dis_img2(self, zmat, n, m, zl, zh):
newmat = []
for i in range(m): #-1,-1,-1):
for j in range(n):
newmat.append(zmat[(j*m)+i])
newmat.reverse()
zmat = newmat
try:
temp_Width = float(self.Width.GetValue())
temp_Height = float(self.Height.GetValue())
except ValueError:
temp_Width = 1
temp_Height = 1
try:
temp_lat = float(self.Latitude.GetValue())
temp_long = float(self.Longitude.GetValue())
except ValueError:
temp_lat = lat_num
temp_long = long_num
if zl == zh:
zl = 0
zh = 10
xray = range (m)
yray = range (n)
for i in range(n):
yray[i] = temp_lat - ((temp_Width / n) * i)
for i in range(m):
xray[i] = temp_long + ((temp_Height / m) * i)
RSpin = self.RAngle.GetValue()
USpin = self.UAngle.GetValue()
DSpin = self.DAngle.GetValue()
z_debth = self.Z_depth.GetValue()
dislin.metafl ('PNG')
dislin.setpag ('da4l')
dislin.setfil (self.globdir)
dislin.disini ()
dislin.pagera ()
dislin.hwfont ()
dislin.name ('Latitude', 'Y')
dislin.name ('Longitude', 'X')
dislin.axis3d(m, n, z_debth)
dislin.view3d(RSpin, USpin, DSpin, 'ANGLE')
dislin.shdmod('smooth', 'surface')
dislin.color('BLUE')
dislin.graf3d(temp_long, temp_long + temp_Height, temp_long, temp_Height/5, temp_lat - temp_Width, temp_lat , temp_lat - temp_Width, temp_Width/5, zl, zh, zl, (zh-zl)/10)
#dislin.graf3d(temp_lat ,temp_lat + temp_Width , temp_lat , temp_Width/5, temp_long, temp_long + temp_Height, temp_long,temp_Height/5, zl, zh, zl, (zh-zl)/5)
dislin.surshd(xray, m, yray, n, zmat)
dislin.title()
dislin.disfin()
def dis_img3(self, zmat, n, m, zl, zh):
newmat = []
for i in range(m):
for j in range(n):
newmat.append(zmat[(j * m) + i])
#newmat.reverse()
try:
temp_Width = float(self.Width.GetValue())
temp_Height = float(self.Height.GetValue())
temp_lat = float(self.Latitude.GetValue())
temp_long = float(self.Longitude.GetValue())
except ValueError:
temp_lat = lat_num
temp_long = long_num
temp_Width = 1
temp_Height = 1
if zl == zh:
zl = 0
zh = 10
xray = range (m)
yray = range (n)
c_lines = self.Cont_lines.GetValue()
for i in range(n):
yray[i] = temp_lat - ((temp_Width / n) * i)
for i in range(m):
xray[i] = temp_long + ((temp_Height / m) * i)
dislin.metafl('PNG')
dislin.setpag('da4l')
dislin.setfil(self.globdir)
dislin.disini()
dislin.pagera()
dislin.hwfont()
dislin.complx()
dislin.name ('Latitude', 'Y')
dislin.name ('Longitude', 'X')
if (m * (1400 / n))< 2000:
dislin.axslen(m * (1400 / n), 1400)
else:
dislin.axslen(2000, n * (2000 / m))
dislin.graf(temp_long, temp_long + temp_Height, temp_long, temp_Height/5, temp_lat - temp_Width, temp_lat , temp_lat - temp_Width, temp_Width/5)
#dislin.graf(temp_lat,temp_lat + temp_Width, temp_lat , temp_Width/5,temp_long, temp_long + temp_Height, temp_long,temp_Height/5)
dislin.height (25)
for i in range (c_lines -1 ):
zlev = (i * ((zh-zl) / c_lines)) + zl
dislin.labels ('FLOAT', 'CONTUR')
dislin.setclr ((i+1) * int(255/c_lines))
dislin.contur (xray, m, yray, n, newmat, zlev)
dislin.disfin()
def input_streem(self, streem):
if tommy.has_key( "RAngle" ) :
test = tommy.getvalue("RAngle", "")
try:
RAngle = int(test)
except ValueError:
pass
else :
pass
if tommy.has_key( "UAngle" ) :
test = tommy.getvalue("UAngle", "")
try:
UAngle = int(test)
except ValueError:
pass
else :
pass
if tommy.has_key( "DAngle" ) :
test = tommy.getvalue("DAngle", "")
try:
DAngle = int(test)
except ValueError:
pass
else :
pass
if tommy.has_key( "Latitude" ) :
test = tommy.getvalue("Latitude", "")
try:
Latitude = float(test)
except ValueError:
pass
else :
pass
if tommy.has_key( "Longitude" ) :
test = tommy.getvalue("Longitude" , "")
try:
Longitude = float(test)
except ValueError:
pass
else :
pass
if tommy.has_key( "Width") :
test = tommy.getvalue("Width" , "")
try:
Width = int(test)
except ValueError:
pass
else :
print "Not found Not found"
if tommy.has_key( "Height") :
test = tommy.getvalue("Height", "")
try:
Height = int(test)
except ValueError:
pass
else :
pass
if tommy.has_key( "Contlines" ) :
test = tommy.getvalue("Contlines" , "")
try:
Contlines = int(test)
except ValueError:
pass
else :
pass
if tommy.has_key( "Z_depth" ) :
test = tommy.getvalue("Z_depth" , "")
try:
Z_depth = int(test)
except ValueError:
pass
else :
pass
self.Longitude.SetValue(str(long_num))
self.Latitude.SetValue(str(lat_num))
self.Width.SetValue(str(width_num))
self.Height.SetValue(str(height_num))
self.Cont_lines.SetValue(str(long_num))
self.Z_depth.SetValue(str(long_num))
self.choice.SetValue(str(long_num))
self.RAngle.SetValue(str(long_num))
self.UAngle.SetValue(str(long_num))
self.DAngle.SetValue(str(long_num))
def gen_Refresh_Button_Press(self, event):
self.displaychoice = 'shade'
self.ThreeD_Refresh_Button_Press(None)
self.view_bit.SaveFile('c:\\python21\\Tom\\server\\glob.jpg', wxBITMAP_TYPE_JPEG)
self.displaychoice = 'contour'
self.ThreeD_Refresh_Button_Press(None)
self.view_bit.SaveFile('c:\\python21\\Tom\\server\\glob2.jpg', wxBITMAP_TYPE_JPEG)
self.displaychoice = 'grid'
self.ThreeD_Refresh_Button_Press(None)
self.view_bit.SaveFile('c:\\python21\\Tom\\server\\glob3.jpg', wxBITMAP_TYPE_JPEG)
# Every wxWindows application must have a class derived from wxApp
class MyApp(wxApp):
# wxWindows calls this method to initialize the application
def OnInit(self):
# Create an instance of our customized Frame class
frame = ViewerFrame(NULL, -1, "Digital Elevation Model Viewer")
frame.Show(true)# Tell wxWindows that this is our main window
self.SetTopWindow(frame) # Return a success flag
return true
app = MyApp(0) # Create an instance of the application class
app.MainLoop() # Tell it to start processing events