
! script name: events.d/eventdata
! topic: Sample - select event

!A
!A NAME:
!A
!A 	Events
!A
!A DESCRIPTION:
!A
!A 	Select an event to include in the AMO task list.  An event can
!A	be used to output code to the command_file in between tools
!A 	The TurboPost can then interpret this event.
!A	If the Process Table is in use, events may be inserted into
!A	the Process Table.
!A
!B INSTRUCTIONS:
!B
!B	CHOOSE EVENT TO LOAD, Deletion.  This allows you to choose the
!B	event that you want to load or a sub directory.  This list will
!B	only show those events that have not yet been read into the
!B	system.  Deletion allows you to delete an event once it has
!B	been read into the system. 
!B
!B	Events output instructions to the command file in between 
!B	selected tasks. An event can OUTPUT a line of CNC code,
!B	they can be used to ASSIGN a value to a turbo post variable,
!B	and they can be used to call a turbo post MACRO.
!B	Here is an example event to output M00.
!B
!B		Event name:      M00 Stop
!B		Event type:      OUTPUT
!B		Event data:      M00 ( *** Program Stop *** )
!B	
!B	Here is a sample event to turn on step mode. It sets a turbopost
!B	variable.
!B
!B		Event name:  Turn on step mode
!B		Event type:  ASSIGN:
!B		Event data:  Step_on=1;
!B
!B	Events are ASCII files located in the following folder:
!B		C:/usr/weber/util/eventdata/events
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: read an event ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM File_name$[256],Dir$[256],D_label$[256],Choice$[256],Mask$[32]
DIM Namelist$[8000],Namelist2$[8000]
DIM New_dir$[256]

WsEventData= 12345

DeActivateUndo
Stat= NamedVarStr("events dir",WsSystemVars,"/usr/weber/util/eventdata/events/",Dir$)
D_label$="EVENTS DIRECTORY"
Choice$="EVENT SELECTED"
Mask$="*"

Start:!
New_dir$= FileNameString(Dir$)
File_name$= Dir$

Event_name:!
Stat= DirectoryNames(New_dir$,Mask$,Namelist2$)
Stat= AlphabeticalOrder(Namelist2$,",",WsAscending,Namelist$)

I= 1
LOOP
	Stat= StringFieldStr(Namelist$,",",I,Answer$)
	EXIT IF NOT LEN(Answer$)
	Name$= ExtUserDataStr(FileNameString(New_dir$,Answer$),"Event name:")
	EntData= FindUserData(Name$,WsEventData)
	IF ValidGeometry(EntData) THEN
		Stat= RemoveFromList(Answer$,Namelist$,Namelist2$)
		Namelist$= Namelist2$
	ELSE
		I= I+1
	END IF
END LOOP

IF NOT LEN(Namelist$) THEN
	IF New_dir$= FileNameString(Dir$) THEN Leave
	New_dir$= PathNameDirectory(New_dir$)
	GOTO Event_name
END IF
Stat= GeneralListBox(D_label$,Choice$,Namelist$)

File_name:Stat= SetInputFormat("a99","")
Stat= GetValue("CHOOSE EVENT TO LOAD, Deletion ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF UPC$(Answer$)="DELETION" OR UPC$(Answer$)="D" THEN
	Destination$= "delete.d/deleteevent"
	GOTO Leave
END IF
IF NOT LEN(Answer$) THEN File_name
IF Answer$="CANCEL" THEN
	IF New_dir$= FileNameString(Dir$) THEN Leave
	New_dir$= PathNameDirectory(New_dir$)
	GOTO Event_name
END IF

File_name$= FileNameString(New_dir$,Answer$)
IF DoesFileExist(File_name$)=2 THEN
	File_name$= New_dir$
	New_dir$= FileNameString(New_dir$,Answer$)
	GOTO Event_name
END IF
New_dir$= PathNameDirectory(File_name$)

Event= ReadUserData(WsEventData,"temp",File_name$)
IF NOT ValidGeometry(Event) THEN Event_name
Stat= GetUserString(Event,"Event name:",Name$)
Exists= FindUserData(Name$,WsEventData)
IF NOT ValidGeometry(Exists) THEN
	Stat= ChangeDataName(Event,Name$)
ELSE
	Stat= DeleteEntity(Event)
END IF

GOTO Event_name

Leave:!
LowerSelectBox
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

