
! script name: wsccommon.d/retrieve
! topic: read entire stored job

!A
!A NAME:
!A
!A 	Open
!A
!A DESCRIPTION:
!A
!A 	This script allows the entire stored job to be read in or only the
!A 	geometry or the turbo post portion. (Current information will be
!A 	deleted.)
!A
!B INSTRUCTIONS:
!B
!B 	OPEN Entire, Geometry, Turbo info, Cnc tape or None
!B
!B 		E - Entire allows all stored information pertaining to a
!B 		    specified job to be brought in.
!B 		G - Geometry retrieves only the file with the geometry in it.
!B 		T - Turbo post info retrieves only turbo-post info.
!B 		C - CNC Info  (nc tape) retrieves only the nc tape file.
!B 		N - None allows the procedure to be ended.
!B
!B 	SELECT EXISTING JOB FILE: The selection box will
!B 		appear at this time for a selection to be made.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: open ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Dir$[256],Dir1$[256]
DIM D_label$[256]
DIM Sub_label$[256]
DIM F_label$[256]
DIM Choice$[256]
DIM Mask$[32]
DIM Header$[4096]
DIM Tmp$[256]
DIM Ac$[256]
DIM Jobname$[256]
DIM Jobs$(20,2)[256]
DIM Startup$[256]
DIM Setconstants$[256]
DIM Store_dir$[255],Retrieve_dir$[255],Pics_dir$[255]
DIM Iges_dir$[255],Dxf_dir$[255],Use_widget$[255]

DeActivateUndo
stat= NamedVarStr("startup script",WsSystemVars,"startup",Startup$)
stat= NamedVarStr("startup constants",WsSystemVars,"setconstants",SetConstants$)
Stat= NamedVarStr("storage dir",WsSystemVars,"/usr/weber/ST/",Store_dir$)
Stat= NamedVarStr("retrieve dir",WsSystemVars,"/usr/weber/ST/",Retrieve_dir$)
Stat= NamedVarStr("pics dir",WsSystemVars,"/usr/weber/ST/pics/",Pics_dir$)
Stat= NamedVarStr("iges storage dir",WsSystemVars,"/usr/weber/ST/iges/",Iges_dir$)
Stat= NamedVarStr("dxf storage dir",WsSystemVars,"/usr/weber/ST/dxf/",Dxf_dir$)
Stat= NamedVarStr("use iges widget",WsSystemVars,"no",Use_widget$)
Use_safe= NamedVarVal("use backup routine",WsSystemVars,0.0)
Time_check= NamedVarVal("time check",WsSystemVars,720.0)
Save_dirs= NamedVarVal("save dirs",WsSystemVars,0)

Answer$= StoredFileName
IF NOT LEN(Answer$) THEN

! Stat=SetInputFormat("a1=",",E,G,N,C,T,")
! Stat=SetEqualsValue(0,"E")
! Stat=GetValue("OPEN Entire, Geometry, Turbo info, Cnc tape or None",Answer$)
! IF (ExitScript(Destination$)) THEN Leave
Answer$="E"
Op_mode= POS("GETC",Answer$)

IF Answer$="N" THEN LOAD "typecontrol"

StdWorkplane

Stat= NamedVarStr("retrieve dir",WsSystemVars,"/usr/weber/ST/",Dir$)
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 EXISTING JOB FILE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN Leave
LowerFileBox
ELSE
	Name$= StoredFileName("")
	StdWorkplane
	Op_mode= 2
END IF
IF (POS(Answer$,".igs") OR POS(Answer$,".IGS")) THEN LOAD "wsccommon.d/importigs:"&Answer$
IF (POS(Answer$,".iges") OR POS(Answer$,".IGES")) THEN LOAD "wsccommon.d/importigs:"&Answer$
IF (POS(Answer$,".dxf") OR POS(Answer$,".DXF")) THEN LOAD "wsccommon.d/readdxf:"&Answer$
IF (POS(Answer$,".dwg") OR POS(Answer$,".DWG")) THEN LOAD "wsccommon.d/readdxf:"&Answer$

IF Op_mode=1 OR Op_mode=2 THEN DeleteAll
PlotOff
IF Op_mode>=1 THEN
	IF Op_mode< 4 THEN
		Stat= RemoveFile("synfile")
		Stat= RemoveFile("command_buffer")
		Stat= RemoveFile("tapelist")
		Stat= RemoveFile("timefile")
		Stat= RemoveFile("tempdata")
		Stat= RemoveFile("tempscript")
		Stat= RemoveFile("tempfile")
		Stat= RemoveDirFiles("./","*","command_file")
		Stat= RemoveDirFiles("./","*","notepad")
		Stat= RemoveDirFiles("./","*","",".gif")
		Stat= RemoveDirFiles("./","*","",".jpg")
		Stat= RemoveDirFiles("./","*","",".html")
		Stat= RemoveDirFiles("./","*","",".htm")
		Stat= RemoveDirFiles("./","*","",".hpgl")
		Stat= RemoveDirFiles("./","*","",".plt")
	END IF
	Stat= RemoveDirFiles("./","*","tapefile")
	Stat= RemoveDirFiles("./","*","tapefil")
END IF
Stat=ReadStoredFile(Answer$,Op_mode)
IF Save_dirs THEN Retrieve_dir$=PathNameDirectory(Answer$)
PlotOn

stat=ChangeLabelStr("websys",Answer$)

IF Op_mode=1 OR Op_mode=2 THEN
	V1=CreateVariable("startup script",WsSystemVars,Startup$)
	V1=CreateVariable("startup constants",WsSystemVars,SetConstants$)
	V1=CreateVariable("storage dir",WsSystemVars,Store_dir$)
	V1=CreateVariable("retrieve dir",WsSystemVars,Retrieve_dir$)
	V1=CreateVariable("pics dir",WsSystemVars,Pics_dir$)
	V1=CreateVariable("iges storage dir",WsSystemVars,Iges_dir$)
	V1=CreateVariable("dxf storage dir",WsSystemVars,Dxf_dir$)
	V1=CreateVariable("use iges widget",WsSystemVars,Use_widget$)
	V1=CreateVariable("use backup routine",WsSystemVars,Use_safe)
	V1=CreateVariable("time check",WsSystemVars,Time_check)
	V1=CreateVariable("save dirs",WsSystemVars,Save_dirs)
END IF

Stat= CurrentHeader(Header$)
IF LEN(Header$) THEN
        Head=ReadUserData(WsGeneralString,"HEADER",Header$)
        IF ValidGeometry(Head) THEN
		Stat=GetUserString(Head,"Accumulated Time:",Ac$)
		IF(POS(Answer$,".X_T") OR POS(Answer$,".x_t")) THEN Answer$=""
		Stat= PutUserString(Head,"File name:",Answer$)
		AccTime = VAL("0"&TRIM$(Ac$))
		V1=CreateVariable("accumulated time",WsSystemVars,AccTime)
		V1=CreateVariable("job start time",WsSystemVars,TIMEDATE)
		Enti= UserDataString(Head,Header$)
		Stat= FileHeader(Header$)
		Stat= DeleteEntity(Head)
        END IF
END IF

IF Op_mode<>4 THEN ResizeAll

Leave:!
LowerFileBox
Stat=SetInputFormat("n4","")

IF (NOT LEN(Destination$)) THEN
	 LOAD SetConstants$
ELSE
	 LOAD Destination$
END IF
END

