
! script name: vproperty.d/vcontsegfeedfr
! VAR_TOPIC: set feed rate factor contour segment

!A
!A NAME:
!A
!A 	Contour Feed Factor	VARIATIONAL
!A
!A DESCRIPTION:
!A	
!A 	Set rate factor on a contour segment.
!A

stat=ChangeLabelStr("ScriptNameStatus","Function: contour segment feed rate factor")

DIM Destination$[256]
DIM Answer$[256]
DIM Factor_var$[256]
DIM Contour$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Name1$[256]
DIM Name2$[256]
DIM Descr$[256]

Feed_factor=1.0
Pen_color= 19
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

Start:!
DeActivateUndo
Stat= SetInputFormat("n4=","")
Stat= SetEqualsValue(Feed_factor)
Feed_factor= GetValue("FEED RATE FACTOR ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_factor_var=LastVariableInput(Factor_var$)

Pick_contour: !
Contour=PickGroupEnt("PICK CONTOUR ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
Stat=EntityNameCheck(Contour,Contour$)

Pick_start: !
Stat= SetInputFormat("a1",",S,")
E1=PickEntity("PICK FIRST POINT, Start point ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "S" THEN
	Point1$= ""
ELSE
	IF NOT ValidDependency(E1) THEN Pick_start
	T1=LastPickPara
	Pick_return1=CurrPickReturn
	Stat=EntityNameCheck(E1,Point1$)
	Ps=ParameterReturnPt(E1,T1,Pick_return1)
	Stat=SetLastPoint(Ps)
END IF

Pick_end: !
Stat= SetInputFormat("a1",",E,")
E2=PickEntity("PICK LAST POINT, End point ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "E" THEN
	Point2$= ""
ELSE
	IF NOT ValidDependency(E2) THEN Pick_end
	T2=LastPickPara
	Pick_return2=CurrPickReturn
	Stat=EntityNameCheck(E2,Point2$)
	Pe=ParameterReturnPt(E2,T2,Pick_return2)
	Stat=SetLastPoint(Pe)
END IF

Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)


Stat=GenerateVarName(WsVarRecordEnt,Name1$)
Stat=GenerateVarName(WsVarRecordEnt,Name2$)
Descr$= "MACHINING: Contour Segment Feed Factor = "&VAL$(Feed_factor)
RecordFunctionOn
Stat=RecordDescr(Descr$)
IF LEN(Point1$) THEN
   SELECT Pick_return1
       CASE WsGeometryEnd
           Ps=ParameterReturnPt(Point1$,T1,WsGeometryEnd)
       CASE WsGeometryMid
           Ps=ParameterReturnPt(Point1$,T1,WsGeometryMid)
       CASE WsGeomCenter
           Ps=ParameterReturnPt(Point1$,T1,WsGeomCenter)
   END SELECT
   E1=SplitContElement(Contour$,Ps)
   Stat= NameEntity(E1,Name1$)
END IF
IF LEN(Point2$) THEN
   SELECT Pick_return2
       CASE WsGeometryEnd
           Pe=ParameterReturnPt(Point2$,T2,WsGeometryEnd)
       CASE WsGeometryMid
           Pe=ParameterReturnPt(Point2$,T2,WsGeometryMid)
       CASE WsGeomCenter
           Pe=ParameterReturnPt(Point2$,T2,WsGeomCenter)
   END SELECT
   E2=SplitContElement(Contour$,Pe)
   Stat= NameEntity(E2,Name2$)
END IF
IF LEN(Point1$) AND LEN(Point2$) THEN
	G1= ContourSubGroup(Contour$,Ps,Pe)
	Stat=DeleteEntity(Ps)
	Stat=DeleteEntity(Pe)
ELSE
	IF LEN(Point1$) AND (NOT LEN(Point2$)) THEN
		G1= ContourSubGroup(Contour$,Ps,0)
		Stat=DeleteEntity(Ps)
	ELSE
		IF (NOT LEN(Point1$)) AND  LEN(Point2$) THEN
			G1= ContourSubGroup(Contour$,0,Pe)
			Stat=DeleteEntity(Pe)
		ELSE
			G1= ContourSubGroup(Contour$,0,0)
		END IF
	END IF
END IF
IF No_factor_var THEN
        V1=FreeParameter("Factor",Feed_factor)
ELSE
        V1=FreeParameter("Factor",Factor_var$)
END IF
Stat= SetFeedFactor(G1,V1)
IF Pen_color THEN
        V2=FreeParameter("Color",Pen_color)
	Stat= SetColor(G1,V2)
END IF
Stat=DeleteEntity(G1)
RecordFunctionOff
CloseVarRecord

GOTO Pick_contour



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