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


ParcelToolModeless.sml

See other examples of Tool and Macro scripts ...


#  ParcelToolModeless.SML - Allows user to select and highlight a vector polygon
#	representing a parcel.  Script opens a Visual Basic form showing the
#  parcel ID from the selected polygon.  User enters Last Name and First
#  Name in the Visual Basic form and the database is updated.

#  Created by: Randy Smith
#  Most recent revision: 9-2003

# The following symbols are predefined
#    class VIEW View            {use to access the view the tool script is attached to}
#    class GROUP Group          {use to access the group being viewed if the script is run from a group view}
#    class LAYOUT Layout        {use to access the layout being viewed if the script is run from a layout view} 
# 
# The following values are also predefined and are valid when the various On...() 
# functions are called which deal with pointer and keyboard events. 
#    number PointerX            Pointer X coordinate within view in pixels 
#    number PointerY            Pointer Y coordinate within view in pixels 

$import MicroImages_SML_OLE_Demo_EXE.VBForm

# Variable declarations
class GRE_LAYER_VECTOR vectorLayer;
class Vector targetVector;
class GRE_GROUP activegroup;
class VBForm form;
class Database ParcelDB;
class DBTABLEINFO parceltable;
numeric elementNum;

# Checks layer to see if it is valid.
func checkLayer() {
	local numeric valid = true;

	# Get names layers if usable.  If not output error messages.
	# Get name of active layer if it is usable.  If not output an error message.
	if (activegroup.ActiveLayer.Type == "") {
		PopupMessage("Group has no layers!");
		valid = false;
		}
	else if (activegroup.ActiveLayer.Type == "Vector") {
		vectorLayer = activegroup.ActiveLayer;
		DispGetVectorFromLayer(targetVector, vectorLayer);
		if (targetVector.$Info.NumPolys < 1) {
			PopupMessage("No polygons!");
			valid = false;
			}
		parceltable = TableGetInfo( targetVector.Poly.ParcelInfo );
		}
	else {
		PopupMessage("Not a vector!");
		valid = false;
		}
	return valid;
	}

# Called when user presses 'left' pointer/mouse button. 
func OnLeftButtonPress () { 
	# If the selected layer is valid, proceed.
	if (checkLayer()) {
		# Set local variables
		local class POINT2D point;
		local numeric num;
		local string parcelID$;

		# get screen coordinates from cursor and transform to layer coordinates.
		point.x = PointerX;
		point.y = PointerY;

		point = View.GetTransLayerToScreen(vectorLayer).ConvertPoint2DInv(point);

		num = FindClosestPoly(targetVector, point.x, point.y, GetLastUsedGeorefObject(targetVector));

		if (num > 0) {
			elementNum = num;
			vectorLayer.Poly.HighlightSingle(elementNum);	# highlight selected polygon
			parcelID$ = targetVector.Poly[elementNum].ParcelInfo.ParcelID$;

			form.Clear();			# Clear fields in Visual Basic dialog window

			# assign values for fields in form from attributes of selected polygon
			form.ElemID = parcelID$;
		   form.LastName = targetVector.Poly[elementNum].ParcelInfo.OwnerLastName$;
	      form.FirstName = targetVector.Poly[elementNum].ParcelInfo.OwnerFirstName$;

			form.ShowDialog();	# open the Visual Basic form as modeless dialog

			}
      }
	}  # end of OnLeftButtonPress 

# function called when Apply button on Visual Basic dialog is pressed
func OnApply () {
	if (elementNum > 0) {
			# set values in parcel table from info entered in Visual Basic form
			targetVector.Poly[elementNum].ParcelInfo.OwnerLastName$ = form.LastName;
			targetVector.Poly[elementNum].ParcelInfo.OwnerFirstName$ = form.FirstName;

			# notify RVC that the table has changed and unhighlight all elements
			TableTriggerRecordChangedCallback( parceltable );
			vectorLayer.UnhighlightAllElements( );
			}
	}

# function called when Close button on Visual Basic dialog is pressed
func OnClose () {
	View.SetDefaultTool();	# reset tool icon buttons on View when close VB dialog closes
	}

# Callback for when the active group changes.
proc cbGroup() {
	activegroup = Layout.ActiveGroup;
	}

# Called the first time the tool is activated.
# If the tool implements a dialog it should be created (but not displayed) here.
func OnInitialize () {
	if (Layout) {
		WidgetAddCallback( Layout.GroupSelectedCallback, cbGroup );
		activegroup = Layout.ActiveGroup;
		}
	else
		activegroup = Group;

		# register callback functions in SML script with the Visual Basic dialog
  		form.SetOnApply( OnApply );
		form.SetOnClose( OnClose );

	PopupMessage("Left-click in the View to select a parcel polygon.");

	}  # end of OnInitialize

func OnActivate() {
	form.ShowDialog();
	}

func OnDeactivate() {
	form.HideDialog();
	}





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: 10 Aug 07