
! script name: filing.d/exportigscur
! topic: export current geometry to iges

!A
!A NAME:
!A
!A 	EXPORT TO IGES: Current Geometry
!A
!A DESCRIPTION:
!A
!A 	This script converts the current Synergy geometry into an IGES
!A 	ascii data file.
!A
!B INSTRUCTIONS:
!B
!B 	IGES FILE NAME: Enter the name of the IGES file to be created.
!B
!B 	VARIOUS QUESTIONS: These questions provide imformation to the
!B 		iges process for the startup and globals record sections.
!B		Default fills in all global questions with default answers.
!B
!B	LAYER NUMBERS, Current, All
!B		Individual layers can be included by providing a comma
!B		separated list of the desired layers. ( i.e. 101,102,203 )
!B		If any layer is negative, all stated layers will be excluded.
!B		Answering Current will pass the current plot layers.
!B		Answering All will pass all layers.


DIM A$[256],Answer$[256],C$[256],Destination$[256],Default$[256]
DIM Sub_label$[256],Mask$[32],D_label$[32]
DIM Syn_name$[256],Igs_name$[256],Igs_fullname$[256],Global_file$[256],Start_file$[256]
DIM Todir$[256]
DIM Start_rec$[120]
DIM Pass$[4096],Layer$[4096]

Stat=ChangeLabelStr("ScriptNameStatus","Function: export to iges ")

!C
!C 	Switches:
!C
!C 		Show_Global_data: 1 show global data; 0 don't
!C 		Show_error_data: 1 show error data; 0 don't
!C 		Todir$ points to the iges file directory
!C

Show_global_data=1
Show_error_data=1
Stat= NamedVarStr("iges storage dir",WsSystemVars,"/usr/weber/ST/iges/",Todir$)

DeActivateUndo
Mask$="[A-Za-z0-9]*"

D_label$="DIRECTORY"
Sub_label$="SUB DIRECTORIES"
F_label$="FILES"
Output_to_file=0
Syn_name$="/tmp/synout"

Iges_name:C$="IGES FILE NAME"
GOSUB Question

Igs_name$=Answer$
Igs_fullname$=RPT$(Todir$,NOT POS(Igs_name$,"/"))&Igs_name$

ON ERROR GOTO Start_file
ASSIGN @File TO Igs_fullname$
ASSIGN @File TO *

Stat=GeneralListBox("EXPORT IGES INFO","SELECTION","STORE ANYWAY,NEW NAME,")
C$=Igs_name$&" ALREADY EXISTS IN "&Todir$
GOSUB Question
LowerSelectBox
IF Answer$="STORE ANYWAY" THEN 
	ON ERROR GOTO Skip_purge
	Stat= RemoveFile(Igs_fullname$)
Skip_purge:OFF ERROR
	GOTO Start_file
END IF
GOTO Iges_name

Start_file:ON ERROR GOTO Sfile_error
Start_file$="start_recs"
Start_recs:ASSIGN @File TO Start_file$
OFF ERROR
ASSIGN @File TO *
Stat= RemoveFile(Start_file$)
Start_cr:CREATE ASCII Start_file$,1
ASSIGN @File TO Start_file$
GOTO Start
Sfile_error: IF ERRN=56 THEN Start_cr
	OFF ERROR
	GOTO Start_recs
Start: Start_cnt= 1
OUTPUT Start_rec$ USING "#,A,7D";"S",Start_cnt
LOOP
	C$="ENTER START RECORD #"&VAL$(Start_cnt)&"(72 char max), Default, Proceed"
	GOSUB Question
	A$=LWC$(Answer$)
EXIT IF ((A$="proceed") OR (A$="proceed?") OR (A$="p") OR (A$="d") OR (A$="default,"))
	I=LEN(Answer$)
	IF I>72 THEN 
		BEEP 
		Stat=MessageStringBox("START RECORD   #"&VAL$(Start_cnt)&"   TOO LONG ","IGES ERRORS ENCOUNTERED")
	ELSE
		OUTPUT Start_rec$ USING "#,A,7D";"S",Start_cnt
		OUTPUT @File;Answer$&RPT$(" ",72-I)&Start_rec$
		Start_cnt=Start_cnt+1
	END IF
END LOOP

