TLINBYATT.sml

  Download

More scripts: Display Toolbar

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
#  TLINBYATT.SML - For TIGER Line vector objects
#	Allows user to select line and highlights all lines with same Class attribute.
#  Created by: Randy Smith
#  Most recent revision: 8-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.
#    numeric PointerX            Pointer X coordinate within view in pixels
#    numeric PointerY            Pointer Y coordinate within view in pixels
# Variable declarations
class GRE_LAYER_VECTOR vectorLayer;
class Vector targetVector;
class GRE_GROUP activegroup;
# 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.NumLines < 1 ) {
			PopupMessage( "No lines!" );
			valid = false;
			}
		}
	else {
		PopupMessage( "Not a vector!" );
		valid = false;
		}
	return valid;
	}  # end of checkLayer
# Called when user presses 'left' pointer/mouse button.
proc 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 att$;
		local numeric line;
		local array elemnums[0];
		local numeric count = 0;
		# Check point.
		point.x = PointerX;
		point.y = PointerY;
		point = TransPoint2D( point, ViewGetTransViewToScreen( View, 1 ) );
		point = TransPoint2D( point, ViewGetTransMapToView( View, vectorLayer.Projection, 1 ) );
		elementNum = FindClosestLine( targetVector, point.x, point.y, GetLastUsedGeorefObject( targetVector ) );
		if (elementNum > 0)
			att$ = targetVector.line[elementNum].Class_Codes.CFCC$;
			for line = 1 to NumVectorLines( targetVector ) {
				if ( targetVector.line[line].Class_Codes.CFCC$ == att$ ) {
					count += 1;
					ResizeArrayPreserve( elemnums, count );
					elemnums[ count ] = line;
					}
				}
			vectorLayer.Line.HighlightMultiple( count, elemnums );
		}
	}  # 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.
proc OnInitialize () {
	if (Layout) {
		WidgetAddCallback( Layout.GroupSelectedCallback, cbGroup );
		activegroup = Layout.ActiveGroup;
		}
	else
		activegroup = Group;
	PopupMessage("Left-click in the View to select the nearest line\n and all lines with the same attribute.");
	}  # end of OnInitialize