TNTmips

HOME

FREE PRODUCTS
  TNTlite
  TNTatlas
  TNTsim3D

DOWNLOADS
  Release Version
  Development Version
  FTP
  Language Kits
  Sample Geodata
  Reseller Resources
  Promotional

DOCUMENTATION
  Tutorials
  Technical Guides
  Quick Guides

SITE MAP


getdata.sml


### getdata.sml
### Sample script for Building Dialogs in SML

### Illustrates different available methods for reading values from a dialog.

### Global variable declarations
numeric errXML, dlgreturn;
string xmlfile$;

# clear the console window
clear();	

### create string with path and filename of XML file with the
### dialog specification (assumed to be in same directory as this script)
xmlfile$ = _context.ScriptDir + "/getdata.xml";

### read and parse XML file; returns an error code (number < 0 ) if there are syntax errors
class XMLDOC doc;
errXML = doc.Read(xmlfile$);

if (errXML < 0) {
	PopupError(errXML); # Popup an error dialog. "Details" button shows syntax errors.
	Exit();
}

### declare class instance for the dialog element in the XML structure
### and get the dialog handle from the XML structure.
### Pop up an error dialog and exit if the dialog ID can't be found in the XML.
class XMLNODE dlgnode;	
dlgnode = doc.GetElementByID("tigrds");

if (dlgnode == 0) {
	PopupMessage("Could not find dialog node in XML document");
	Exit();
}

### declare class instance for the dialog window and set the XML structure
### in memory as the source for the dialog.
class GUI_DLG dlgwin;
dlgwin.SetXMLNode(dlgnode);

### open as a modal dialog; the DoModal() method doesn't return until the dialog is
### closed; it returns -1 if the user presses [Cancel], or 0 if the user presses [OK]. 
dlgreturn = dlgwin.DoModal();

if (dlgreturn == -1) {		# exit script when Cancel button on dialog is pressed
	Exit();
	}



# Here are four ways to get settings out of the dialog.
# The extracted values are printed to the console window as an example.

proc GetValues () {

	# 1 -- Use the GetValues() class method for the dialog window (in GUI_DLG)
	# 		to get all of the control settings at once.  They are returned to a
	#		previously-declared instance of class GUIFORMDATA. Use GetValue...()
	#		methods in that class to read the values as needed.

	printf("Dialog values using GUI_FORMDATA:\n");
	class GUI_FORMDATA data;
	data = dlgwin.GetValues();
	printf("  Extract Road Lines toggle (numeric value)= %d\n", data.GetValueNum("getrds") );
	printf("  Extract Road Lines toggle (string value)= %s\n", data.GetValueStr("getrds") );
	printf("  Make Roads Buffer toggle (numeric value)= %d\n", data.GetValueNum("mkbuf") );
	printf("  Make Roads Buffer toggle (string value) = %s\n", data.GetValueStr("mkbuf") );
	printf("  Buffer distance value = %d\n", data.GetValueNum("buffdist") );


	# 2 -- Use GetCtrlValueNum() and GetCtrlValueStr() class methods for the dialog
	#		window (in class GUI_DLG) to ask the dialog for each control value as
	#		needed.  No GUI_FORMDATA class instance is required.  Less efficient than
	#		#1 if multiple control values are needed.  Internally it calls dlgwin.GetValues,
	#		pulls out the one value asked for, and discards the rest.

	printf("\nDialog values using GetCtrlValue... methods in GUI_DLG class:\n");
	printf("  Extract Road Lines toggle (numeric value)= %d\n", dlgwin.GetCtrlValueNum("getrds") );
	printf("  Extract Road Lines toggle (string value)= %s\n", dlgwin.GetCtrlValueStr("getrds") );
	printf("  Make Roads Buffer toggle (numeric value)= %d\n", dlgwin.GetCtrlValueNum("mkbuf") );
	printf("  Make Roads Buffer toggle (string value) = %s\n", dlgwin.GetCtrlValueStr("mkbuf") );
	printf("  Buffer distance value = %d\n", dlgwin.GetCtrlValueNum("buffdist") );

	# 3 -- Use the GetCtrlByID() method in GUI_DLG to get the handle for a control,
	#		which is assigned to a previously-declared instance of the appropriate control
	#		class.  Then use a GetValue...() or similar method in the individual GUI_CTRL... 
	#		class to read the control value individually as needed.
	class GUI_CTRL_TOGGLEBUTTON getrds;
	class GUI_CTRL_TOGGLEBUTTON mkbuf;
	class GUI_CTRL_EDIT_NUMBER buffdist;
	getrds = dlgwin.GetCtrlByID( "getrds" );
	mkbuf = dlgwin.GetCtrlByID( "mkbuf" );
	buffdist = dlgwin.GetCtrlByID( "buffdist" );

	printf("\nDialog values using GetCtrlByID and control class methods:\n");
	printf("  Extract Road Lines toggle (numeric value) = %d\n", getrds.GetValueNum() );
	printf("  Extract Road Lines toggle (string value)= %s\n", getrds.GetValueStr() );
	printf("  Make Roads Buffer toggle (numeric value)= %d\n", mkbuf.GetValueNum() );
	printf("  Make Roads Buffer toggle (string value) = %s\n", mkbuf.GetValueStr() );
	printf("  Buffer distance value = %d\n", buffdist.GetValueNum() );

	# 4 -- A more compact (but perhaps less clear version of method 3.  Methods to get
	#		the control handle and its value are strung together, eliminating the need to
	#		declare the control handle class variable.

	printf("\nDialog values using GetCtrlByID strung together with control class methods:\n");
	printf("  Extract Road Lines toggle (numeric value) = %d\n", dlgwin.GetCtrlByID("getrds").GetValueNum() );
	printf("  Extract Road Lines toggle (string value)= %s\n", dlgwin.GetCtrlByID("getrds").GetValueStr() );
	printf("  Make Roads Buffer toggle (numeric value)= %d\n", dlgwin.GetCtrlByID("mkbuf").GetValueNum() );
	printf("  Make Roads Buffer toggle (string value) = %s\n", dlgwin.GetCtrlByID("mkbuf").GetValueStr() );
	printf("  Buffer distance value = %d\n", dlgwin.GetCtrlByID("buffdist").GetValueNum() );

	}


Back Home ©MicroImages, Inc. 2008 Published in the United States of America
11th Floor - Sharp Tower, 206 South 13th Street, Lincoln NE 68508-2010   USA
Business & Sales: (402)477-9554  Support: (402)477-9562  Fax: (402)477-9559
Business info@microimages.com  Support support@microimages.com  Web webmaster@microimages.com

9 May 2008

page update: 14 Aug 07