
! script name: filing.d/placefile
! topic: read file into group and place

!A
!A NAME:
!A
!A 	Reposition in 2D
!A
!A DESCRIPTION:
!A
!A 	This script allows a file to be read into a group and placed at several
!A 	locations.  This script will not permanently place a file until "Place"
!A 	is selected.
!A 	
!B INSTRUCTIONS:
!B
!B 	SELECT EXISTING FILE: The selection box will appear
!B 		at this time for a selection to be made.
!B
!B 	GROUP NAME: Enter the name to be associated with the
!B 		file to be placed.  The group name will have a
!B 		number appended to it in sequential order each
!B 		additional time the file is placed.
!B
!B 	LOCATION ABS X,Y,Z: Enter the X,Y,Z coordinates
!B 		to be used as the reference point in placing the file.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B 	
!B 	ORIENTATION ANGLE: Enter the angle to be used for
!B 		orienting the file to be placed.
!B
!B 	Undo or Place: Enter "U" to undo (delete) the
!B 		file placement.  Enter "P" to finalize the placement
!B 		of the file.  Place must be selected to finalize the
!B 		process, exiting the script works like Undo.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: place file ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Dir$[256]
DIM D_label$[256]
DIM Sub_label$[256]
DIM F_label$[256]
DIM Choice$[256]
DIM Mask$[256]
DIM Group_name$[256]
DIM Gname$[256]
DIM Decision$[256]

!C 	If Ask_undo$="Y" the "Undo, Restore, Delete" options will be present.
!C
!C 	If Ask_undo$="N" the script will automatically delete the elements
!C 	when they are picked.  NO CHANCE to change the selection.

DeActivateUndo
Ask_undo$="Y"

Stat=SetPickMask(WsPickAll)
Component_group= 30999
Group_type= Component_group

IF ARGC>1 THEN
	Answer$=ARGV(1)
	Name$=Answer$
	GOTO Skip_file_select
END IF

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]*"
Mask$= "Synergy Files (*.syn)|*.syn|"
Mask$= Mask$&"Drawing Exchange Format (*.dxf)|*.dxf|"
Mask$= Mask$&"Drawing File (*.dwg)|*.dwg|"
Mask$= Mask$&"All Files (*.*)|*.*||"

Stat=UserFileBox(Dir$,Mask$,D_label$,Sub_label$,F_label$,Choice$)
Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT EXISTING FILE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN Leave
LowerFileBox
IF NamedVarVal("save dirs",WsSystemVars,0) THEN V1=CreateVariable("retrieve dir",WsSystemVars,PathNameDirectory(Answer$))

Name$=Answer$

Stat=SetInputFormat("a99","")
Stat=GetValue("GROUP NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Skip_file_select:!
Group_name$= Answer$
Gname$= Answer$

Group_num= 0

New_location: !

  Path_num=CurrPathNum
  Cont_num=CurrContourNum
  Hole_num=CurrHoleNum
  Path_grp_num=CurrPathGrpNum
  Hole_grp_num=CurrHoleGrpNum

Decision$=""
Stat=SetPickMask(WsPickNoSurf)
Stat=SetInputFormat("n4","")
Pc= XyzInput("LOCATION",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

Angle= InputAngle("ORIENTATION ANGLE")
IF (ExitScript(Destination$)) THEN Leave

Stat=SetPickMask(WsPickAll)

PlotOff
Group=ReadGroupFile(Group_name$,Group_type,Name$)
PlotOn

T1=AngleTransform(Pc,0,0,Angle)
stat= TransGroupTrans(Group,T1)
stat= DeleteEntity(Pc)

Stat= ResolveNames(Group)

PlotAll

IF Ask_undo$="Y" THEN
   Decision$="U"
   Stat=SetInputFormat("a1=",",U,P,")
   Stat=SetEqualsValue(0,"P")
   Stat=GetValue("Undo or Place",Answer$)
   IF (ExitScript(Destination$)) THEN Leave
   Decision$=Answer$
END IF

SELECT Decision$

  CASE "P"

    Group_num= Group_num+1
    Group_name$= Gname$&VAL$(Group_num)

  CASE "U"

    Temp_group=Group
    IF NOT ValidGeometry(Temp_group) THEN New_location
    Stat=UnLink(Temp_group)
    Stat=DeleteGroup(Temp_group,1)
    Stat=DeleteEntity(Temp_group)
    GOSUB Reset_counters

END SELECT

TransformCleanup

Stat=SetPickMask(WsPickAll)
GOTO New_location

Reset_counters: !

  Stat=SetCurrPathNum(Path_num)
  Stat=SetCurrContNum(Cont_num)
  Stat=SetCurrHoleNum(Hole_num)
  Stat=SetPathGrpNum(Path_grp_num)
  Stat=SetHoleGrpNum(Hole_grp_num)

RETURN

Leave:!
Stat=SetPickMask(WsPickAll)

IF NOT ValidGeometry(Group) THEN Leave_1

IF Ask_undo$="Y" AND Decision$="U" THEN
   Temp_group=Group
   Stat=UnLink(Temp_group)
   Stat=DeleteGroup(Temp_group,1)
   Stat=DeleteEntity(Temp_group)
   TransformCleanUp
   GOSUB Reset_counters
ELSE
	IF ARGC>1 THEN Stat= DeleteEntity(Group)
END IF

Leave_1: !
Stat=SetPickMask(WsPickAll)

LowerFileBox
Stat=SetInputFormat("n4","")
stat= DeleteEntity(Pc)

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


