
! script name: operations.d/operationctrl
! topic: general read operation

!A
!A NAME:
!A
!A 	General Operation Control (Choose Operation)
!A
!A DESCRIPTION:
!A
!A	This script will call the necessary scripts to load the operation
!A	information from a certain directory.  The operation directory is
!A	passed directly into the script as ARGV(1).
!A	For user defined operations the directory name should end with .udf
!A	and reside in /usr/weber/util/tooldata/operations2_in(mm) or
!A	/usr/weber/util/tooldata/loperations_in(mm) for turning.
!A

stat=ChangeLabelStr("ScriptNameStatus","Function: general operation control (choose operation)")

COM /Ops_var_design/ Use_variational
DIM Description$[256],Destination$[256],Answer$[256],Dir$[256]
DIM File_name$[256],Tldir$[256],Ques$[256],Mask$[256]
DIM Which_tool$[256],Ref_tool$[256],Op_dir$[256]
DIM Namelist$[32000],Op_names$[512]
DIM Namelist2$[32000],Mask$[20]
DIM Current_op$[256],Check_flexops$[32000]

DeActivateUndo
Stat=NamedVarStr("current operation",WsSystemVars,"",Current_op$)
IF Current_op$="" THEN Current_op$="OPERATION DATA"
IF ARGC<2 THEN
	Use_variational= 0
ELSE
	Use_variational= VAL(ARGV(1))
END IF
IF ARGC>2 THEN
        IF ARGV(2)="user_defined" THEN Mask$="[ ,z]*.udf"
ELSE
        Mask$="*"
END IF

Stat=SetInputFormat("a99","")
Material=FindUserData("MATERIAL",WsMaterial)
IF NOT ValidGeometry(Material) THEN
        Stat= NamedVarStr("material dir",WsSystemVars,"/usr/weber/util/tooldata/materials/",Dir$)
        Stat=DirectoryNames(Dir$,"*",Namelist$)
        Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
	Stat=GeneralListBox("MATERIALS DIRECTORY","MATERIALS SELECTED",Namelist2$)

        Stat=GetValue("INPUT MATERIAL FILE NAME",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        File_name$= FileNameString(Dir$,Answer$)
        Material=ReadUserData(WsMaterial,"MATERIAL",File_name$)
END IF
LowerSelectBox

Stat= NamedVarStr("operations dir",WsSystemVars,"/usr/weber/util/tooldata/operations2_in/",Dir$)

Pick_direct:!
Stat=SetInputFormat("a99","")
Stat=DirectoryNames(Dir$,Mask$,Namelist$)
Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
IF NOT LEN(Namelist$) THEN Namelist2$="NONE CURRENTLY AVAILABLE,"
Stat=GeneralListBox("OPERATIONS DIRECTORY","DIRECTORY SELECTED",Namelist2$)

Stat=GetValue("INPUT OPERATION TYPE ",Op_dir$)
IF ExitScript(Destination$) OR Op_dir$="CANCEL" THEN Leave
Dir$= FileNameString(Dir$,Op_dir$)
IF NOT DoesFileExist(Dir$) THEN Leave

Stat=DirectoryNames(Dir$,"*",Namelist$)
Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
Stat=GeneralListBox("OPERATIONS","OPERATION SELECTED",Namelist2$)

Stat=GetValue("INPUT OPERATION ",Answer$)
IF ExitScript(Destination$) OR Answer$="CANCEL" THEN Leave
LowerSelectBox

Misc_group=GrpFindUserData("MISCELLANEOUS DATA TRANSFER",WsMiscData)
IF ValidGeometry(Misc_group) THEN Stat= DeleteGroup(Misc_group,1)

Op_group=GrpFindUserData("OPERATION DATA",WsOperation)
IF ValidGeometry(Op_group) THEN Stat= DeleteGroup(Op_group,1)

MiscData=ReadUserData(WsMiscData,"MISCELLANEOUS DATA TRANSFER",FileNameString(Dir$,Answer$))
IF NOT ValidGeometry(MiscData) THEN Leave

Stat=SetInputFormat("n4","")
Stat=UserDataString(MiscData,Check_flexops$)
IF POS(Check_flexops$,"SELECT") THEN
        LOAD "scenarios.d/checkselects:operations.d/loadoperdata"
ELSE
        LOAD "operations.d/loadoperdata"
END IF

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