
! script name: edit.d/edittypeend
! topic: edit end point of a type

!A
!A NAME:
!A
!A 	Edit Type End
!A
!A DESCRIPTION:
!A
!A 	This script allows the end point of a type to be modified.
!A 	If a contour is open, the start point of the first type may
!A 	be edited by picking an element close to it.  Otherwise, it
!A 	will only be the end point of the type that may be modified.
!A 	Remember, the start point of a type is the end point of the last
!A 	type defined, except for the first type defined on an open contour.
!A
!B INSTRUCTIONS:
!B
!B 	PICK TYPE TO BE EDITED: Pick an element on the type to be modified.
!B
!B 	STARTING ABS X,Y: Enter the new X,Y coordinates of the start point
!B 		of the type to be modified.  This question will only be
!B 		asked if an element near the start point of an open contour
!B 		is selected.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	ENDING ABS X,Y: Enter the new X,Y coordinates of the end point
!B 		of type to be modified.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: edit type end ")

DIM Destination$[256]
DIM Answer$[256]


DeActivateUndo
Ploop:!
T1=PickTypeEnt("PICK TYPE TO BE EDITED")
IF (ExitScript(Destination$)) THEN Leave
E1=LastPickEnt

Which_end=EditWhichEnd(T1,E1)

Stat=HighlightType(T1,WsTypesPen)

IF (Which_end=WsStart) THEN
	Pstart=TypeEndPoint(T1,WsStart)
	Pend=TypeEndPoint(T1,WsEnd)
	Stat=SetLastPoint(Pstart,WsXyOnly)

	Stat=SetEditPoint(Pstart)
	Ps=XyzInput("STARTING",WsXyOnly)
	IF (ExitScript(Destination$)) THEN Leave

	X=XPointValue(Ps)
	Y=YPointValue(Ps)

	Stat=EditTypeValue(T1,WsEditXStart,X)
	Stat=EditTypeValue(T1,WsEditYStart,Y)
ELSE
	Ps=TypeEndPoint(T1,WsStart)
	Pend=TypeEndPoint(T1,WsEnd)
	Stat=SetLastPoint(Ps,WsXyOnly)

	Stat=SetEditPoint(Pend)
	Pe=XyzInput("ENDING",WsXyOnly)
	IF (ExitScript(Destination$)) THEN Leave

	X=XPointValue(Pe)
	Y=YPointValue(Pe)

	Stat=EditTypeValue(T1,WsEditXEnd,X)
	Stat=EditTypeValue(T1,WsEditYEnd,Y)
END IF

Stat=CalculateType(T1)


Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Pend)
Stat=DeleteEntity(Pstart)
GOTO Ploop

Leave:!
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Pend)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
