
! script name: plot.d/autoplotpos
! topic: Sample - use main views perspective to plot on plotter to scale

!A
!A NAME:
!A
!A 	Plot Position
!A
!A DESCRIPTION:
!A
!A	This script is for plotting a view on a plotter to scale, at a
!A 	specified position from plotter zero.  The perspective (e.g.
!A 	isometric, top, front, or side) of the main view is used.
!A
!B INSTRUCTIONS:
!B
!B 	INPUT PAPER SIZE A B C D E: Enter the paper size to be used
!B 	for 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
!C NOTE:
!C
!C 	This is an unsupported sample script.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: plot position ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
DIM Filename$[256]
DIM Namelist$[32000]
DIM Name$[256]


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


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



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

CALL Setlinetypes(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",Name$,xmin,xmax,ymin,ymax,p1x,p1y,p2x,p2y)
	GOTO Start
ELSE
	Stat= ChPlotterViewFile(Plotter_view,Plotname$)
END IF

Source_view= 1

Ask_scale:Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(1.0)
Plot_scale= GetValue("PLOT SCALE ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
if(NOT plot_scale) THEN Ask_scale

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(0.0)
X_plot= GetValue("X PLOT POSITION ",Answer$)
IF (ExitScript(Destination$)) THEN Leave


Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(0.0)
Y_plot= GetValue("Y PLOT POSITION ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Units= CurrentUnits

Plotter_units=1016
IF Units= WsMetric THEN Plotter_units=40

Scale_factor= 1/Plot_scale
Xlength=  Scale_factor*ABS(p2x- p1x)/Plotter_units
Ywidth=  Scale_factor*ABS(p2y- p1y)/Plotter_units

stat= CopyViewTrans(Plotter_view,Source_view)
stat= TurnViewOn(Plotter_view)
stat= ResizeView(Plotter_view,WsUpdatePlotFile,0)

Xmin= - Xlength/2
Ymin= - Ywidth/2
Xmax= Xlength/2
Ymax= Ywidth/2

px= X_plot*Plotter_units
py= Y_plot*Plotter_units

p1x= px- Xlength/2*Plotter_units
p1y= py- Ywidth/2*Plotter_units
p2x= px+ Xlength/2*Plotter_units
p2y= py+ Ywidth/2*Plotter_units

stat= OutputString(Name$,"SP1"&CHR$(10),WsNewFile)
stat= ChangeP1_P2(Plotter_view,p1x,p1y,p2x,p2y)
stat= ScaleView(Plotter_view,Xmin,Xmax,Ymin,Ymax)
stat= TurnViewOff(Plotter_view)
stat= OutputString(Name$,"SP"&CHR$(10),WsAppend)
stat= OutputString(Name$,"SP"&CHR$(10),WsAppend)

IF  Plot_to_device THEN
	stat= StartProcess("synplot.ksh "&Name$&" &")
END IF

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

SUB Setlinetypes(Answer$)
SELECT Answer$
CASE "A"
	stat= PlotLineTypeMap(2,"LT1,3")
	stat= PlotLineTypeMap(3,"LT1,5")
	stat= PlotLineTypeMap(4,"LT1,1.5")
	stat= PlotLineTypeMap(5,"LT2")
	stat= PlotLineTypeMap(6,"LT4")
	stat= PlotLineTypeMap(7,"LT5")
	stat= PlotLineTypeMap(8,"LT6")
	stat= PlotLineTypeMap(9,"LT")
	stat= PlotLineTypeMap(10,"LT5")
	stat= PlotLineTypeMap(11,"LT2")
	stat= PlotLineTypeMap(12,"LT6")
	stat= PlotLineTypeMap(13,"LT2")
	stat= PlotLineTypeMap(14,"LT6")
	stat= PlotLineTypeMap(15,"LT5")
CASE "B"
	stat= PlotLineTypeMap(2,"LT1,1")
	stat= PlotLineTypeMap(3,"LT1,2")
	stat= PlotLineTypeMap(4,"LT1,.5")
	stat= PlotLineTypeMap(5,"LT2,2")
	stat= PlotLineTypeMap(6,"LT4")
	stat= PlotLineTypeMap(7,"LT5")
	stat= PlotLineTypeMap(8,"LT6")
	stat= PlotLineTypeMap(9,"LT")
	stat= PlotLineTypeMap(10,"LT5")
	stat= PlotLineTypeMap(11,"LT2")
	stat= PlotLineTypeMap(12,"LT6")
	stat= PlotLineTypeMap(13,"LT2")
	stat= PlotLineTypeMap(14,"LT6")
	stat= PlotLineTypeMap(15,"LT5")
CASE "C"
	stat= PlotLineTypeMap(2,"LT1,.75")
	stat= PlotLineTypeMap(3,"LT1,1.5")
	stat= PlotLineTypeMap(4,"LT1,.375")
	stat= PlotLineTypeMap(5,"LT2,2")
	stat= PlotLineTypeMap(6,"LT4,1")
	stat= PlotLineTypeMap(7,"LT5,2")
	stat= PlotLineTypeMap(8,"LT6,2")
	stat= PlotLineTypeMap(9,"LT")
	stat= PlotLineTypeMap(10,"LT5,1")
	stat= PlotLineTypeMap(11,"LT2,2")
	stat= PlotLineTypeMap(12,"LT6,2")
	stat= PlotLineTypeMap(13,"LT2,2")
	stat= PlotLineTypeMap(14,"LT6,2")
	stat= PlotLineTypeMap(15,"LT5,2")
CASE "D"
	stat= PlotLineTypeMap(2,"LT1,.75")
	stat= PlotLineTypeMap(3,"LT1,1.5")
	stat= PlotLineTypeMap(4,"LT1,.375")
	stat= PlotLineTypeMap(5,"LT2,.5")
	stat= PlotLineTypeMap(6,"LT4,1")
	stat= PlotLineTypeMap(7,"LT5,2")
	stat= PlotLineTypeMap(8,"LT6,2")
	stat= PlotLineTypeMap(9,"LT")
	stat= PlotLineTypeMap(10,"LT5,1")
	stat= PlotLineTypeMap(11,"LT2,2")
	stat= PlotLineTypeMap(12,"LT6,2")
	stat= PlotLineTypeMap(13,"LT2,2")
	stat= PlotLineTypeMap(14,"LT6,2")
	stat= PlotLineTypeMap(15,"LT5,2")
CASE "E"
	stat= PlotLineTypeMap(2,"LT1,.5")
	stat= PlotLineTypeMap(3,"LT1,1")
	stat= PlotLineTypeMap(4,"LT1,.25")
	stat= PlotLineTypeMap(5,"LT2,.375")
	stat= PlotLineTypeMap(6,"LT4,1")
	stat= PlotLineTypeMap(7,"LT5,1.5")
	stat= PlotLineTypeMap(8,"LT6,1.5")
	stat= PlotLineTypeMap(9,"LT")
	stat= PlotLineTypeMap(10,"LT5,1")
	stat= PlotLineTypeMap(11,"LT2,2")
	stat= PlotLineTypeMap(12,"LT6,2")
	stat= PlotLineTypeMap(13,"LT2,2")
	stat= PlotLineTypeMap(14,"LT6,2")
	stat= PlotLineTypeMap(15,"LT5,2")
END SELECT
SUBEND