PRINT A$
IF (A$="d") OR (A$="default,") THEN
Answer$=""
Default=1
END IF
IF Start_cnt=1 THEN
	OUTPUT @File;RPT$(" ",72)&Start_rec$
ELSE
	Start_cnt=Start_cnt-1
END IF

ASSIGN @File to *
ON ERROR GOTO Gfile_error
Global_file$="globals"
Global_recs:Stat= RemoveFile(Global_file$)
OFF ERROR
Global_cr:CREATE ASCII Global_file$,1
ASSIGN @File TO Global_file$
GOTO Gstart
Gfile_error:IF ERRN=56 OR ERRN=-1 THEN Global_cr
	OFF ERROR
	GOTO Global_recs
Gstart:Output_to_file=1
Default$="SENDER IDENTIFICATION"
C$="PRODUCT IDENTIFICATION FROM SENDER:"		! 3)sending product id
GOSUB Question
OUTPUT @File;"FILE NAME:"&Igs_name$			! 4)file name
OUTPUT @File;"SYSTEM ID: Synergy by Weber Systems"	! 5)system id
Default$="PRODUCT IDENTIFICATION"
C$="PRODUCT IDENTIFICATION FOR THE RECEIVER:"		!12)receiving product id
GOSUB Question
Default$="AUTHOR"
C$="NAME OF AUTHOR:"					!21)name of author
GOSUB Question
Default$="ORGANIZATION"
C$="AUTHOR'S ORGANIZATION:"				!22)author's org.
GOSUB Question
Default=0

ASSIGN @File TO *
Output_to_file=0

! Added layer stripping

Ask_layers:!
C$="LAYER NUMBERS, Current , All "
GOSUB Question
A$=LWC$(Answer$)
SELECT A$
CASE "a","all"
	Layer$=""
CASE "c","current","current,"
	Layer$=GetPlotLayers
CASE ELSE
	Layer$=Answer$
END SELECT

! end of layer stripping

Stat=NamedVarStr("iges out parameters",WsSystemVars,"-p3",Pass$)
IF Layer$<>"" THEN Layer$=" -l "&Layer$
Pass$=JoinStrings(Pass$," ",Layer$)

PRINT "/usr/weber/bin/synigs "&Syn_name$&" "&Igs_fullname$&Pass$&" >message_global 2>iges_errors"

Export:Stat= DisplayMessage("EXPORTING DATA . . .")

Stat=StoreFile(Syn_name$,1)
IF Stat THEN
           Stat=SetInputFormat("a99","")
           Stat=GetValue("WARNING -- FILE NOT STORED: cannot open file",Answer$)
           IF (ExitScript(Destination$)) THEN Leave
           GOTO Leave
END IF
Stat= StartIgesOut(Igs_fullname$,Syn_name$,Pass$,"message_global","iges_errors")

!D
!D Iges data is converted to synergy by a process call to "synigs".
!D 	Usage:	synigs infile outfile [-i] [-p#]
!D
!D igssyn options:
!D
!D 		infile - synergy geometry file
!D
!D 		outfile - iges data filename
!D
!D 		-i  ignore properties associated with entities to speed
!D 			the conversion process
!D
!D		-l (layerlist) pass only the entities on the specified layers
!D		   (layerlist) is a comma separated list of layers.
!D		   (i.e. -l 100,101,202,505 ), default is all layers.
!D
!D		-L (layerlist) pass everthing but the specified layers
!D			
!D 	-p# set print level to #.  Print levels:
!D
!D 		0) no standard output
!D 		1) global data
!D 		2) record totals & include level 1
!D 		3) entity totals & include levels 1 & 2
!D
!D 	default) level 1 (i.e. if -p# not specified)
!D

IF Show_global_data THEN Stat=MessageFileBox(Global_file$,"IGES GLOBAL DATA")
IF Show_error_data THEN Stat=MessageFileBox("iges_errors","IGES ERRORS ENCOUNTERED")

Leave:Assign @File TO *

LowerFileBox
Stat=SetInputFormat("n4","")

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
Question:Stat=SetInputFormat("a99","",WsFalse)
IF Default<>1 THEN
Stat=GetValue(C$,Answer$)
IF (ExitScript(Destination$)) THEN Leave
ELSE
Answer$=Default$
END IF
IF Output_to_file THEN OUTPUT @File USING "#,K,/";C$&Answer$
RETURN
END

