Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# ParcelToolVB.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: 4-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.VBTestForm
# Variable declarations
class VECTORLAYER vectorLayer;
class Vector targetVector;
class GROUP activegroup;
class VBTestForm form;
class Database ParcelDB;
# 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;
}
}
else {
PopupMessage("Not a vector!");
valid = false;
}
return valid;
}
# Called when user presses 'left' pointer/mouse button.
func OnLeftButtonPress () {
# If the selected layer is not valid, don't do anything.
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 Dailog window
form.ElemID = parcelID$;
form.ShowDialog();
targetVector.Poly[elementNum].ParcelInfo.OwnerLastName$ = form.LastName;
targetVector.Poly[elementNum].ParcelInfo.OwnerFirstName$ = form.FirstName;
}
} # 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;
} # end of OnInitialize nitialize e