
! script name: views.d/mknamedview
! topic: make named view

!A
!A NAME:
!A
!A 	Make Named View
!A
!A DESCRIPTION:
!A
!A 	This script allows a view to be named and assigned colors and layers.
!A
!B INSTRUCTIONS:
!B
!B 	USER VIEW NUMBER: Input the view number to be assigned.
!B
!B 	DESCRIPTION: Give a description of the view.
!B
!B 	INPUT LAYERS VISIBLE: Enter the layers that are
!B 		visible for the plot group.
!B
!B 	INPUT COLORS VISIBLE: Enter the colors that are
!B 		visible for the plot group.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: make named view ")

DIM Answer$[256]
DIM Destination$[256]
DIM Description$[256]
DIM Name$[256]
DIM Namelist$[256]
DIM Prompt$[256]
DIM Valid$[256]
DIM Layers$[8192]
DIM Colors$[8192]

Start:!

! 	Find the available Views and add the next one in sequence to the list

Namelist$=""
Next_view= 0
FOR I=1 TO 5
Name$= "View "&VAL$(I)
Sview= FindNamedView(Name$)
IF ValidGeometry(Sview) THEN
	Stat= StoredViewDescr(Sview,Answer$)
	Namelist$=Namelist$&VAL$(I)&" "&Answer$&","
ELSE
	IF NOT Next_view THEN Next_view= I
END IF
NEXT I

IF Next_view THEN Namelist$=Namelist$&VAL$(Next_view)&","

Stat=GeneralListBox("Views","Views",Namelist$)
Stat=SetInputFormat("a99","",0)
Stat=GetValue("USER VIEW NUMBER",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave

Vnum=VAL(Answer$)
Name$="View "&VAL$(Vnum)
Sview=FindNamedView(Name$)

IF ValidGeometry(Sview) THEN
Editing=1
ELSE
Editing=0
END IF

IF Editing THEN
	Stat= StoredViewDescr(Sview,Answer$)
	Stat= SetEditString(Answer$)
END IF

Stat=SetInputFormat("a99","",WsFalse)
Stat=GetValue("DESCRIPTION",Description$)
IF (ExitScript(Destination$)) THEN Leave

Prompt$="INPUT LAYERS VISIBLE, All, Refresh "
Valid$=",A,R,"
Layers$=GetPlotLayers

IF Editing THEN
	Prompt$=Prompt$&", Previous "
	Valid$=",A,R,P,"
END IF

DoLayers:!
IF LEN(Layers$) THEN
IF Layers$[1,1]="," THEN Layers$=Layers$[2]
IF Layers$[LEN(Layers$)]="," THEN Layers$[LEN(Layers$)]=""
END IF
Stat=SetInputFormat("a99",Valid$,WsFalse)
Stat=SetEditString(Layers$)
Stat=GetValue(Prompt$,Layers$)
IF (ExitScript(Destination$)) THEN Leave
IF Layers$="CANCEL" THEN Leave

IF UPC$(Layers$)="P" OR POS(Layers$,"Previous") THEN
	Stat= StoredViewLayers(Sview,Layers$)
	GOTO DoLayers
END IF

IF UPC$(Layers$)="R" OR POS(Layers$,"Refresh") THEN
	Layers$=GetPlotLayers
	GOTO DoLayers
END IF

Prompt$="INPUT COLORS VISIBLE, All, Refresh "
Valid$=",A,R,"
Colors$=GetPlotColors

IF Editing THEN
	Prompt$=Prompt$&", Previous "
	Valid$=",A,P,"
END IF

DoColors:!
IF LEN(Colors$) THEN
IF Colors$[1,1]="," THEN Colors$=Colors$[2]
IF Colors$[LEN(Colors$)]="," THEN Colors$[LEN(Colors$)]=""
END IF
Stat=SetInputFormat("a99",Valid$,WsFalse)
Stat=SetEditString(Colors$)
Stat=GetValue(Prompt$,Colors$)
IF (ExitScript(Destination$)) THEN Leave
IF Colors$="CANCEL" THEN Leave

IF (UPC$(Colors$)="P") OR (POS(Colors$,"Previous")) THEN
	Stat= StoredViewColors(Sview,Colors$)
	GOTO DoColors
END IF

IF UPC$(Colors$)="R" OR POS(Colors$,"Refresh") THEN
	Colors$=GetPlotColors
	GOTO DoColors
END IF


IF Editing THEN
	stat= DeleteEntity(Sview)
END IF

Sview= MakeViewEntity(1,Name$,Description$)

IF (ValidGeometry(Sview)) THEN
	IF UPC$(Layers$)="A" OR POS(Layers$,"All") THEN
		stat= ChangeViewLayers(Sview,"")
	ELSE
		Layers$= ","&Layers$&","
		stat= ChangeViewLayers(Sview,Layers$)
	END IF

	IF UPC$(Colors$)="A" OR POS(Colors$,"All") THEN
		stat= ChangeViewColors(Sview,"")
	ELSE
		Colors$= ","&Colors$&","
		stat= ChangeViewColors(Sview,Colors$)
	END IF
ELSE

stat= DisplayMessage("VIEW NOT CREATED")

END IF

GOTO Start

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