! script name: conv_parabolas
! topic: Custom script to convert parabolic interpolation to linear
!A	
!A	NAME:  Convert Parabolas
!A	
!A	DESCRIPTION:
!A	This script converts parabolic interpolation (G6) into linear moves.
!A	
!A	The source tape file can be in either decimal or trailing zero format.
!A	The converted tape is in decimal format.
!A	The convert function will sense the input format based on finding a
!A	decimal point in X, Y or Z axis numbers in the first 100 blocks.
!A	
!A	The input file name determines the output and offset filenames by
!A	finding the extension ( i.e .nc ) and replacing it with .cg6 for
!A	the output name and .oft for the offset name.
!A
!A	When you run this script, only the G6 Blocks are replaced. The other
!A	blocks are not modified, except to convert trailing to decimal and 
!A	add the offset amounts.
!A	The X,Y,Z,I,J,K words are converted to decimal if necessary.
!A	
!A	The approximate chord height is specified by the tolerance.  This should
!A	be treated as an estimate. The tolerance specified should always be
!A	smaller than the tolerance needed for machining.  No matter what the
!A	tolerance, a parabola is replaced by at least two lines. The size of
!A	the converted tape file may be several times the size of the source
!A	file depending on the tolerance.
!A	
!A	\E<Directory>/conv_parabolas
!A	
!A	Examples:
!A	To run the script with default modes from the misc.d directory, enter:
!A	\Emisc.d/conv_parabolas
!A	
!A	The parabolic curves created from the G6 are constructed by the method
!A	outlined in the machine manual (diagram 4.2).  The parabolic curves are
!A	then interpolated by straight lines using the given tolerance.  The
!A	parabolic curves are represented by a nurb curve of degree 2.  The
!A	construction creates the nurb curve identical to the parabola. In
!A	Synergy, we represent parabolic curves with nurb curves.
!A	All curves generated by polynomial interpolation can be represented
!A	exactly by nurbs.
!A	
!A	

stat=ChangeLabelStr("ScriptNameStatus","Function: convert parabolas ")

DIM Inputname$[256]
DIM Output_file$[256]
DIM Answer$[256]
DIM Destination$[256]
DIM Fileline$[2048]
DIM Fileline1$[2048]
DIM Filename$[256]
DIM Offset_file$[256]
DIM Tempdata$[256]
DIM Tapeline$[512]
DIM Dir$[512]
DIM Dir1$[512]
DIM D_label$[256]
DIM Sub_label$[256]
DIM F_label$[256]
DIM Choice$[256]
DIM Mask$[32]
DIM A$[256],B$[256],C$[256]
DIM Comments$[512]
DEG

StdWorkplane

Tol=NamedVarVal("3D Cutting Tol",Ws3DSystemVars,0.001)

Input_name:!
Stat= NamedVarStr("retrieve dir",WsSystemVars,"/usr/weber/ST/",Dir$)
IF (OSystemId=0) THEN      ! NT
        Stat= ReplaceString(Dir$,"/","\\",Dir1$)
        Stat= DisplayMessage("CHOOSE SOURCE TAPE FILE FROM FILE BOX")
        LOOP
            Stat= StartProcess("/mksnt/filebox -a -d "&Dir1$&" >/tmp/filename")
            IF Stat THEN Leave
	    Stat= GetFileLine("/tmp/filename",1,Inputname$)
            IF NOT Stat THEN 
            	Stat= DisplayMessage("ERROR ACCESSING FILE ")
            	Leave_loop= 0
	    ELSE
        	Stat= ReplaceString(Inputname$,CHR$(13),"",Answer$)
            	Leave_loop= 1
	    END IF
            EXIT IF Leave_loop
        END LOOP
        Stat= ReplaceString(Dir1$,"\\","/",Dir$)
	Inputname$= Answer$
ELSE                    !HP
        D_label$="DIRECTORY"
        Sub_label$="SUB DIRECTORIES"
        F_label$="FILES"
        Choice$="FILE TO OPEN"
        Mask$="[A-Za-z0-9]*"

   	Stat=UserFileBox(Dir$,Mask$,D_label$,Sub_label$,F_label$,Choice$,"Synergy")
        Stat=SetInputFormat("a99","")
        Stat=GetValue("SELECT SOURCE TAPE FILE",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        IF Answer$= "CANCEL" THEN Leave
        LowerFileBox
	Inputname$= Answer$
END IF


Output_name:!
P=POS(Inputname$,".")
IF P>1 THEN
Output_file$=Inputname$[1,P-1]&".cg6"
ELSE
Output_file$=Inputname$&".cg6"
END IF


Offset_name:!
P=POS(Inputname$,".")
IF P>1 THEN
Offset_file$=Inputname$[1,P-1]&".oft"
ELSE
Offset_file$=Inputname$&".oft"
END IF

! Format of ConvertPW is (tolerance,inputfile,outputfile,offsetfile)
Stat=ConvertPWG06File(Tol,Inputname$,Output_file$,Offset_file$)

Leave:!

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
