# Created by Leo from: C:\Python22\Tom\sfsding.leo # << globalDEMV-comment2 declarations >> import os from wxPython.wx import * import dislin import string import binascii import Image import image_view import StringIO # startup numbers (declares global variables) not sure if it is necessary 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() # initialize wxPython image handlers # -- end -- << globalDEMV-comment2 declarations >> # << globalDEMV-comment2 methods >> (1 of 5) def imgtyp(file_nm):# returns wx image type fl_fld = os.path.splitext(file_nm) ext = fl_fld[1] ext = string.lower(ext[1:])# get extension if ext == 'bmp': image = wxBITMAP_TYPE_BMP elif ext == 'gif': image = wxBITMAP_TYPE_GIF elif ext == 'png': image = wxBITMAP_TYPE_PNG elif ext == 'jpg': image = wxBITMAP_TYPE_JPEG return image # << globalDEMV-comment2 methods >> (2 of 5) def get_init_data(parent):# get data from the .hdr file 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) temp_file.close() return dir # << globalDEMV-comment2 methods >> (3 of 5) class Global_tile(wxScrolledWindow):# the display window for giff from DEM package # << class Global_tile declarations >> # 8 to 1 ratio giff of data # separate window so that I can catch the mouse events # this is essentially taken from the demo # -- end -- << class Global_tile declarations >> # << class Global_tile methods >> (1 of 4) def __init__(self, parent, main_parent,id = -1, size = wxDefaultSize): # object, parent objet (one side of split window) for wxPython, parent object wxScrolledWindow.__init__(self, parent, id, wxPoint(0, 0), size, wxSUNKEN_BORDER) self.parent = main_parent # make the parent object pointer passable to other procedures in the class # scrolled window properties self.lines = [] self.maxWidth = 1500 self.maxHeight = 1500 self.SetBackgroundColour(wxNamedColor("WHITE")) 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) # some class variables self.coords = (0,0,1,1)# the box coordinates (probably redundant) self.x, self.y = 0,0 # the mouse position self.recstartx, self.recstarty = 0,0 # the rectangle start position # class events EVT_MOUSE_EVENTS(self, self.OnMouseEvent) # for when the mouse is used over the scrolled window EVT_PAINT(self,self.OnPaint)# for when the window is move or resized # << class Global_tile methods >> (2 of 4) def OnMouseEvent(self,event):# the whole point of this class if event.LeftDown():# mouse down global lat_num, long_num # make sure I have access to my global variables self.x, self.y = self.ConvertEventCoords(event)# get the mouse position self.recstartx, self.recstarty = self.x, self.y # set the start of the rectangle mouse position lat_num = start_lat - ((self.recstarty * 8) * y_scale)# calculate the latitude long_num = start_long + ((self.recstartx * 8) * x_scale)# calculate the longitude self.parent.Longitude.SetValue(str(long_num))# set the value of the Longitude text box self.parent.Latitude.SetValue(str(lat_num))# set the value of the Latitude text box self.CaptureMouse()# Capture all mouse events in class elif event.Dragging():# dragging the mouse dc = wxClientDC(self) # make a device context, client because it is not in the OnPaint method self.PrepareDC(dc)# link with class dc.BeginDrawing()# draw to the DC dc.DrawBitmap(self.bmp, 0, 0, 0)# draw the GIF from the DEM Package self.x, self.y = self.ConvertEventCoords(event)# get the mouse position dc.SetBrush(wxTRANSPARENT_BRUSH)# make sure the square is not filled dc.SetPen(wxPen(wxNamedColour('RED'), 1))# set the box outline to red 1pixel self.coords = (self.recstartx, self.recstarty) + ((self.x - self.recstartx), (self.y - self.recstarty)) # put the box in a tuple for the drawing function apply(dc.DrawRectangle, self.coords)# draw the box dc.EndDrawing()# move the drawing to the window elif event.LeftUp():# let go of mouse button global height_num,width_num# make sure I have access to my global variables height_num = ((self.y - self.recstarty)* 8) * y_scale# calculate the height width_num = ((self.x - self.recstartx) * 8) * x_scale# calculate the width self.parent.Width.SetValue(str(width_num))# set the value of the Width text box self.parent.Height.SetValue(str(height_num))# set the value of the Height text box self.ReleaseMouse()# Release Mouse events # << class Global_tile methods >> (3 of 4) def OnPaint(self, event):# when the window is moved or uncovered dc = wxPaintDC(self) # make a device context, paint because it is in the OnPaint method self.PrepareDC(dc)# link with class dc.BeginDrawing()# draw to the DC dc.DrawBitmap(self.bmp, 0, 0, 0)# draw the GIF from the DEM Package dc.SetBrush(wxTRANSPARENT_BRUSH)# make sure the square is not filled dc.SetPen(wxPen(wxNamedColour('RED'), 1))# set the box outline to red 1pixel apply(dc.DrawRectangle, self.coords)# draw the box dc.EndDrawing()# move the drawing to the window # << class Global_tile methods >> (4 of 4) def ConvertEventCoords(self, event):# gets x, y inside scrolled window xView, yView = self.GetViewStart() # Get the position at which the visible portion of the window starts. xDelta, yDelta = self.GetScrollPixelsPerUnit() # Get the number of pixels per scroll line made by SetScrollbars. return (event.GetX() + (xView * xDelta), event.GetY() + (yView * yDelta)) # calculate and return x and y position # -- end -- << class Global_tile methods >> # << globalDEMV-comment2 methods >> (4 of 5) ## Create a new frame class, derived from the wxPython Frame. class ViewerFrame(wxFrame): # << class ViewerFrame methods >> (1 of 4) 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 self.Imagetest = Image.new.__init__('RGB',(853,603)) # make sure I have access to my global variables demdirectory = get_init_data(self) # get .DEM file location as well as set up data from .HDR file self.displaychoice = 'shade'# start with shade plot self.globdir = os.path.join(os.getcwd(),'glob.png') # set the file name used for transferring the data from dislin in the current working directory 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)# the menu event exitID=wxNewId()# Make a new ID for a menu entry. menu.Append(exitID, '&Save', 'Save Projection')# Name the ID by adding it to the menu. EVT_MENU(self, exitID, self.Picture_Save)# the menu event exitID=wxNewId()# Make a new ID for a menu entry. menu.Append(exitID, 'E&xit', 'Exit program')# Name the ID by adding it to the menu. EVT_MENU(self, exitID, self.Picture_Exit)# the menu event self.mainmenu.Append (menu, '&File') # Add the File menu to the menu bar. self.SetMenuBar (self.mainmenu) # Attach the menu bar to the window. # make the main splitter window one side holds the dislin picture one for the DEM GIF self.Splitter = wxSplitterWindow(self, -1) # make sizers self.Picture_button_sizer = wxBoxSizer(wxHORIZONTAL) self.Picture_sizer = wxBoxSizer(wxVERTICAL) 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.ThreeD_button_sizer = wxBoxSizer(wxHORIZONTAL) self.ThreeD_sizer = wxBoxSizer(wxVERTICAL) self.choices_sizer = wxBoxSizer(wxVERTICAL) self.choices_text_sizer = wxBoxSizer(wxVERTICAL) self.camera_sizer = wxBoxSizer(wxVERTICAL) self.camera_text_sizer = wxBoxSizer(wxVERTICAL) # right splitter window # panel for text and labels and scrolled window self.Picture_view = wxPanel(self.Splitter, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL) # The DEM gif scrolled window self.PictureWindow = Global_tile(self.Picture_view, self) # long and lat boxes with labels self.Longitude_ID = wxNewId() self.Latitude_ID = wxNewId() self.lattext = wxStaticText(self.Picture_view, -1, " Latitude") self.longtext = 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) #Height and Width boxes with lables self.widthtext = wxStaticText(self.Picture_view, -1, " Width") self.heighttext = 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) # right splitter window # panel for text and lables and scrolled window self.ThreeD_viewID = wxNewId() self.ThreeD_view = wxPanel(self.Splitter, self.ThreeD_viewID, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL) # The Dislin PNG scrolled window self.ThreeDWindowID = wxNewId() #self.glob_thing = wxScrolledWindow(self.ThreeD_view, self.ThreeDWindowID, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER) self.glob_thing = image_view.ImageView(self.ThreeD_view, -1, tools = [image_view.PanTool, image_view.ZoomTool, image_view.SharpTool , image_view.ColorTool , image_view.BrightTool , image_view.ContTool , image_view.RestoreTool]) # refresh button 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) # A choice dialog for the display type self.displaytext = 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) # spin controls and lables for the contour lines, z debth, rotation angle, up angle and distance self.conttext = wxStaticText(self.ThreeD_view, -1, " Cont. lines") self.ztext = 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.ratext = wxStaticText(self.ThreeD_view, -1, " R Angle") self.uatext = wxStaticText(self.ThreeD_view, -1, " Up Angle") self.disttext = wxStaticText(self.ThreeD_view, -1, " Distance") 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) # set up splitter window self.Splitter.SetMinimumPaneSize(20) self.Splitter.SplitVertically(self.ThreeD_view, self.Picture_view) self.Splitter.SetSashPosition(300) # set up initial bitmaps for scrolled windows 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)) # add everything to sizers self.sub_Picture_button_text_sizer.Add(self.lattext, 1, wxEXPAND) self.sub_Picture_button_text_sizer.Add(self.longtext, 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(self.heighttext, 1, wxEXPAND) self.sub_Picture_button_text_sizer2.Add(self.widthtext, 1, wxEXPAND) self.sub_Picture_button_sizer2.Add(self.Height, 1, wxEXPAND) self.sub_Picture_button_sizer2.Add(self.Width, 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.camera_text_sizer.Add(self.ratext, 1, wxEXPAND) self.camera_text_sizer.Add(self.uatext, 1, wxEXPAND) self.camera_text_sizer.Add(self.disttext, 1, wxEXPAND) 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.ThreeD_Refresh_Button, 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(self.displaytext, 1, wxEXPAND) self.choices_text_sizer.Add(self.conttext, 1, wxEXPAND) self.choices_text_sizer.Add(self.ztext, 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.glob_thing, 10, wxEXPAND) self.ThreeD_view.SetSizer(self.ThreeD_sizer) self.ThreeD_view.SetAutoLayout(1) self.ThreeD_sizer.Fit(self.ThreeD_view) #make sure that the right controls are displayed self.UAngle.Show(0) self.DAngle.Show(0) self.RAngle.Show(0) self.ratext.Show(0) self.uatext.Show(0) self.disttext.Show(0) self.conttext.Show(0) self.ztext.Show(0) self.Cont_lines.Show(0) self.Z_depth.Show(0) # << class ViewerFrame methods >> (2 of 4) def OnCloseWindow(self, event): # close the DEM file tom.close() # tell the window to kill itself self.Destroy() # << class ViewerFrame methods >> (3 of 4) def Picture_Open(self, event): # run the get_init_data function and reset bitmaps and text boxes in DEM gif scrolled window 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)) # << class ViewerFrame methods >> (4 of 4) def EvtChoice(self, event):# if the display choice is changed self.displaychoice = event.GetString() if self.displaychoice == 'shade': self.UAngle.Show(0)# makeing sure only appropriate controls are displayed self.DAngle.Show(0) self.RAngle.Show(0) self.ratext.Show(0) self.uatext.Show(0) self.disttext.Show(0) self.conttext.Show(0) self.ztext.Show(0) self.Cont_lines.Show(0) self.Z_depth.Show(0) elif self.displaychoice == 'contour': self.UAngle.Show(0) self.DAngle.Show(0) self.RAngle.Show(0) self.ratext.Show(0) self.uatext.Show(0) self.disttext.Show(0) self.conttext.Show(1) self.ztext.Show(0) self.Cont_lines.Show(1) self.Z_depth.Show(0) elif self.displaychoice == 'grid': self.UAngle.Show(1) self.DAngle.Show(1) self.RAngle.Show(1) self.ratext.Show(1) self.uatext.Show(1) self.disttext.Show(1) self.conttext.Show(0) self.ztext.Show(1) self.Cont_lines.Show(0) self.Z_depth.Show(1) def OnRSpin(self, event):# rotation angle has changed RSpin = self.RAngle.GetValue() def OnUSpin(self, event):# up angle has changed USpin = self.UAngle.GetValue() def OnDSpin(self, event):# distance has changed DSpin = self.DAngle.GetValue() def EvtLatitudeText(self, event):# Latitude has changed try: # while you type in a new number some of the characters # don’t make since so we just pass till it makes since my_lat_num = float(event.GetString()) my_height_num = float(self.Height.GetValue()) if my_lat_num > Latitude_Minimum and my_lat_num < Latitude_Maximum:# is it in scale temp = int((-(my_lat_num - start_lat)/ y_scale)/ 8)# convert from lat to bitmap cooranants if temp != self.PictureWindow.recstarty:# is it the same spot on the bitmap # the same drawing procedure used in the Global_tile class self.PictureWindow.recstarty = temp 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 def EvtLongitudeText(self, event):# Longitude has changed try:# while you type in a new number some of the characters # don’t make since so we just pass till it makes since my_long_num = float(event.GetString()) my_width_num = float(self.Width.GetValue()) if my_long_num > Longitude_Minimum and my_long_num < Longitude_Maximum:# is it in scale temp = int(((my_long_num - start_long) / x_scale)/ 8)# convert from long to bitmap cooranants if temp != self.PictureWindow.recstartx:# is it the same spot on the bitmap self.PictureWindow.recstartx = temp 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 def Picture_Save(self, event): # save the dislin PNG as any PIL file type 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", wxSAVE) if dlg.ShowModal() == wxID_OK: path = dlg.GetPath() newimage = self.glob_thing.get_image() newimage.save(path) else: pass dlg.Destroy() def EvtText(self, event): try:# while you type in a new number some of the characters # don’t make since so we just pass till it makes since 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 = temp 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 def EvtHeightText(self, event): try:# while you type in a new number some of the characters # don’t make since so we just pass till it makes since 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 = temp 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 def Picture_Exit(self, event): # close the DEM file tom.close() # tell the window to kill itself self.Destroy() def ThreeD_Refresh_Button_Press(self, event): # where Everything is happening hi_num = 0# there’s a master list of elevation for each tile of the DEM data lo_num = 4328# so I could use some kind of look up table but this way is just as easy new_line = [] data_char = '' data_line_num = (self.PictureWindow.coords[2] * 16) # width of box 8 to 1 data to gif ratio 16 bit variable in a string for x in range((self.PictureWindow.coords[1] * 8),(self.PictureWindow.coords[1] + self.PictureWindow.coords[3]) * 8): # iterate over height data_start = (x * 9600) + (self.PictureWindow.coords[0] * 16) # find start position of rectangle in file (the number 9600 bytes per line # should probably be in a variable) tom.seek(data_start)# move to proper position in file data_char = tom.read(data_line_num)# read proper number of bytes for i in range(0, len(data_char) - 1, 2):# iterate over the characters by 2s # its a 16 bit signed integer which means that there has got to be # a more elegant way of doing this but I was lazy data_num = (ord(data_char[i]) << 8) | ord(data_char[i+1]) if data_num == 55537:#sea level data_num = 0 if data_num >= 32767: data_num = -(data_num ^ 65535) new_line.append(data_num) img_size = ((self.PictureWindow.coords[2] * 8) , (self.PictureWindow.coords[3] * 8) ) # Image size for dislin # this could be an error spot on some systems if self.displaychoice == 'shade':# call the shade routine self.dis_img(new_line, img_size[1], img_size[0], min(new_line),max(new_line)) elif self.displaychoice == 'grid':# call the grid routine self.dis_img2(new_line,img_size[1],img_size[0], lo_num, hi_num) elif self.displaychoice == 'contour':# call the contour routine self.dis_img3(new_line,img_size[1],img_size[0], lo_num, hi_num) self.glob_thing.set_image(self.Imagetest) def dis_img(self, zmat, n, m, zl, zh):# shade routine char = '' temp_Width = 1 temp_Height = 1 temp_lat = 1 temp_long = 1 newmat = [] max_bytes = 0 for i in range(m-1,-1,-1):# transform the rectangle for j in range(n): newmat.append(zmat[(j*m)+i]) newmat.reverse() # get the lat, long, height and width for lables 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('VIRT')# level 0,sets the file type dislin.setpag('da4l')# page size and orientation dislin.setfil(self.globdir)# file name dislin.disini()# level 1, change to level 1 dislin.pagera()# plots a border around the page dislin.hwfont()# sets default font 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) # level 3 dislin.graf3(temp_long, temp_long + temp_Width, temp_long, temp_Width/5, temp_lat - temp_Height, temp_lat , temp_lat - temp_Height, temp_Height / 5, zl, zh, zl, (zh-zl)/10) dislin.crvmat(newmat, m, n, 1, 1) dislin.title() char_buff = dislin.rbfpng(max_bytes) max_bytes = int(char_buff[1]) char_buff = dislin.rbfpng(max_bytes) char = char_buff[0] self.Imagetest = Image.open(StringIO.StringIO(char)) dislin.disfin() def dis_img2(self, zmat, n, m, zl, zh): char = '' max_bytes = 0 newmat = [] for i in range(m): 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_Height / n) * i) for i in range(m): xray[i] = temp_long + ((temp_Width / m) * i) RSpin = self.RAngle.GetValue() USpin = self.UAngle.GetValue() DSpin = self.DAngle.GetValue() z_debth = self.Z_depth.GetValue() dislin.metafl ('VIRT') 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_Width, temp_long, temp_Width/5, temp_lat - temp_Height, temp_lat , temp_lat - temp_Height, temp_Height / 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)--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.surshd(xray, m, yray,n, zmat) dislin.title() char_buff = dislin.rbfpng(max_bytes) max_bytes = int(char_buff[1]) char_buff = dislin.rbfpng(max_bytes) char = char_buff[0] self.Imagetest = Image.open(StringIO.StringIO(char)) dislin.disfin() def dis_img3(self, zmat, n, m, zl, zh): char = '' max_bytes = 0 newmat = [] for i in range(m): for j in range(n): newmat.append(zmat[(j*m)+i]) 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_Height / n) * i) for i in range(m): xray[i] = temp_long + ((temp_Width / m) * i) dislin.metafl('VIRT') 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_Width, temp_long, temp_Width/5, temp_lat - temp_Height, temp_lat , temp_lat - temp_Height, temp_Height/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) char_buff = dislin.rbfpng(max_bytes) max_bytes = int(char_buff[1]) char_buff = dislin.rbfpng(max_bytes) char = char_buff[0] self.Imagetest = Image.open(StringIO.StringIO(char)) dislin.disfin() # -- end -- << class ViewerFrame methods >> # << globalDEMV-comment2 methods >> (5 of 5) # Every wxWindows application must have a class derived from wxApp class MyApp(wxApp): # << class MyApp declarations >> # wxWindows calls this method to initialize the application # -- end -- << class MyApp declarations >> # << class MyApp methods >> 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 # -- end -- << class MyApp methods >> # -- end -- << globalDEMV-comment2 methods >> app = MyApp(0) # Create an instance of the application class app.MainLoop() # Tell it to start processing events