
! script name: v4axisturn.d/removesyncpts
! var_topic: remove sync points

!A
!A NAME:
!A	
!A	Remove sync points VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script removes sync points from a four axis lathe path.
!A	Sync points are used to syncronize the motion of the two independent
!A	turrets on the lathe.
!A
!B INSTRUCTIONS:
!B
!B	PICK PATH FOR SYNC POINTS: Pick the lathe path that the 
!B				sync points are on.
!B
!B	PICK SYNC POINT,  All, Show, New, Exit: Pick the Sync point to be
!B				removed. All will remove all the sync points
!B				on that path. If an Undo/Redo is performed
!B				then Show will update the graphics.
!B				New selects a new lathe path.
!B				Exit will leave the script.
!B			
!B
!C NOTE:
!C
!C	The free parameter Sync point # is the numerical order 
!C	of the sync point in its occurance along
!C	the contour not the number assigned to the sync point which 
!C	may change. If the cutter path is changed this number may no
!C	longer correspond to the sync point which is to be removed.
!C	In that case the free parameter must be edited.
!C
!C      This script is variational is should only be used on paths
!C      created variationally. Failure to do this will result in
!C      multiple occurances of the sync points.
!C
!# see also - htdocs/help.d/fouraxisturn.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: Remove sync points ")

DIM Answer$[256]
DIM Destination$[256]
DIM Contour$[256]
DEG

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave
stat= SetInputFormat("n4","")

Pen_color= 3

ActivateUndo
Pick_contour: !
Stat=SetInputFormat("n4","")
Contour=PickGroupEnt("PICK PATH FOR SYNC POINTS")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
IF IsEntVariational(Contour)= WsFalse THEN
	Stat= MessageStringBox("Path must be variational","Warning")
	GOTO Pick_contour
END IF
Stat=EntityNameCheck(Contour,Contour$)

Stat= DeleteGroup(Syncpts,WsTrue)
Syncpts= ContourSyncPoints(Contour)
Stat= SetForceVisible(Syncpts,WsTrue)
Stat= SetColor(Syncpts,Pen_color)
IF NOT ValidGeometry(Syncpts) THEN Pick_contour

Pick_loop: !
ActivateUndo
Stat=SetInputFormat("a1",",A,S,E,N,")
Element=PickEntity("PICK SYNC POINT,  All, Show, New, Exit ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "A" 
	Stat= DeleteGroup(Syncpts,WsTrue)
	ActivateUndo
	Stat= AdvanceUndoNumber("remove contour sync pts")
	Stat= AddGroupToUndo(WsUBModifyMode,Contour,1,WsTrue)

	RecordFunctionOn
	Stat=RecordDescr("FOUR AXIS TURN: Remove path sync points")
	Stat= RemoveSyncPoints(Contour$)
	RecordFunctionOff
	Curr_record= CurrentVarRecord
	CloseVarRecord

        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

	Syncpts= ContourSyncPoints(Contour)
	Stat= SetForceVisible(Syncpts,WsTrue)
	Stat= SetColor(Syncpts,Pen_color)
	GOTO Pick_contour
CASE "N"
	Stat= DeleteGroup(Syncpts,WsTrue)
	GOTO Pick_contour
CASE "E"
	GOTO Leave
CASE "S"
	Stat= DeleteGroup(Syncpts,WsTrue)
	Syncpts= ContourSyncPoints(Contour)
	Stat= SetForceVisible(Syncpts,WsTrue)
	Stat= SetColor(Syncpts,Pen_color)
	GOTO Pick_loop
CASE ELSE
	PlotOff
	T1= LastPickPara
	P1= ParameterPt(Element,T1)
	N= ClosestSyncPtNum(Contour,P1,1)
	Stat= DeleteEntity(P1)
	PlotOn
	IF N THEN
		Element= SyncPointEntity(Contour,N)
		Stat= DeleteGroup(Syncpts,WsTrue)
		ActivateUndo
		Stat= AdvanceUndoNumber("Remove sync pt")
		Stat= AddItemToUndo(WsUBModifyMode,Element)

		RecordFunctionOn
        	Stat=RecordDescr("FOUR AXIS TURN: Remove sync point")
		V1= FreeParameter("Sync point #",N)
		Stat= DeleteSyncPoint(Contour$,V1)
        	RecordFunctionOff
		Curr_record= CurrentVarRecord
        	CloseVarRecord

        	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
	END IF
END SELECT

Stat= DeleteGroup(Syncpts,WsTrue)
Syncpts= ContourSyncPoints(Contour)
Stat= SetForceVisible(Syncpts,WsTrue)
IF NOT ValidGeometry(Syncpts) THEN Pick_contour
Stat= SetColor(Syncpts,Pen_color)
GOTO Pick_loop

Leave:!
PlotOn
Stat= DeleteGroup(Syncpts,WsTrue)
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END


