home products news downloads documentation support gallery online maps resellers search
TNTmips Downloads Menu

HOME

CONTACT US

CURRENT RELEASE
  TNT 2013

DEVELOPMENT VERSION
  TNT 2014

TNTmips Pro
PRIOR RELEASES
  TNT 2012

FREE SOFTWARE
  TNTmips Free
  TNTatlas
  TNTsdk

MORE DOWNLOADS
  HASP Key Driver
  Screen Recorder
  TNT Language Kits
  Sample Geodata
  TNT Scripts

DOCUMENTATION
  TNTmips Tutorials
  Tutorial Datasets
  Technical Guides
  Scripts
  Quick Guides

MORE INFO
  Download FAQs
  FTP
  Download Managers
  Find Reseller

SITE MAP


pointsel.sml

See other examples of Tool and Macro scripts ...


#  POINTSEL.SML -

# View ToolScript
# Allows user to select and highlight a vector point.

#  Authors: Mark Smith and Randy Smith
#  Most recent revision: 6 May 2008

#  Requires version 2007:73 or later of the TNT products

	# 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}
	#    numeric ToolIsActive           Will be 0 if tool is inactive or 1 if tool is active
	#
	# 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
	#    numeric ShiftPressed        1 if  key being pressed or 0 if not
	#    numeric CtrlPressed         1 if  key being pressed or 0 if not
	#    numeric LeftButtonPressed   1 if left pointer button pressed or 0 if not
	#    numeric RightButtonPressed  1 if right pointer button pressed or 0 if not
	#    numeric MiddleButtonPressed 1 if middle pointer button pressed or 0 if not

### GLOBAL VARIABLES
class GRE_LAYER_VECTOR vectorLayer;
class RVC_VECTOR targetVector;
class GRE_GROUP activegroup;
class RVC_GEOREFERENCE vecGeoref;


###################################################################################
##############   USER-DEFINED FUNCTIONS AND PROCEDURES   ##########################
###################################################################################

# 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 );
		targetVector.GetDefaultGeoref(vecGeoref);

		if ( targetVector.$Info.NumPoints < 1 ) {
			PopupMessage("No points!");
			valid = false;
			}
		}
	else {
		PopupMessage( "Not a vector!" );
		valid = false;
		}
	return valid;
	}  # end of checkLayer();

### Callback for when the active layer changes.
proc cbLayer()
	{
	checkLayer();
	}

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

##################################################################################
# The following script functions will be called (if used in the script) when
# the appropriate action or event occurs as described in the comments before each.
# To use a function, uncomment the lines containing the 'func' definition
# and ending brace '}' by removing the leftmost '#' on the line and add the
# function code between the two lines.

# 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 class TRANS2D_MAPGEN trans;	# coordinate transformation parameters

		# Check point.
		point.x = PointerX;
		point.y = PointerY;

		# convert point position from screen coordinates to map coordinates for the targetVector
		trans = View.GetTransViewToScreen(1);	# transformation from screen to view coordinates
		point = trans.ConvertPoint2DFwd(point);
		trans = View.GetTransMapToView(vecGeoref.GetCoordRefSys(), 1);	# transformation from view to layer map coordinates
		point = trans.ConvertPoint2DFwd(point);		

		elementNum = FindClosestPoint( targetVector, point.x, point.y, GetLastUsedGeorefObject( targetVector ) );

		if (elementNum > 0)
			vectorLayer.Point.HighlightSingle( elementNum );
		}
	}  # end of OnLeftButtonPress


# 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 point.");

	}  # end of OnInitialize


# Called when tool is activated.
# If the tool implements a dialog it should be "managed" (displayed) here.
proc OnActivate ()
	{
	checkLayer();
	}  # end of OnActivate


# Called when tool is deactivated (usually when switching to another tool).
# If the tool implements a dialog it should be "unmanaged" (hidden) here.
proc OnDeactivate ()
	{
	if (activegroup.ActiveLayer.Type == "Vector") then
		activegroup.ActiveLayer.UnhighlightAllElements();
	}  # end of OnDeactivate


# Called when tool is to be 'suspended' during a redraw operation.
# proc OnSuspend () {
# }  # end of OnSuspend

# Called when tool is to be 'resumed' after a redraw operation.
# If the tool displays any graphics they should be updated by this function.
# proc OnResume () {
# }  # end of OnResume

# Called when user presses 'right' pointer/mouse button.
# proc OnRightButtonPress () {
# }  # end of OnRightButtonPress

# Called when user presses 'middle' pointer/mouse button.
# proc OnMiddleButtonPress () {
# }  # end of OnMiddleButtonPress

# Called when user releases 'left' pointer/mouse button.
# proc OnLeftButtonRelease () {
# }  # end of OnLeftButtonRelease

# Called when user releases 'right' pointer/mouse button.
# proc OnRightButtonRelease () {
# }  # end of OnRightButtonRelease

# Called when user releases 'middle' pointer/mouse button.
# proc OnMiddleButtonRelease () {
# }  # end of OnMiddleButtonRelease

# Called when user moves cursor if no button being pressed
# proc OnPointerMoveNoButton () {
# }  # end of OnPointerMoveNoButton

# Called when user moves cursor while holding down button
# proc OnPointerMoveWithButton () {
# }  # end of OnPointerMoveWithButton

# Called when cursor enters window associated with view.
# proc OnEnterWindow () {
# }  # end of OnEnterWindow

# Called when cursor leaves window associated with view.
# proc OnLeaveWindow () {
# }  # end of OnLeaveWindow

# Called when user presses 'key' on keyboard.
# proc OnKeyPress (key) {
# }  # end of OnKeyPress


 


Back Home ©MicroImages, Inc. 2013 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

25 March 2009

page update: 26 May 11