Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# ParcelToolModal.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 GRE_VIEW View {use to access the view the tool script is attached to}
# class GRE_GROUP Group {use to access the group being viewed if the script is run from a group view}
# class GRE_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;
# 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 elementNum;
local string parcelID$;
# Check point.
point.x = PointerX;
point.y = PointerY;
point = TransPoint2D(point, ViewGetTransViewToScreen(View, 1));
point = TransPoint2D(point, ViewGetTransMapToView(View, vectorLayer.Projection, 1));
elementNum = FindClosestPoly(targetVector, point.x, point.y, GetLastUsedGeorefObject(targetVector));
if (elementNum > 0)
vectorLayer.Poly.HighlightSingle(elementNum);
parcelID$ = targetVector.Poly[elementNum].ParcelInfo.ParcelID$;
form.Clear(); # Clear fields in VB Dialog window
form.ElemID = parcelID$;
form.LastName = targetVector.Poly[elementNum].ParcelInfo.OwnerLastName$;
form.FirstName = targetVector.Poly[elementNum].ParcelInfo.OwnerFirstName$;
form.DoModal();
targetVector.Poly[elementNum].ParcelInfo.OwnerLastName$ = form.LastName;
targetVector.Poly[elementNum].ParcelInfo.OwnerFirstName$ = form.FirstName;
TableTriggerRecordChangedCallback( parceltable );
vectorLayer.UnhighlightAllElements( );
}
} # end of OnLeftButtonPress
# 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;
PopupMessage("Left-click in the View to select a parcel polygon.");
} # end of OnInitialize