
! script name: plot.d/plotterview
! topic: plot a view on a plotter

!A
!A NAME:
!A
!A 	Plot a View
!A
!A DESCRIPTION:
!A
!A 	This script is for plotting a view on a plotter.  The Main View
!A 	is plotted on the plotter at the maximum scale allowed.
!A
!B INSTRUCTIONS:
!B
!B 	INPUT PAPER SIZE A B C D E: Enter the paper size to be used for
!B 		plotting.
!B
!C NOTES:
!C
!C 	The A size is the default paper.  The data files for the different
!C 	size paper are in:
!C
!C 		"/usr/weber/util/tooldata/plotconfig"
!C
!C 	The files may need to be modified depending on the type of plotter
!C 	being used.  New files may be added by following the format of the
!C 	other files.  If a new file is added, make sure the option is added
!C 	to the question and answer selections.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: plot a view ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
DIM Filename$[256]
DIM Namelist$[32000]
DIM Plotname$[256]
DIM Papersize$[16]


Plot_to_device=1 ! 1 sends plot to device through synplot.ksh


! Generate plotfile name
Namelist$= DirectoryNamesStr("./","*",WsAscending,"plotfile",".hpgl")
IF NOT POS(Namelist$,"plotfile") THEN
        Plotname$="plotfile1.hpgl"
ELSE
        A$= NextNumberedName(Namelist$,"plotfile",",")
        Plotname$=A$&".hpgl"
END IF

P1x= -4500
P1y= -2790
P2x= 4500
P2y= 2790

Filename$="/usr/weber/util/tooldata/plotconfig"

Stat=SetInputFormat("a1",",A,B,C,D,E,")
Stat= GetValue("INPUT PAPER SIZE A B C D E ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Papersize$=Answer$

Filename$=FileNameString(Filename$,Answer$&"size")
Plot_config=ReadUserData(2013,"PLOT CONFIG",Filename$)
IF (NOT (ValidGeometry(Plot_config))) THEN Start
P1x=GetUserValue(Plot_config,"P1x:")
P1y=GetUserValue(Plot_config,"P1y:")
P2x=GetUserValue(Plot_config,"P2x:")
P2y=GetUserValue(Plot_config,"P2y:")

Start:Plotter_view= FindView("PLOTTER")
IF NOT Plotter_view THEN
	xmin= -10
	xmax= 10
	ymin= -10
	ymax= 10
	stat= MakePlotterView("PLOTTER",Plotname$,xmin,xmax,ymin,ymax,p1x,p1y,p2x,p2y)
	GOTO Start
ELSE
	Stat= ChPlotterViewFile(Plotter_view,Plotname$)
END IF
stat= ChangeP1_P2(Plotter_view,p1x,p1y,p2x,p2y)

Source_view= 1
stat= OutputString(Plotname$,CHR$(10),WsNewFile)
stat= CopyViewTrans(Plotter_view,Source_view)
stat= CopyViewScale(Plotter_view,Source_view)
stat= TurnViewOn(Plotter_view)
Drawing= ActiveDrawing
IF ValidGeometry(Drawing) THEN 
	Stat= SetActiveDrawing(Drawing,Plotter_view)
	Stat= PlotView(Plotter_view)
	Stat= SetActiveDrawing(Drawing)
ELSE
	Stat= PlotView(Plotter_view)
END IF
stat= TurnViewOff(Plotter_view)
stat= OutputString(Plotname$,CHR$(10),WsAppend)

IF Plot_to_device THEN
	stat=ChangeLabelStr("ScriptNameStatus","SYNPLOT,"&Papersize$&","&Plotname$)
! 	stat= StartProcess("synplot.ksh "&Plotname$&" "&Papersize$&" &")
END IF

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

