VIEW2.sml

  Download

More scripts: SML Fundamentals

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# VIEW2.SML
# Sample script for tutorial Writing Scripts in SML
# Randy Smith, MicroImages, Inc.
# Requires TNTmips version 2008:74
# 3 December 2009
# Script provides an example of how to create and display an image and vector layer
# in a View window in an SML script.
class RVC_RASTER Rast;	# input raster object
class RVC_VECTOR Vect;	# input vector object
class STRING xml$;	# string variable containing the dialog specification in XML
class XMLDOC doc;		# class instance for the parsed XML text containing the view dialog specification
class XMLNODE dlgnode;	# class instance for the dialog node in the XML structure for the dialog window
class GUI_DLG dlgview;	# dialog class instance for the dialog window
class GRE_VIEW view;		# class instance for the view
class COLOR color;		# background color for the view
numeric err;				# variable for error checking  
#####################################################################
### Procedure called when View dialog window is initialized.  Used to create
### view within the window and to create a group to view the selected raster.
proc OnInitDialog () 
	{
	local class GUI_LAYOUT_PANE viewpane; 	# class instance for layout pane to contain the view
	local class WIDGET viewpaneWidget;		# class for widget for layout pane to serve as parent for the view
	local class GRE_GROUP viewgp;				# class for group to be shown in the view
	local class GRE_LAYER_RASTER rastLayer;	# class for the raster layer
	local class GRE_LAYER_VECTOR vectLayer;
	viewpane = dlgview.GetPaneByID("viewpane");		# get handle for layout pane from dialog
	viewpaneWidget = viewpane.GetWidget();					# get Xm widget for pane
	viewgp = GroupCreate();										# create display group
	rastLayer = GroupQuickAddRasterVar(viewgp, Rast);	# add the raster object to the group
	vectLayer = GroupQuickAddVectorVar(viewgp, Vect);	# add the vector object to the group
	
	# create 2D view of group in dialog using viewpane's widget as parent
	view = viewgp.CreateView(viewpaneWidget, "View", 400, 200, "NoDftMarkButtons,NoStatusBar,NoLegend");
	# set white as background color for view
	color.red = 100;	color.green = 100;	color.blue = 100;
	view.BackgroundColor = color;
	}
#######################################################################
### Procedure called when the close button on the View window is pressed
proc onClose()
	{
	dlgview.Close(0);
	Exit();
	}
########################################################################
### Procedure called when the view dialog window opens
proc onViewOpen()
	{
	view.Redraw();
	}
######################  MAIN PROGRAM  ###############################
clear();
# prompt user to select input raster and vector objects
GetInputRaster(Rast);
GetInputVector(Vect);
xml$ = '<?xml version="1.0"?>
	<root>
		<dialog id="dlgview" Title="View2" Buttons="" HorizResize="Expand" VertResize="Expand" OnOpen="onViewOpen()">
			<pane id="viewpane" Orientation = "vertical" HorizResize="Expand" VertResize="Expand"/>
			<pane Orientation="horizontal" HorizAlign="right" HorizResize="Expand" VertResize="Expand">
				<pushbutton Name="  Close  " VertResize="Fixed" VertAlign="Bottom" OnPressed="onClose()"/> 
			</pane>
		</dialog>
	</root>';
# parse XML text for the dialog into memory; 
# return an error code (number < 0 ) if there are syntax errors
err = doc.Parse(xml$);
if (err < 0) 
	{
	PopupError(err); 	# Popup an error dialog. "Details" button shows syntax errors.
	Exit();
	}
# get the dialog element from the parsed XML document and
# show error message if the dialog element can't be found
dlgnode = doc.GetElementByID("dlgview");
if (dlgnode == 0) 
	{
	PopupMessage("Could not find dialog node in XML document");
	Exit();
	}
# Set the XML dialog element as the source for the GUI_DLG class instance
# we are using for the dialog window. Also set the OnInitDialog procedure to be called.
dlgview.SetXMLNode(dlgnode);
dlgview.SetOnInitDialog(OnInitDialog);
dlgview.DoModal();